KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > typeinfo > JParameterizedType


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 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * Represents a parameterized type in a declaration.
24  */

25 public class JParameterizedType extends JType {
26
27   private final JClassType parameterized;
28
29   private final List JavaDoc typeArgs = new ArrayList JavaDoc();
30
31   JParameterizedType(JClassType parameterized) {
32     this.parameterized = parameterized;
33   }
34
35   /**
36    * The signature of the raw type.
37    */

38   public String JavaDoc getJNISignature() {
39     return getRawType().getJNISignature();
40   }
41
42   public JType getLeafType() {
43     return parameterized;
44   }
45
46   /*
47    * Get the name of this type without all of the parameterized information
48    */

49   public String JavaDoc getNonParameterizedQualifiedSourceName() {
50     return parameterized.getQualifiedSourceName();
51   }
52
53   public String JavaDoc getParameterizedQualifiedSourceName() {
54     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
55     sb.append(parameterized.getQualifiedSourceName());
56     sb.append('<');
57     boolean needComma = false;
58     for (Iterator JavaDoc iter = typeArgs.iterator(); iter.hasNext();) {
59       JType typeArg = (JType) iter.next();
60       if (needComma) {
61         sb.append(", ");
62       } else {
63         needComma = true;
64       }
65       sb.append(typeArg.getParameterizedQualifiedSourceName());
66     }
67     sb.append('>');
68     return sb.toString();
69   }
70
71   /**
72    * Everything is fully qualified and includes the &lt; and &gt; in the
73    * signature.
74    */

75   public String JavaDoc getQualifiedSourceName() {
76     return parameterized.getQualifiedSourceName();
77   }
78
79   public JClassType getRawType() {
80     return parameterized;
81   }
82
83   /**
84    * In this case, the raw type name.
85    */

86   public String JavaDoc getSimpleSourceName() {
87     return parameterized.getSimpleSourceName();
88   }
89
90   public JType[] getTypeArgs() {
91     return (JType[]) typeArgs.toArray(TypeOracle.NO_JTYPES);
92   }
93
94   public JArrayType isArray() {
95     return null;
96   }
97
98   public JClassType isClass() {
99     return parameterized.isClass();
100   }
101
102   public JClassType isInterface() {
103     return parameterized.isInterface();
104   }
105
106   public JParameterizedType isParameterized() {
107     return this;
108   }
109
110   public JPrimitiveType isPrimitive() {
111     return null;
112   }
113
114   void addTypeArg(JType type) {
115     assert (type.isPrimitive() == null);
116     typeArgs.add(type);
117   }
118 }
119
Popular Tags