KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > types > Type


1 package polyglot.types;
2
3 import polyglot.util.Position;
4
5 /**
6  * A <code>Type</code> is the base type of all classes which represent
7  * types.
8  */

9 public interface Type extends Qualifier
10 {
11     /**
12      * Return a string into which to translate the type.
13      * @param c A resolver in which to lookup this type to determine if
14      * the type is unique in the given resolver.
15      */

16     String JavaDoc translate(Resolver c);
17
18     /**
19      * Return an array of this type.
20      */

21     ArrayType arrayOf();
22
23     /**
24      * Return a <code>dims</code>-array of this type.
25      */

26     ArrayType arrayOf(int dims);
27
28     /**
29      * Cast the type to a class type, or null.
30      */

31     ClassType toClass();
32
33     /**
34      * Cast the type to a null type, or null.
35      */

36     NullType toNull();
37
38     /**
39      * Cast the type to a reference type, or null.
40      */

41     ReferenceType toReference();
42
43     /**
44      * Cast the type to a primitive type, or null.
45      */

46     PrimitiveType toPrimitive();
47
48     /**
49      * Cast the type to an array type, or null.
50      */

51     ArrayType toArray();
52
53     /**
54      * Return true if this type is a subtype of <code>ancestor</code>.
55      */

56     boolean isSubtype(Type ancestor);
57
58     /**
59      * Return true if this type descends from <code>ancestor</code>.
60      */

61     boolean descendsFrom(Type ancestor);
62
63     /**
64      * Return true if this type can be cast to <code>toType</code>.
65      */

66     boolean isCastValid(Type toType);
67
68     /**
69      * Return true if a value of this type can be assigned to a variable of
70      * type <code>toType</code>.
71      */

72     boolean isImplicitCastValid(Type toType);
73
74     /**
75      * Return true a literal <code>value</code> can be converted to this type.
76      */

77     boolean numericConversionValid(Object JavaDoc value);
78
79     /**
80      * Return true a literal <code>value</code> can be converted to this type.
81      */

82     boolean numericConversionValid(long value);
83
84     /**
85      * Return true if this type is a subtype of <code>ancestor</code>.
86      */

87     boolean isSubtypeImpl(Type t);
88
89     /**
90      * Return true if this type descends from <code>ancestor</code>.
91      */

92     boolean descendsFromImpl(Type t);
93
94     /**
95      * Return true if this type can be cast to <code>toType</code>.
96      */

97     boolean isCastValidImpl(Type t);
98
99     /**
100      * Return true if a value of this type can be assigned to a variable of
101      * type <code>toType</code>.
102      */

103     boolean isImplicitCastValidImpl(Type t);
104
105     /**
106      * Return true a literal <code>value</code> can be converted to this type.
107      */

108     boolean numericConversionValidImpl(Object JavaDoc value);
109
110     /**
111      * Return true a literal <code>value</code> can be converted to this type.
112      * This method should be removed. It is kept for backward compatibility.
113      */

114     boolean numericConversionValidImpl(long value);
115
116     /**
117      * Return true if a primitive type.
118      */

119     boolean isPrimitive();
120
121     /**
122      * Return true if void.
123      */

124     boolean isVoid();
125
126     /**
127      * Return true if boolean.
128      */

129     boolean isBoolean();
130
131     /**
132      * Return true if char.
133      */

134     boolean isChar();
135
136     /**
137      * Return true if byte.
138      */

139     boolean isByte();
140
141     /**
142      * Return true if short.
143      */

144     boolean isShort();
145
146     /**
147      * Return true if int.
148      */

149     boolean isInt();
150
151     /**
152      * Return true if long.
153      */

154     boolean isLong();
155
156     /**
157      * Return true if float.
158      */

159     boolean isFloat();
160
161     /**
162      * Return true if double.
163      */

164     boolean isDouble();
165
166     /**
167      * Return true if int, short, byte, or char.
168      */

169     boolean isIntOrLess();
170
171     /**
172      * Return true if long, int, short, byte, or char.
173      */

174     boolean isLongOrLess();
175
176     /**
177      * Return true if double, float, long, int, short, byte, or char.
178      */

179     boolean isNumeric();
180
181     /**
182      * Return true if a reference type.
183      */

184     boolean isReference();
185
186     /**
187      * Return true if a null type.
188      */

189     boolean isNull();
190
191     /**
192      * Return true if an array type.
193      */

194     boolean isArray();
195
196     /**
197      * Return true if a class type.
198      */

199     boolean isClass();
200
201     /**
202      * Return true if a subclass of Throwable.
203      */

204     boolean isThrowable();
205
206     /**
207      * Return true if an unchecked exception.
208      */

209     boolean isUncheckedException();
210
211     /**
212      * Return true if the types can be compared; that is, if they have
213      * the same type system.
214      */

215     boolean isComparable(Type t);
216
217     /**
218      * Yields a string representing this type. The string
219      * should be consistent with equality. That is,
220      * if this.equals(anotherType), then it should be
221      * that this.toString().equals(anotherType.toString()).
222      *
223      * The string does not have to be a legal Java identifier.
224      * It is suggested, but not required, that it be an
225      * easily human readable representation, and thus useful
226      * in error messages and generated output.
227      */

228     String JavaDoc toString();
229 }
230
Popular Tags