KickJava   Java API By Example, From Geeks To Geeks.

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


1 package polyglot.ext.jl.types;
2
3 import polyglot.types.*;
4 import polyglot.util.*;
5 import java.io.*;
6
7 /**
8  * Abstract implementation of a type object. Contains a reference to the
9  * type system and to the object's position in the code.
10  */

11 public abstract class TypeObject_c implements TypeObject
12 {
13     protected transient TypeSystem ts;
14     protected Position position;
15
16     /** Used for deserializing types. */
17     protected TypeObject_c() {
18     }
19     
20     /** Creates a new type in the given a TypeSystem. */
21     public TypeObject_c(TypeSystem ts) {
22         this(ts, null);
23     }
24
25     public TypeObject_c(TypeSystem ts, Position pos) {
26     this.ts = ts;
27     this.position = pos;
28     }
29
30     public Object JavaDoc copy() {
31         try {
32             return (TypeObject_c) super.clone();
33         }
34         catch (CloneNotSupportedException JavaDoc e) {
35             throw new InternalCompilerError("Java clone() weirdness.");
36         }
37     }
38
39     public TypeSystem typeSystem() {
40         return ts;
41     }
42
43     public Position position() {
44         return position;
45     }
46
47     private void writeObject(ObjectOutputStream out) throws IOException {
48         out.defaultWriteObject();
49     }
50
51     private void readObject(ObjectInputStream in) throws IOException,
52                            ClassNotFoundException JavaDoc {
53     if (in instanceof TypeInputStream) {
54         ts = ((TypeInputStream) in).getTypeSystem();
55     }
56
57         in.defaultReadObject();
58     }
59
60     /**
61      * Return whether o equals this.
62      * Implementations should override equalsImpl().
63      */

64     public final boolean equals(Object JavaDoc o) {
65         return o instanceof TypeObject && ts.equals(this, (TypeObject) o);
66     }
67
68     public int hashCode() {
69         return super.hashCode();
70     }
71     
72     /**
73      * Default implementation is pointer equality.
74      */

75     public boolean equalsImpl(TypeObject t) {
76         return t == this;
77     }
78
79     /**
80      * Overload equalsImpl to find inadvertant overridding errors.
81      * Make package-scope and void to break callers.
82      */

83     void equalsImpl(Object JavaDoc o) { }
84 }
85
Popular Tags