01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.jjs.ast.js;
17:
18: import com.google.gwt.dev.jjs.ast.Context;
19: import com.google.gwt.dev.jjs.ast.JClassType;
20: import com.google.gwt.dev.jjs.ast.JExpression;
21: import com.google.gwt.dev.jjs.ast.JProgram;
22: import com.google.gwt.dev.jjs.ast.JType;
23: import com.google.gwt.dev.jjs.ast.JVisitor;
24:
25: import java.util.ArrayList;
26: import java.util.List;
27:
28: /**
29: * A JSON-style list of JS expressions.
30: */
31: public class JsonArray extends JExpression {
32:
33: public List<JExpression> exprs = new ArrayList<JExpression>();
34:
35: public JsonArray(JProgram program) {
36: super (program, null);
37: }
38:
39: public JType getType() {
40: // If JavaScriptObject type is not available, just return the Object type
41: JClassType jsoType = program.getJavaScriptObject();
42: return (jsoType != null) ? jsoType : program
43: .getTypeJavaLangObject();
44: }
45:
46: public boolean hasSideEffects() {
47: for (int i = 0, c = exprs.size(); i < c; ++i) {
48: if (exprs.get(i).hasSideEffects()) {
49: return true;
50: }
51: }
52: return false;
53: }
54:
55: public void traverse(JVisitor visitor, Context ctx) {
56: if (visitor.visit(this, ctx)) {
57: visitor.accept(exprs);
58: }
59: visitor.endVisit(this, ctx);
60: }
61:
62: }
|