KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > typeinfo > 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.core.ext.typeinfo;
17
18 /**
19  * Type representing a Java array.
20  */

21 public class JArrayType extends JType {
22
23   private JType componentType;
24
25   private String JavaDoc lazyQualifiedName;
26
27   private String JavaDoc lazySimpleName;
28
29   JArrayType(JType componentType) {
30     this.componentType = componentType;
31   }
32
33   public JType getComponentType() {
34     return componentType;
35   }
36
37   public String JavaDoc getJNISignature() {
38     return "[" + componentType.getJNISignature();
39   }
40
41   public JType getLeafType() {
42     return componentType.getLeafType();
43   }
44
45   public String JavaDoc getParameterizedQualifiedSourceName() {
46     return getComponentType().getParameterizedQualifiedSourceName() + "[]";
47   }
48
49   public String JavaDoc getQualifiedSourceName() {
50     if (lazyQualifiedName == null) {
51       lazyQualifiedName = getComponentType().getQualifiedSourceName() + "[]";
52     }
53     return lazyQualifiedName;
54   }
55
56   public int getRank() {
57     JArrayType componentArrayType = componentType.isArray();
58     if (componentArrayType != null) {
59       return 1 + componentArrayType.getRank();
60     }
61
62     return 1;
63   }
64
65   public String JavaDoc getSimpleSourceName() {
66     if (lazySimpleName == null) {
67       lazySimpleName = getComponentType().getSimpleSourceName() + "[]";
68     }
69     return lazySimpleName;
70   }
71
72   public JArrayType isArray() {
73     return this;
74   }
75
76   public JClassType isClass() {
77     // intentional null
78
return null;
79   }
80
81   public JClassType isInterface() {
82     // intentional null
83
return null;
84   }
85
86   public JParameterizedType isParameterized() {
87     // intentional null
88
return null;
89   }
90
91   public JPrimitiveType isPrimitive() {
92     // intentional null
93
return null;
94   }
95
96   public void setLeafType(JType type) {
97     JArrayType componentTypeIsArray = componentType.isArray();
98     if (componentTypeIsArray != null) {
99       componentTypeIsArray.setLeafType(type);
100     } else {
101       componentType = type;
102     }
103   }
104
105   public String JavaDoc toString() {
106     return getQualifiedSourceName();
107   }
108 }
109
Popular Tags