1 24 25 package org.aspectj.compiler.base.ast; 26 27 import java.io.*; 28 import java.util.Enumeration ; 29 import org.aspectj.compiler.base.*; 30 import org.aspectj.util.CollectionUtil; 31 import org.aspectj.compiler.base.parser.SourceInfo; 32 33 import org.aspectj.compiler.crosscuts.joinpoints.*; 35 import org.aspectj.compiler.crosscuts.ast.*; 36 37 38 import java.util.*; 39 import java.lang.reflect.*; 40 41 public class World extends CompilerObject { 42 private List compilationUnits = new ArrayList(); 43 private List files = new LinkedList(); 44 private ArrayList codeDecs = new ArrayList(); 45 46 48 public final SourceLocation source = new DummySourceLocation(getCompiler()); 49 50 public final CompilationUnit missingCompilationUnit = 51 new CompilationUnit(source, null, null, new Decs(source), new SourceInfo(null, null),true); 52 53 public final FieldDec FIELD_DEC_NOT_FOUND = 54 new FieldDec(source,new Modifiers(source,1), 55 getTypeManager().anyType.makeTypeD(), "not$found", null); 56 public final FieldDec FIELD_NOT_FOUND = FIELD_DEC_NOT_FOUND; 57 58 public final VarDec VAR_DEC_NOT_FOUND = 59 new VarDec(source,getTypeManager().anyType.makeTypeD(), "not$found", null); 60 61 public final MethodDec METHOD_DEC_NOT_FOUND = 62 new MethodDec(source,new Modifiers(source, 0),getTypeManager().anyType.makeTypeD(), 63 "not$found", new Formals(source), 64 new TypeDs(source), null); 65 66 public final ConstructorDec CONSTRUCTOR_DEC_NOT_FOUND = 67 new ConstructorDec(source,new Modifiers(source, 0), new Formals(source), 68 new TypeDs(source), null); 69 70 public final PointcutDec POINTCUT_DEC_NOT_FOUND = 71 new PointcutDec(source,new Modifiers(source, 0), "NOT_FOUND", null, null, new EmptyPcd(source)); 72 public final PointcutDec POINTCUT_NOT_FOUND = POINTCUT_DEC_NOT_FOUND; 73 74 public List getFiles() { 75 return files; 76 } 77 78 private class CompilationUnitEnumerator implements Enumeration { 79 int idx = 0; 80 public boolean hasMoreElements() { return idx < compilationUnits.size(); } 81 public Object nextElement() { return compilationUnits.get(idx++); } 82 } 83 private class FileEnumerator implements Enumeration { 84 int idx = 0; 85 public boolean hasMoreElements() { return idx < files.size(); } 86 public Object nextElement() { return files.get(idx++); } 87 } 88 89 91 public void cleanup() { 94 files = new LinkedList(); 95 codeDecs = new ArrayList(); 96 compilationUnits = new ArrayList(); 97 } 98 99 public World(JavaCompiler compiler) { 100 super(compiler); 101 } 102 103 107 public Enumeration enumerateCompilationUnits() { 108 return new CompilationUnitEnumerator(); 109 } 110 111 public List getCompilationUnits() { 112 return compilationUnits; 113 } 114 115 public void addCompilationUnit(CompilationUnit cu) { 116 compilationUnits.add(cu); 117 } 118 119 public Enumeration enumerateFiles() { 120 return new FileEnumerator(); 121 } 122 123 public void addFile(String filename) { 124 if (files.contains(filename)) 125 return; 126 files.add(filename); 127 } 128 129 131 public String genLabel() { 132 return "aj$label" + labelCount++; 133 } 134 private int labelCount = 0; 135 136 141 public List getTypes() { 142 ArrayList types = new ArrayList(); 143 Enumeration en = enumerateCompilationUnits(); 144 while (en.hasMoreElements()) { 145 CompilationUnit cu = (CompilationUnit)en.nextElement(); 146 types.addAll(cu.getDefinedTypes()); 147 } 148 return types; 149 } 150 151 155 156 private List sourceTypes = new LinkedList(); 157 158 public void addSourceType(Type type) { 159 sourceTypes.add(type); 161 getTypeManager().addType(type); 162 } 163 164 public Iterator sourceTypesIterator() { 165 return new Iterator() { 166 int index = 0; 167 public boolean hasNext() { return index < sourceTypes.size(); } 168 public Object next() { return sourceTypes.get(index++); } 169 public void remove() { throw new RuntimeException ("can't remove from this"); } 170 }; 171 } 173 174 175 private LinkedList buildingTypeGraph = new LinkedList(); 176 177 public void pushBuildingTypeGraph(TypeDec td) { 178 buildingTypeGraph.addLast(td); 179 } 181 182 public void popBuildingTypeGraph() { 183 buildingTypeGraph.removeLast(); 184 } 185 186 public LinkedList getBuildingTypeGraph() { 187 return buildingTypeGraph; 188 } 189 190 191 193 194 private List jpPlanners = new LinkedList(); 197 198 public void addJpPlanner(JpPlanner planner) { 199 if (planner.isStaticPlanner()) { 200 staticJpPlanners.add(new TopJpPlanner(planner)); 201 } else { 202 jpPlanners.add(new TopJpPlanner(planner)); 203 } 204 } 205 206 public List getJpPlanners() { return jpPlanners; } 207 208 private List staticJpPlanners = new LinkedList(); 209 210 public List getStaticJpPlanners() { return staticJpPlanners; } 211 212 private Collection typePlanners = new LinkedList(); 216 public void addTypeDecPlanner(TypeDecPlanner planner) { 217 if (!typePlanners.contains(planner)) typePlanners.add(planner); 218 } 219 220 public boolean collectedTypeDecPlanners = false; 221 222 public void runTypeDecPlanners(TypeDec typeDec, int phase) { 223 if (!typeDec.fromSource()) return; 225 226 for (Iterator i = typePlanners.iterator(); i.hasNext(); ) { 228 TypeDecPlanner planner = (TypeDecPlanner)i.next(); 229 230 planner.plan(typeDec, phase); 232 } 233 } 234 235 public Map calleeSideCallPoints = new HashMap(); 236 237 private Map sourceToOutput = new HashMap(); 238 private Map outputToSource = new HashMap(); 239 240 public Map getSourceToOutputLineMap() { return sourceToOutput; } 241 public Map getOutputToSourceLineMap() { return sourceToOutput; } 242 243 public void clearState() { 244 sourceToOutput = null; 245 outputToSource = null; 246 } 247 } 248 249 250 | Popular Tags |