Permalink
Browse files

Allow using the ModuleVisitor without side effects (only reusing the

existing modules and packages)
This is for the IDE (EditorPhasedUnits and binary-archive
ExternalPhasedUnits typechecked on-the-fly)
This doesn't change anything by default
  • Loading branch information...
1 parent d467d07 commit dd8409cb2eefd86d930cc18f749e910b8bc661c2 David Festal committed Feb 28, 2014
@@ -44,6 +44,15 @@
private final Package pkg;
private Tree.CompilationUnit unit;
private Phase phase = Phase.SRC_MODULE;
+ private boolean completeOnlyAST = false;
+
+ public void setCompleteOnlyAST(boolean completeOnlyAST) {
+ this.completeOnlyAST = completeOnlyAST;
+ }
+
+ public boolean isCompleteOnlyAST() {
+ return completeOnlyAST;
+ }
public ModuleVisitor(ModuleManager moduleManager, Package pkg) {
this.moduleManager = moduleManager;
@@ -120,18 +129,22 @@ else if (name.get(0).equals("java")||name.get(0).equals("javax")) {
}
mainModule = moduleManager.getOrCreateModule(name, version);
importPath.setModel(mainModule);
- mainModule.setUnit(unit.getUnit());
- mainModule.setVersion(version);
+ if (!completeOnlyAST) {
+ mainModule.setUnit(unit.getUnit());
+ mainModule.setVersion(version);
+ }
String nameString = formatPath(importPath.getIdentifiers());
if ( !pkg.getNameAsString().equals(nameString) ) {
importPath
.addError("module name does not match descriptor location: " +
nameString + " should be " + pkg.getNameAsString(),
8000);
}
- moduleManager.addLinkBetweenModuleAndNode(mainModule, that);
- mainModule.setAvailable(true);
- buildAnnotations(that.getAnnotationList(), mainModule.getAnnotations());
+ if (!completeOnlyAST) {
+ moduleManager.addLinkBetweenModuleAndNode(mainModule, that);
+ mainModule.setAvailable(true);
+ buildAnnotations(that.getAnnotationList(), mainModule.getAnnotations());
+ }
}
HashSet<String> set = new HashSet<String>();
Tree.ImportModuleList iml = that.getImportModuleList();
@@ -175,21 +188,25 @@ else if (name.get(0).equals("java")||name.get(0).equals("javax")) {
importPath.addUsageWarning("discouraged package name: this namespace is used by Java platform modules");
}
importPath.setModel(pkg);
- pkg.setUnit(unit.getUnit());
+ if (!completeOnlyAST) {
+ pkg.setUnit(unit.getUnit());
+ }
String nameString = formatPath(importPath.getIdentifiers());
if ( !pkg.getNameAsString().equals(nameString) ) {
importPath
.addError("package name does not match descriptor location: " +
nameString + " should be " + pkg.getNameAsString(),
8000);
}
- if (hasAnnotation(that.getAnnotationList(), "shared", unit.getUnit())) {
- pkg.setShared(true);
- }
- else {
- pkg.setShared(false);
+ if (!completeOnlyAST) {
+ if (hasAnnotation(that.getAnnotationList(), "shared", unit.getUnit())) {
+ pkg.setShared(true);
+ }
+ else {
+ pkg.setShared(false);
+ }
+ buildAnnotations(that.getAnnotationList(), pkg.getAnnotations());
}
- buildAnnotations(that.getAnnotationList(), pkg.getAnnotations());
}
}
}
@@ -241,20 +258,22 @@ else if (name.size()>1 && name.get(0).equals("ceylon")
if (that.getImportPath()!=null) {
that.getImportPath().setModel(importedModule);
}
- if (mainModule != null) {
- if (importedModule.getVersion() == null) {
- importedModule.setVersion(version);
- }
- ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
- if (moduleImport == null) {
- Tree.AnnotationList al = that.getAnnotationList();
- boolean optional = hasAnnotation(al, "optional", unit.getUnit());
- boolean export = hasAnnotation(al, "shared", unit.getUnit());
- moduleImport = new ModuleImport(importedModule, optional, export);
- buildAnnotations(al, moduleImport.getAnnotations());
- mainModule.getImports().add(moduleImport);
+ if (!completeOnlyAST) {
+ if (mainModule != null) {
+ if (importedModule.getVersion() == null) {
+ importedModule.setVersion(version);
+ }
+ ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
+ if (moduleImport == null) {
+ Tree.AnnotationList al = that.getAnnotationList();
+ boolean optional = hasAnnotation(al, "optional", unit.getUnit());
+ boolean export = hasAnnotation(al, "shared", unit.getUnit());
+ moduleImport = new ModuleImport(importedModule, optional, export);
+ buildAnnotations(al, moduleImport.getAnnotations());
+ mainModule.getImports().add(moduleImport);
+ }
+ moduleManager.addModuleDependencyDefinition(moduleImport, that);
}
- moduleManager.addModuleDependencyDefinition(moduleImport, that);
}
}
}
@@ -116,13 +116,18 @@ protected PhasedUnit(VirtualFile unitFile, VirtualFile srcDir, Tree.CompilationU
this(unitFile, srcDir, cu, p, moduleManager, context, null);
}
+ protected boolean reuseExistingDescriptorModels() {
+ return false;
+ }
+
public Module visitSrcModulePhase() {
if ( ModuleManager.MODULE_FILE.equals(fileName) ||
ModuleManager.PACKAGE_FILE.equals(fileName) ) {
if (! moduleVisited) {
moduleVisited = true;
processLiterals();
moduleVisitor = new ModuleVisitor(moduleManager, pkg);
+ moduleVisitor.setCompleteOnlyAST(reuseExistingDescriptorModels());
moduleManager = null;
compilationUnit.visit(moduleVisitor);
return moduleVisitor.getMainModule();

0 comments on commit dd8409c

Please sign in to comment.