aspect JAModuleASTGrammar { //refined from JastAdd/ASTGrammer.jrag refine ASTGrammar private void Program.loadASTFile(String name) { try { File inFile = new File(name); FileInputStream is = new FileInputStream(inFile); //parse AST file scanner.JavaScanner scanner = new scanner.JavaScanner(new scanner.Unicode(is)); scanner.enterJastAdd(); CompilationUnit cu = (CompilationUnit)new parser.JavaParser().parse(scanner, parser.JavaParser.AltGoals.ast_file); scanner.previousState(); is.close(); cu.setPathName(inFile.getAbsolutePath()); cu.setRelativeName(name); //generate ASTNode CUs List importList = cu.getImportDeclList(); for(int i = 0; i < cu.getTypeDeclList().getNumChild(); i++) { TypeDecl typeDecl = (TypeDecl)cu.getTypeDeclList().getChildNoTransform(i); CompilationUnit unit = new CompilationUnit( cu.getPackageDecl(), (List)importList.fullCopy(), new List().add(typeDecl) ); unit.setFromSource(true); unit.setRelativeName(name); unit.setPathName("."); //NEIL: Added modules for generated AST files unit.setOrigASTCompilationUnit(cu); if (cu.getModuleDecl() != null) { unit.setModuleDecl(cu.getModuleDecl()); unit.addChild(cu.getModuleDecl()); } addCompilationUnit(unit); } } catch (Exception e) { throw new Error(e.getMessage()); } } //store the original AST cu in the generated CUs for AST types protected CompilationUnit CompilationUnit.origASTCompilationUnit = null; public CompilationUnit CompilationUnit.getOrigASTCompilationUnit() { return this.origASTCompilationUnit; } public void CompilationUnit.setOrigASTCompilationUnit(CompilationUnit astCU) { this.origASTCompilationUnit = astCU; } public boolean CompilationUnit.isGeneratedFromAST() { return (this.origASTCompilationUnit != null); } public static final String Program.JASTADD_FRAMEWORK_MODULE = "jastadd$framework"; refine ASTGrammar eq CompilationUnit.lookupFrameworkType(String name) { TypeDecl result = null; //if is a module member, get from framework module if (isInJAModule()) { result = lookupType(Program.JASTADD_FRAMEWORK_MODULE, name); if (result != null) { return result; } else if (getHostProgram().hasASTCompilationUnit() && getHostProgram().hasJAModules()) { //if result is null and .ast and .module files are present, return an error error("Unable to find AST framework type " + name); return null; } } //Keep these for backward compatibility (so JastAddModules can compile module-less jastadd) // imported types SimpleSet set = set = importedTypes(name); if(set.isEmpty()) { // types in the same package result = lookupType(packageName(), name); if(result != null && result.accessibleFromPackage(packageName())) set = set.add(result); } if(set.isEmpty()) { // types imported on demand set = importedTypesOnDemand(name); } if(set.size() == 1) { return (TypeDecl)set.iterator().next(); } else { return unknownType(); } } syn lazy boolean Program.hasASTCompilationUnit() { for (Iterator i = compilationUnitIterator(); i.hasNext() ; ) { CompilationUnit cu = (CompilationUnit) i.next(); if (cu.isGeneratedFromAST()) { return true; } } return false; } }