KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
19  * Instances are shared.
20  */

21 public class JArrayType extends JClassType {
22
23   private static String JavaDoc calcName(JType leafType, int dims) {
24     String JavaDoc name = leafType.getName();
25     for (int i = 0; i < dims; ++i) {
26       name = name + "[]";
27     }
28     return name;
29   }
30
31   private int dims;
32   private JType leafType;
33
34   /**
35    * These are only supposed to be constructed by JProgram.
36    */

37   JArrayType(JProgram program, JType leafType, int dims) {
38     super(program, null, calcName(leafType, dims), false, false);
39     this.leafType = leafType;
40     this.dims = dims;
41   }
42
43   public int getDims() {
44     return dims;
45   }
46
47   public JType getElementType() {
48     if (dims == 1) {
49       return leafType;
50     }
51     return program.getTypeArray(leafType, dims - 1);
52   }
53
54   public String JavaDoc getJavahSignatureName() {
55     String JavaDoc s = leafType.getJavahSignatureName();
56     for (int i = 0; i < dims; ++i) {
57       s = "_3" + s;
58     }
59     return s;
60   }
61
62   public String JavaDoc getJsniSignatureName() {
63     String JavaDoc s = leafType.getJsniSignatureName();
64     for (int i = 0; i < dims; ++i) {
65       s = "[" + s;
66     }
67     return s;
68   }
69
70   public JType getLeafType() {
71     return leafType;
72   }
73
74   public boolean isAbstract() {
75     return false;
76   }
77
78   public boolean isFinal() {
79     return false;
80   }
81
82   public void traverse(JVisitor visitor, Context ctx) {
83     if (visitor.visit(this, ctx)) {
84     }
85     visitor.endVisit(this, ctx);
86   }
87
88 }
89
Popular Tags