KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > jjs > ast > JNewArray


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;
17
18 import com.google.gwt.dev.jjs.SourceInfo;
19
20 import java.util.ArrayList JavaDoc;
21
22 /**
23  * New array expression.
24  */

25 public class JNewArray extends JExpression implements HasSettableType {
26
27   public ArrayList JavaDoc dims = null;
28   public ArrayList JavaDoc initializers = null;
29   private JArrayType arrayType;
30
31   public JNewArray(JProgram program, SourceInfo info, JArrayType arrayType) {
32     super(program, info);
33     this.arrayType = arrayType;
34   }
35
36   public JArrayType getArrayType() {
37     return arrayType;
38   }
39
40   public JType getType() {
41     return arrayType;
42   }
43
44   public boolean hasSideEffects() {
45     if (initializers != null) {
46       for (int i = 0, c = initializers.size(); i < c; ++i) {
47         if (((JExpression) initializers.get(i)).hasSideEffects()) {
48           return true;
49         }
50       }
51     }
52     if (dims != null) {
53       for (int i = 0, c = dims.size(); i < c; ++i) {
54         if (((JExpression) dims.get(i)).hasSideEffects()) {
55           return true;
56         }
57       }
58     }
59     // The new operation on an array does not actually cause side effects.
60
return false;
61   }
62
63   public void setType(JType arrayType) {
64     this.arrayType = (JArrayType) arrayType;
65   }
66
67   public void traverse(JVisitor visitor, Context ctx) {
68     if (visitor.visit(this, ctx)) {
69       assert ((dims != null) ^ (initializers != null));
70
71       if (dims != null) {
72         visitor.accept(dims);
73       }
74
75       if (initializers != null) {
76         visitor.accept(initializers);
77       }
78     }
79     visitor.endVisit(this, ctx);
80   }
81 }
82
Popular Tags