KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > jjs > ast > js > JsonObject


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.JExpression;
20 import com.google.gwt.dev.jjs.ast.JNode;
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 JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * Represents a JS construct that should be emitted as a JSON-style object.
30  */

31 public class JsonObject extends JExpression {
32
33   /**
34    * An individual property initializer within a JSON object initializer.
35    */

36   public static class JsonPropInit extends JNode {
37
38     public JExpression labelExpr;
39     public JExpression valueExpr;
40
41     public JsonPropInit(JProgram program, JExpression labelExpr,
42         JExpression valueExpr) {
43       super(program, null);
44       this.labelExpr = labelExpr;
45       this.valueExpr = valueExpr;
46     }
47
48     public void traverse(JVisitor visitor, Context ctx) {
49       if (visitor.visit(this, ctx)) {
50         labelExpr = visitor.accept(labelExpr);
51         valueExpr = visitor.accept(valueExpr);
52       }
53       visitor.endVisit(this, ctx);
54     }
55   }
56
57   public final List JavaDoc/* <JsonPropInit> */propInits = new ArrayList JavaDoc/* <JsonPropInit> */();
58
59   public JsonObject(JProgram program) {
60     super(program, null);
61   }
62
63   public JType getType() {
64     return program.getTypeVoid();
65   }
66
67   public boolean hasSideEffects() {
68     for (int i = 0, c = propInits.size(); i < c; ++i) {
69       JsonPropInit propInit = ((JsonPropInit) propInits.get(i));
70       if (propInit.labelExpr.hasSideEffects()
71           || propInit.valueExpr.hasSideEffects()) {
72         return true;
73       }
74     }
75     return false;
76   }
77
78   public void traverse(JVisitor visitor, Context ctx) {
79     if (visitor.visit(this, ctx)) {
80       visitor.accept(propInits);
81     }
82     visitor.endVisit(this, ctx);
83   }
84
85 }
86
Popular Tags