1 package polyglot.ext.jl.types; 2 3 import java.util.LinkedList ; 4 import java.util.List ; 5 6 import polyglot.frontend.Source; 7 import polyglot.types.*; 8 import polyglot.types.Package; 9 import polyglot.util.InternalCompilerError; 10 import polyglot.util.Position; 11 import polyglot.util.TypedList; 12 13 20 public class ParsedClassType_c extends ClassType_c implements ParsedClassType 21 { 22 protected transient LazyClassInitializer init; 23 protected transient Source fromSource; 24 protected Type superType; 25 protected List interfaces; 26 protected List methods; 27 protected List fields; 28 protected List constructors; 29 protected List memberClasses; 30 protected Package package_; 31 protected Flags flags; 32 protected Kind kind; 33 protected String name; 34 protected ClassType outer; 35 36 protected boolean inStaticContext = false; 37 38 protected ParsedClassType_c() { 39 super(); 40 } 41 42 public ParsedClassType_c(TypeSystem ts, LazyClassInitializer init, 43 Source fromSource) { 44 super(ts); 45 this.init = init; 46 this.fromSource = fromSource; 47 48 if (init == null) { 49 throw new InternalCompilerError("Null lazy class initializer"); 50 } 51 } 52 53 public Source fromSource() { 54 return fromSource; 55 } 56 57 public Kind kind() { 58 return kind; 59 } 60 61 public void inStaticContext(boolean inStaticContext) { 62 this.inStaticContext = inStaticContext; 63 } 64 65 public boolean inStaticContext() { 66 return inStaticContext; 67 } 68 69 public ClassType outer() { 70 if (isTopLevel()) 71 return null; 72 if (outer == null) 73 throw new InternalCompilerError("Nested classes must have outer classes."); 74 75 return outer; 76 } 77 78 public String name() { 79 if (isAnonymous()) 80 throw new InternalCompilerError("Anonymous classes cannot have names."); 81 82 if (name == null) 83 throw new InternalCompilerError("Non-anonymous classes must have names."); 84 return name; 85 } 86 87 88 public Type superType() { 89 return this.superType; 90 } 91 92 93 public Package package_() { 94 return package_; 95 } 96 97 98 public Flags flags() { 99 if (isAnonymous()) 100 return Flags.NONE; 101 return flags; 102 } 103 104 105 protected boolean initialized() { 106 return this.methods != null && 107 this.constructors != null && 108 this.fields != null && 109 this.memberClasses != null && 110 this.interfaces != null; 111 } 112 113 114 protected void freeInit() { 115 if (initialized()) { 116 init = null; 117 } 118 else if (init == null) { 119 throw new InternalCompilerError("Null lazy class initializer"); 120 } 121 } 122 123 public void flags(Flags flags) { 124 this.flags = flags; 125 } 126 127 public void kind(Kind kind) { 128 this.kind = kind; 129 } 130 131 public void outer(ClassType outer) { 132 if (isTopLevel()) 133 throw new InternalCompilerError("Top-level classes cannot have outer classes."); 134 this.outer = outer; 135 } 136 137 public void name(String name) { 138 if (isAnonymous()) 139 throw new InternalCompilerError("Anonymous classes cannot have names."); 140 this.name = name; 141 } 142 143 public void position(Position pos) { 144 this.position = pos; 145 } 146 147 public void package_(Package p) { 148 this.package_ = p; 149 } 150 151 public void superType(Type t) { 152 this.superType = t; 153 } 154 155 public void addInterface(Type t) { 156 interfaces().add(t); 157 } 158 159 public void addMethod(MethodInstance mi) { 160 methods().add(mi); 161 } 162 163 public void addConstructor(ConstructorInstance ci) { 164 constructors().add(ci); 165 } 166 167 public void addField(FieldInstance fi) { 168 fields().add(fi); 169 } 170 171 public void addMemberClass(ClassType t) { 172 memberClasses().add(t); 173 } 174 175 176 public List constructors() { 177 if (constructors == null) { 178 constructors = new TypedList(new LinkedList (), ConstructorInstance.class, false); 179 init.initConstructors(this); 180 freeInit(); 181 } 182 return constructors; 183 } 184 185 186 public List memberClasses() { 187 if (memberClasses == null) { 188 memberClasses = new TypedList(new LinkedList (), Type.class, false); 189 init.initMemberClasses(this); 190 freeInit(); 191 } 192 return memberClasses; 193 } 194 195 196 public List methods() { 197 if (methods == null) { 198 methods = new TypedList(new LinkedList (), MethodInstance.class, false); 199 init.initMethods(this); 200 freeInit(); 201 } 202 return methods; 203 } 204 205 206 public List fields() { 207 if (fields == null) { 208 fields = new TypedList(new LinkedList (), FieldInstance.class, false); 209 init.initFields(this); 210 freeInit(); 211 } 212 return fields; 213 } 214 215 216 public List interfaces() { 217 if (interfaces == null) { 218 interfaces = new TypedList(new LinkedList (), Type.class, false); 219 init.initInterfaces(this); 220 freeInit(); 221 } 222 return interfaces; 223 } 224 } 225 | Popular Tags |