//STANDING NOTE: Make VERY sure that all JAModule passes before the java //errorcheck DO NOT TOUCH any AST nodes below CompilationUnit to avoid //the REWRITES //a "rewrite" pass done once all the module CUs are collected. //Module CUs are inserted above the CUs that belong to it //Package name mangling from import owns are not taken into //consideration yet, cloning parts of the tree will be done //in a later pass. aspect InsertModuleCUs { public boolean Program.insertModuleCUs() { List childList = getCompilationUnitList(); //bad, relies on the program child to be the CU list int i = 0; while (i < childList.getNumChild()) { ASTNode child = childList.getChild(i); //if a module cu, proceed to next if (child instanceof ModuleCompilationUnit) { i++; continue; //if a CU but not in a module, proceed to next } else if (child instanceof CompilationUnit && !(((CompilationUnit)child).isInJAModule())) { i++; continue;//useless case, keep for debugging purposes //if a CU in a module, detach and add its copy to its moduleCU } else if (child instanceof CompilationUnit && ((CompilationUnit)child).isInJAModule()) { CompilationUnit childCU = (CompilationUnit) child; ModuleCompilationUnit moduleCU = childCU.lookupModuleCUNoTransform(); childList.removeChild(i); //remove must be here, since the parent node of childCU must not be overwritten //Do a fullCopy instead of a cache flush to avoid the rewrites //NOTE: Needing to know not to trigger rewrites here is a VERY BAD SIGN //of a huge flaw moduleCU.getCompilationUnitList().addChild(childCU.fullCopy()); } else { i++; System.out.println("Unexpected program child type: " + child.getClass()); } } return true; } }