KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > types > NullType_c


1 package polyglot.ext.jl.types;
2
3 import polyglot.types.*;
4 import polyglot.util.*;
5
6 /**
7  * A <code>NullType</code> represents the type of the Java keyword
8  * <code>null</code>.
9  */

10 public class NullType_c extends Type_c implements NullType
11 {
12     /** Used for deserializing types. */
13     protected NullType_c() { }
14
15     public NullType_c(TypeSystem ts) {
16     super(ts);
17     }
18     
19     public String JavaDoc translate(Resolver c) {
20     throw new InternalCompilerError("Cannot translate a null type.");
21     }
22
23     public String JavaDoc toString() {
24     return "type(null)";
25     }
26     
27     public boolean equalsImpl(TypeObject t) {
28         return t instanceof NullType;
29     }
30
31     public int hashCode() {
32     return 6060842;
33     }
34
35     public boolean isCanonical() { return true; }
36     public boolean isNull() { return true; }
37
38     public NullType toNull() { return this; }
39
40     public boolean descendsFromImpl(Type ancestor) {
41         if (ancestor.isNull()) return false;
42         if (ancestor.isReference()) return true;
43         return false;
44     }
45
46     public boolean isImplicitCastValidImpl(Type toType) {
47         return toType.isNull() || toType.isReference();
48     }
49
50     /**
51      * Requires: all type arguments are canonical. ToType is not a NullType.
52      *
53      * Returns true iff a cast from this to toType is valid; in other
54      * words, some non-null members of this are also members of toType.
55      **/

56     public boolean isCastValidImpl(Type toType) {
57         return toType.isNull() || toType.isReference();
58     }
59 }
60
Popular Tags