KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > param > types > SubstClassType_c


1 package polyglot.ext.param.types;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.List JavaDoc;
5
6 import polyglot.ext.jl.types.ClassType_c;
7 import polyglot.types.ClassType;
8 import polyglot.types.Flags;
9 import polyglot.types.Package;
10 import polyglot.types.Resolver;
11 import polyglot.types.Type;
12 import polyglot.types.TypeObject;
13 import polyglot.util.Position;
14
15 /**
16  * Implementation of a ClassType that performs substitutions using a
17  * map. Subclasses must define how the substititions are performed and
18  * how to cache substituted types.
19  */

20 public class SubstClassType_c extends ClassType_c implements SubstType
21 {
22     /** The class type we are substituting into. */
23     protected ClassType base;
24
25     /** Map from formal parameters (of type Param) to actuals. */
26     protected Subst subst;
27
28     public SubstClassType_c(ParamTypeSystem ts, Position pos,
29                             ClassType base, Subst subst)
30     {
31         super(ts, pos);
32         this.base = base;
33         this.subst = subst;
34     }
35
36     /**
37      * Entries of the underlying substitution object.
38      * @return an <code>Iterator</code> of <code>Map.Entry</code>.
39      */

40     public Iterator JavaDoc entries() {
41         return subst.entries();
42     }
43
44     /** Get the class on that we are performing substitutions. */
45     public Type base() {
46         return base;
47     }
48
49     /** The substitution object. */
50     public Subst subst() {
51         return subst;
52     }
53
54     ////////////////////////////////////////////////////////////////
55
// Perform substitutions on these operations of the base class
56

57     /** Get the class's super type. */
58     public Type superType() {
59         return subst.substType(base.superType());
60     }
61
62     /** Get the class's interfaces. */
63     public List JavaDoc interfaces() {
64         return subst.substTypeList(base.interfaces());
65     }
66
67     /** Get the class's fields. */
68     public List JavaDoc fields() {
69         return subst.substFieldList(base.fields());
70     }
71
72     /** Get the class's methods. */
73     public List JavaDoc methods() {
74         return subst.substMethodList(base.methods());
75     }
76
77     /** Get the class's constructors. */
78     public List JavaDoc constructors() {
79         return subst.substConstructorList(base.constructors());
80     }
81
82     /** Get the class's member classes. */
83     public List JavaDoc memberClasses() {
84         return subst.substTypeList(base.memberClasses());
85     }
86
87     /** Get the class's outer class, if a nested class. */
88     public ClassType outer() {
89         return (ClassType) subst.substType(base.outer());
90     }
91
92     ////////////////////////////////////////////////////////////////
93
// Delegate the rest of the class operations to the base class
94

95     /** Get the class's kind: top-level, member, local, or anonymous. */
96     public ClassType.Kind kind() {
97         return base.kind();
98     }
99
100     /** Get whether the class was declared in a static context */
101     public boolean inStaticContext() {
102         return base.inStaticContext();
103     }
104
105     /** Get the class's full name, if possible. */
106     public String JavaDoc fullName() {
107         return base.fullName();
108     }
109
110     /** Get the class's short name, if possible. */
111     public String JavaDoc name() {
112         return base.name();
113     }
114
115     /** Get the class's package, if possible. */
116     public Package JavaDoc package_() {
117         return base.package_();
118     }
119
120     public Flags flags() {
121         return base.flags();
122     }
123
124     public String JavaDoc translate(Resolver c) {
125         return base.translate(c);
126     }
127
128     ////////////////////////////////////////////////////////////////
129
// Equality tests
130

131     /** Type equality test. */
132     public boolean equalsImpl(TypeObject t) {
133         if (t instanceof SubstType) {
134             SubstType x = (SubstType) t;
135             return base.equals(x.base()) && subst.equals(x.subst());
136         }
137         return false;
138     }
139
140     /** Hash code. */
141     public int hashCode() {
142         return base.hashCode() ^ subst.hashCode();
143     }
144
145     public String JavaDoc toString() {
146         return base.toString() + subst.toString();
147     }
148 }
149
Popular Tags