diff options
author | Sasikanth Bharadwaj | 2017-02-14 08:57:57 +0000 |
---|---|---|
committer | Sasikanth Bharadwaj | 2017-02-14 10:30:39 +0000 |
commit | 1d80bc40b1dfdc0bc0117745eb0d044027083363 (patch) | |
tree | a3cee1c08a5f51712017c1b2da30f6db8c9f107d | |
parent | 5b985a80c268f70b5a6f9778d88c8c05a1714e21 (diff) | |
download | eclipse.jdt.core-sasikanth/bug511574_ModuleDecl_Hierarchy.tar.gz eclipse.jdt.core-sasikanth/bug511574_ModuleDecl_Hierarchy.tar.xz eclipse.jdt.core-sasikanth/bug511574_ModuleDecl_Hierarchy.zip |
Change-Id: I1609d9cdfc96eee2a11cc6635a4f06304da6e332
16 files changed, 212 insertions, 145 deletions
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java index 22c7b4949c..c5b2160a00 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java @@ -1027,7 +1027,8 @@ public final class SelectionEngine extends Engine implements ISearchRequestor { } if (parsedUnit.isModuleInfo() && parsedUnit.types != null && parsedUnit.types.length > 0) { - ModuleDeclaration module = (ModuleDeclaration) parsedUnit.types[0];//TODO, could be null + TypeDeclaration modInfo = parsedUnit.types[0]; + ModuleDeclaration module = modInfo.scope.compilationUnitScope().referenceContext.moduleDeclaration ;//TODO, could be null this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); acceptPackageVisibilityStatements(module.exports, parsedUnit.scope); acceptPackageVisibilityStatements(module.opens, parsedUnit.scope); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java index cf5e4b289b..d6351e0605 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java @@ -2600,7 +2600,7 @@ public class ClassFile implements TypeConstants, TypeIds { return 1; } private int generateModuleAttribute() { - ModuleDeclaration module = (ModuleDeclaration)this.referenceBinding.scope.referenceContext; + ModuleDeclaration module = this.referenceBinding.scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleBinding binding = module.moduleBinding; int localContentsOffset = this.contentsOffset; if (localContentsOffset + 10 >= this.contents.length) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java index da1994bfe1..dba5d6fa98 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java @@ -214,11 +214,11 @@ public void createPackageInfoType() { } public void createModuleInfoType(ModuleDeclaration declaration) { - //TypeDeclaration declaration = new TypeDeclaration(this.compilationResult); - declaration.name = TypeConstants.MODULE_INFO_NAME; - declaration.modifiers |= ClassFileConstants.AccModule; - declaration.javadoc = this.javadoc; - this.types[0] = declaration; // Assumes the first slot is meant for this type + TypeDeclaration type = new TypeDeclaration(this.compilationResult); + type.name = TypeConstants.MODULE_INFO_NAME; + type.modifiers = ClassFileConstants.AccModule; + type.javadoc = this.javadoc; + this.types[0] = type; // Assumes the first slot is meant for this type } /* diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java index 923ea7bd1e..679058cf6c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ModuleDeclaration.java @@ -21,17 +21,14 @@ import java.util.Set; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.eclipse.jdt.internal.compiler.flow.FlowContext; -import org.eclipse.jdt.internal.compiler.flow.FlowInfo; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -public class ModuleDeclaration extends TypeDeclaration { +public class ModuleDeclaration extends ASTNode { public ExportsStatement[] exports; public RequiresStatement[] requires; @@ -44,14 +41,20 @@ public class ModuleDeclaration extends TypeDeclaration { public int servicesCount; public int opensCount; public ModuleBinding moduleBinding; - + public int declarationSourceStart; + public int declarationSourceEnd; + public int bodyStart; + public int bodyEnd; // doesn't include the trailing comment if any. + public int modifiersSourceStart; + //public ClassScope scope; public char[][] tokens; public char[] moduleName; public long[] sourcePositions; + public int modifiers = ClassFileConstants.AccDefault; public ModuleDeclaration(CompilationResult compilationResult, char[][] tokens, long[] positions) { - super(compilationResult); - this.compilationResult = compilationResult; +// super(compilationResult); +// this.compilationResult = compilationResult; this.exportsCount = 0; this.requiresCount = 0; this.tokens = tokens; @@ -60,45 +63,40 @@ public class ModuleDeclaration extends TypeDeclaration { this.sourceEnd = (int) (positions[positions.length-1] & 0x00000000FFFFFFFF); this.sourceStart = (int) (positions[0] >>> 32); } - @Override - public void generateCode(ClassFile enclosingClassFile) { - if (this.ignoreFurtherInvestigation) { - return; - } - super.generateCode(enclosingClassFile); - } - @Override - public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { - // TODO Auto-generated method stub - return null; - } +// @Override +// public void generateCode(ClassFile enclosingClassFile) { +// if (this.ignoreFurtherInvestigation) { +// return; +// } +// super.generateCode(enclosingClassFile); +// } - @Override - public void resolve() { + //@Override + public void resolve(ClassScope scope) { // - if (this.binding == null) { - this.ignoreFurtherInvestigation = true; - return; - } - this.moduleBinding = this.scope.environment().getModule(this.moduleName); +// if (this.binding == null) { +// this.ignoreFurtherInvestigation = true; +// return; +// } + this.moduleBinding = scope.environment().getModule(this.moduleName); Set<ModuleBinding> requiredModules = new HashSet<ModuleBinding>(); for(int i = 0; i < this.requiresCount; i++) { RequiresStatement ref = this.requires[i]; - if (ref != null && ref.resolve(this.scope) != null) { + if (ref != null && ref.resolve(scope) != null) { if (!requiredModules.add(ref.resolvedBinding)) { - this.scope.problemReporter().duplicateModuleReference(IProblem.DuplicateRequires, ref.module); + scope.problemReporter().duplicateModuleReference(IProblem.DuplicateRequires, ref.module); } Collection<ModuleBinding> deps = ref.resolvedBinding.dependencyGraphCollector().get(); if (deps.contains(this.moduleBinding)) - this.scope.problemReporter().cyclicModuleDependency(this.moduleBinding, ref.module); + scope.problemReporter().cyclicModuleDependency(this.moduleBinding, ref.module); } } Set<PackageBinding> exportedPkgs = new HashSet<>(); for (int i = 0; i < this.exportsCount; i++) { ExportsStatement ref = this.exports[i]; - if (ref != null && ref.resolve(this.scope)) { + if (ref != null && ref.resolve(scope)) { if (!exportedPkgs.add(ref.resolvedPackage)) { - this.scope.problemReporter().invalidPackageReference(IProblem.DuplicateExports, ref); + scope.problemReporter().invalidPackageReference(IProblem.DuplicateExports, ref); } } } @@ -106,34 +104,34 @@ public class ModuleDeclaration extends TypeDeclaration { for (int i = 0; i < this.opensCount; i++) { OpensStatement ref = this.opens[i]; if (isOpen()) { - this.scope.problemReporter().invalidOpensStatement(ref, this); + scope.problemReporter().invalidOpensStatement(ref, this); } else { - if (ref.resolve(this.scope)) { + if (ref.resolve(scope)) { if (!openedPkgs.add(ref.resolvedPackage)) { - this.scope.problemReporter().invalidPackageReference(IProblem.DuplicateOpens, ref); + scope.problemReporter().invalidPackageReference(IProblem.DuplicateOpens, ref); } } } } Set<TypeBinding> allTypes = new HashSet<TypeBinding>(); for(int i = 0; i < this.usesCount; i++) { - TypeBinding serviceBinding = this.uses[i].serviceInterface.resolveType(this.scope); + TypeBinding serviceBinding = this.uses[i].serviceInterface.resolveType(scope); if (serviceBinding != null && serviceBinding.isValidBinding()) { if (!(serviceBinding.isClass() || serviceBinding.isInterface() || serviceBinding.isAnnotationType())) { - this.scope.problemReporter().invalidServiceRef(IProblem.InvalidServiceIntfType, this.uses[i].serviceInterface); + scope.problemReporter().invalidServiceRef(IProblem.InvalidServiceIntfType, this.uses[i].serviceInterface); } if (!allTypes.add(this.uses[i].serviceInterface.resolvedType)) { - this.scope.problemReporter().duplicateTypeReference(IProblem.DuplicateUses, this.uses[i].serviceInterface); + scope.problemReporter().duplicateTypeReference(IProblem.DuplicateUses, this.uses[i].serviceInterface); } } } Set<TypeBinding> interfaces = new HashSet<>(); for(int i = 0; i < this.servicesCount; i++) { - this.services[i].resolve(this.scope); + this.services[i].resolve(scope); TypeBinding infBinding = this.services[i].serviceInterface.resolvedType; if (infBinding != null && infBinding.isValidBinding()) { if (!interfaces.add(this.services[i].serviceInterface.resolvedType)) { - this.scope.problemReporter().duplicateTypeReference(IProblem.DuplicateServices, + scope.problemReporter().duplicateTypeReference(IProblem.DuplicateServices, this.services[i].serviceInterface); } } @@ -190,4 +188,12 @@ public class ModuleDeclaration extends TypeDeclaration { output.append('\n'); return printIndent(indent, output).append('}'); } + + @Override + public StringBuffer print(int indent, StringBuffer output) { + // + printIndent(indent, output); + printHeader(0, output); + return printBody(indent, output); + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java index 847fbc6edb..bbfeb17954 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java @@ -60,7 +60,7 @@ public abstract class PackageVisibilityStatement extends ModuleStatement { protected PackageBinding resolvePackageReference(Scope scope) { if (this.resolvedPackage != null) return this.resolvedPackage; - ModuleDeclaration exportingModule = (ModuleDeclaration)scope.referenceContext(); + ModuleDeclaration exportingModule = scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleBinding src = exportingModule.moduleBinding; this.resolvedPackage = src != null ? src.getDeclaredPackage(this.pkgRef.tokens) : null; if (this.resolvedPackage == null) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java index 17835e67e0..773b3c9080 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java @@ -35,7 +35,7 @@ public class ProvidesStatement extends ModuleStatement { public TypeReference[] implementations; public boolean resolve(ClassScope scope) { - ModuleDeclaration module = (ModuleDeclaration)scope.referenceContext(); + ModuleDeclaration module = scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleBinding src = module.moduleBinding; TypeBinding infBinding = this.serviceInterface.resolveType(scope); boolean hasErrors = false; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java index 46ad4c80af..81c12343d0 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java @@ -1308,6 +1308,11 @@ public void resolve(ClassScope upperScope) { */ public void resolve(CompilationUnitScope upperScope) { // top level : scope are already created + if (isModuleInfo()) { + ModuleDeclaration module = upperScope.referenceContext.moduleDeclaration; + module.resolve(this.scope); + return; + } resolve(); updateMaxFieldCount(); } @@ -1511,6 +1516,9 @@ void updateMaxFieldCount() { public boolean isPackageInfo() { return CharOperation.equals(this.name, TypeConstants.PACKAGE_INFO_NAME); } +public boolean isModuleInfo() { + return CharOperation.equals(this.name, TypeConstants.MODULE_INFO_NAME); +} /** * Returns whether the type is a secondary one or not. */ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java index 7c202aa4a4..f7a8d2fb51 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java @@ -20,6 +20,7 @@ import org.eclipse.jdt.internal.compiler.ast.Block; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.ImportReference; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.ast.ModuleStatement; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; @@ -137,6 +138,12 @@ public RecoveredElement add(Statement statement, int bracketBalanceValue) { this.updateSourceEndIfNecessary(previousAvailableLineEnd(statement.sourceStart - 1)); return this.parent.add(statement, bracketBalanceValue); } +public RecoveredElement add(ModuleDeclaration moduleDeclaration, int bracketBalanceValue){ + resetPendingModifiers(); + if (this.parent == null) return this; // ignore + this.updateSourceEndIfNecessary(previousAvailableLineEnd(moduleDeclaration.declarationSourceStart - 1)); + return this.parent.add(moduleDeclaration, bracketBalanceValue); +} /* * Record a type declaration */ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredModule.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredModule.java index 261916d540..f23f1fb1aa 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredModule.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredModule.java @@ -24,7 +24,7 @@ import org.eclipse.jdt.internal.compiler.ast.ProvidesStatement; import org.eclipse.jdt.internal.compiler.ast.RequiresStatement; import org.eclipse.jdt.internal.compiler.ast.UsesStatement; -public class RecoveredModule extends RecoveredType { +public class RecoveredModule extends RecoveredElement { public RecoveredExportsStatement[] exports; public int exportCount; @@ -36,9 +36,11 @@ public class RecoveredModule extends RecoveredType { public int usesCount; public RecoveredProvidesStatement[] services; public int servicesCount; + public ModuleDeclaration moduleDeclaration; public RecoveredModule(ModuleDeclaration moduleDeclaration, RecoveredElement parent, int bracketBalance) { - super(moduleDeclaration, parent, bracketBalance); + super(parent, bracketBalance); + this.moduleDeclaration = moduleDeclaration; } public RecoveredElement add(ModuleStatement moduleStatement, int bracketBalanceValue) { @@ -166,7 +168,7 @@ public class RecoveredModule extends RecoveredType { StringBuffer result = new StringBuffer(tabString(tab)); result.append("Recovered module:\n"); //$NON-NLS-1$ result.append("module ");//$NON-NLS-1$ - result.append(CharOperation.charToString(((ModuleDeclaration) this.typeDeclaration).moduleName)); + result.append(CharOperation.charToString(this.moduleDeclaration.moduleName)); result.append(" {");//$NON-NLS-1$ if (this.exportCount > 0) { for (int i = 0; i < this.exportCount; ++i) { @@ -197,87 +199,86 @@ public class RecoveredModule extends RecoveredType { } public ModuleDeclaration updatedModuleDeclaration() { - ModuleDeclaration moduleDeclaration = (ModuleDeclaration) this.typeDeclaration; - updateExports(moduleDeclaration); - updateOpens(moduleDeclaration); - updateRequires(moduleDeclaration); - updateUses(moduleDeclaration); - updateServices(moduleDeclaration); - return moduleDeclaration; + updateExports(this.moduleDeclaration); + updateOpens(this.moduleDeclaration); + updateRequires(this.moduleDeclaration); + updateUses(this.moduleDeclaration); + updateServices(this.moduleDeclaration); + return this.moduleDeclaration; } - private void updateExports(ModuleDeclaration moduleDeclaration) { + private void updateExports(ModuleDeclaration mod) { if (this.exportCount > 0) { - int existingCount = moduleDeclaration.exportsCount, actualCount = 0; + int existingCount = mod.exportsCount, actualCount = 0; ExportsStatement[] exports1 = new ExportsStatement[existingCount + this.exportCount]; if (existingCount > 0){ - System.arraycopy(moduleDeclaration.exports, 0, exports1, 0, existingCount); + System.arraycopy(mod.exports, 0, exports1, 0, existingCount); actualCount = existingCount; } for (int i = 0; i < this.exportCount; i++){ exports1[actualCount++] = (ExportsStatement)this.exports[i].updatedPackageVisibilityStatement(); } - moduleDeclaration.exports = exports1; - moduleDeclaration.exportsCount = actualCount; + mod.exports = exports1; + mod.exportsCount = actualCount; } } - private void updateOpens(ModuleDeclaration moduleDeclaration) { + private void updateOpens(ModuleDeclaration mod) { if (this.opensCount > 0) { - int existingCount = moduleDeclaration.opensCount, actualCount = 0; + int existingCount = mod.opensCount, actualCount = 0; OpensStatement[] opens1 = new OpensStatement[existingCount + this.opensCount]; if (existingCount > 0){ - System.arraycopy(moduleDeclaration.exports, 0, opens1, 0, existingCount); + System.arraycopy(mod.exports, 0, opens1, 0, existingCount); actualCount = existingCount; } for (int i = 0; i < this.opensCount; i++){ opens1[actualCount++] = (OpensStatement)this.opens[i].updatedPackageVisibilityStatement(); } - moduleDeclaration.opens = opens1; - moduleDeclaration.opensCount = actualCount; + mod.opens = opens1; + mod.opensCount = actualCount; } } - private void updateRequires(ModuleDeclaration moduleDeclaration) { + private void updateRequires(ModuleDeclaration mod) { if (this.requiresCount > 0) { - int existingCount = moduleDeclaration.requiresCount, actualCount = 0; + int existingCount = mod.requiresCount, actualCount = 0; RequiresStatement[] requiresStmts = new RequiresStatement[existingCount + this.requiresCount]; if (existingCount > 0){ - System.arraycopy(moduleDeclaration.requires, 0, requiresStmts, 0, existingCount); + System.arraycopy(mod.requires, 0, requiresStmts, 0, existingCount); actualCount = existingCount; } for (int i = 0; i < this.requiresCount; i++){ requiresStmts[actualCount++] = this.requires[i].updatedRequiresStatement(); } - moduleDeclaration.requires = requiresStmts; - moduleDeclaration.requiresCount = actualCount; + mod.requires = requiresStmts; + mod.requiresCount = actualCount; } } - private void updateUses(ModuleDeclaration moduleDeclaration) { + private void updateUses(ModuleDeclaration mod) { if (this.usesCount > 0) { - int existingCount = moduleDeclaration.usesCount, actualCount = 0; + int existingCount = mod.usesCount, actualCount = 0; UsesStatement[] usesStmts = new UsesStatement[existingCount + this.usesCount]; if (existingCount > 0){ - System.arraycopy(moduleDeclaration.uses, 0, usesStmts, 0, existingCount); + System.arraycopy(mod.uses, 0, usesStmts, 0, existingCount); actualCount = existingCount; } for (int i = 0; i < this.usesCount; ++i) { usesStmts[actualCount++] = this.uses[i].updatedUsesStatement(); } - moduleDeclaration.uses = usesStmts; - moduleDeclaration.usesCount = actualCount; + mod.uses = usesStmts; + mod.usesCount = actualCount; } } - private void updateServices(ModuleDeclaration moduleDeclaration) { + private void updateServices(ModuleDeclaration mod) { if (this.servicesCount > 0) { - int existingCount = moduleDeclaration.servicesCount, actualCount = 0; + int existingCount = mod.servicesCount, actualCount = 0; ProvidesStatement[] providesStmts = new ProvidesStatement[existingCount + this.servicesCount]; if (existingCount > 0){ - System.arraycopy(moduleDeclaration.services, 0, providesStmts, 0, existingCount); + System.arraycopy(mod.services, 0, providesStmts, 0, existingCount); actualCount = existingCount; } for (int i = 0; i < this.servicesCount; ++i) { providesStmts[actualCount++] = this.services[i].updatedProvidesStatement(); } - moduleDeclaration.services = providesStmts; - moduleDeclaration.servicesCount = actualCount; + mod.services = providesStmts; + mod.servicesCount = actualCount; } } public void updateParseTree(){ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java index d2aeaa8ec1..5a7dbc126c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java @@ -157,13 +157,12 @@ public RecoveredElement add(ImportReference importReference, int bracketBalanceV if (importReference.declarationSourceEnd == 0) return element; return this; } +public RecoveredElement add(ModuleDeclaration moduleDeclaration, int bracketBalanceValue){ + this.module = new RecoveredModule(moduleDeclaration, this, bracketBalanceValue); + return this.module; +} public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) { - if (typeDeclaration instanceof ModuleDeclaration) { - this.module = new RecoveredModule((ModuleDeclaration)typeDeclaration, this, bracketBalanceValue); - return this.module; - } - if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0){ if (this.typeCount > 0) { // add it to the last type diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java index 3598acc02f..b2f57eaf73 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java @@ -3282,10 +3282,10 @@ class ASTConverter { public ModuleDeclaration convertToModuleDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) { checkCanceled(); if (this.scanner.sourceLevel < ClassFileConstants.JDK9) return null; - org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration moduleDeclaration = (org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) typeDeclaration; + org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration moduleDeclaration = typeDeclaration.scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleDeclaration moduleDecl = this.ast.newModuleDeclaration(); - convert(moduleDeclaration.javadoc, moduleDecl); - setModifiers(moduleDecl, moduleDeclaration); + convert(typeDeclaration.javadoc, moduleDecl); + setModifiers(moduleDecl, typeDeclaration); Name moduleName = getUpdatedName(moduleDeclaration.moduleName, moduleDeclaration.sourceStart, moduleDeclaration.sourceEnd); moduleDecl.setName(moduleName); moduleDecl.setSourceRange(moduleDeclaration.declarationSourceStart, moduleDeclaration.declarationSourceEnd - moduleDeclaration.declarationSourceStart + 1); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java index 195671d65d..8ca1eeb051 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java @@ -22,6 +22,7 @@ import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; /* @@ -51,13 +52,20 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; @SuppressWarnings("rawtypes") public interface ISourceElementRequestor { - public static class ModuleInfo extends TypeInfo { + public static class ModuleInfo { + public int declarationStart; + public int modifiers; + public char[] name; + public int nameSourceStart; + public int nameSourceEnd; public char[] moduleName; public RequiresInfo[] requires; public PackageExportInfo[] exports; public ServicesInfo[] services; public PackageExportInfo[] opens; public char[][] usedServices; + public Annotation[] annotations; + public ModuleDeclaration node; } public static class RequiresInfo { public char[] moduleName; @@ -225,4 +233,11 @@ public interface ISourceElementRequestor { void exitMethod(int declarationEnd, Expression defaultValue); void exitType(int declarationEnd); + + default void enterModule(ModuleInfo info) { + // do nothing + } + default void exitModule(int declarationEnd) { + // do nothing + } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java index 9663736222..6979fbf5d8 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Map; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.compiler.ISourceElementRequestor.ModuleInfo; import org.eclipse.jdt.internal.compiler.ISourceElementRequestor.ParameterInfo; import org.eclipse.jdt.internal.compiler.ISourceElementRequestor.TypeParameterInfo; import org.eclipse.jdt.internal.compiler.ast.ASTNode; @@ -465,7 +464,12 @@ public void notifySourceElementRequestor( notifySourceElementRequestor(importRef, false); } } else { // instanceof TypeDeclaration - notifySourceElementRequestor((TypeDeclaration)node, true, null, currentPackage); + TypeDeclaration type = (TypeDeclaration) node; + if (type.isModuleInfo()) { + notifySourceElementRequestor(parsedUnit.moduleDeclaration); + } else { + notifySourceElementRequestor((TypeDeclaration)node, true, null, currentPackage); + } } } } @@ -584,6 +588,36 @@ protected void notifySourceElementRequestor( importReference.modifiers); } } +protected void notifySourceElementRequestor(ModuleDeclaration moduleDeclaration) { + boolean isInRange = + this.initialPosition <= moduleDeclaration.declarationSourceStart + && this.eofPosition >= moduleDeclaration.declarationSourceEnd; + ISourceElementRequestor.ModuleInfo info = new ISourceElementRequestor.ModuleInfo(); + if (isInRange) { + + int currentModifiers = moduleDeclaration.modifiers; + + // remember deprecation so as to not lose it below + //TODO + //boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(moduleDeclaration.annotations); + + info.declarationStart = moduleDeclaration.declarationSourceStart; + info.modifiers = currentModifiers; + // TODO + //typeInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag; + info.name = TypeConstants.MODULE_INFO_NAME; + info.nameSourceStart = moduleDeclaration.sourceStart; + info.nameSourceEnd = moduleDeclaration.sourceEnd; + info.moduleName = moduleDeclaration.moduleName; + // TODO + //info.annotations = moduleDeclaration.annotations; + info.node = moduleDeclaration; + this.requestor.enterModule(info); + fillModuleInfo(moduleDeclaration, info); + //TODO + this.requestor.exitModule(moduleDeclaration.declarationSourceEnd); + } +} protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType, ImportReference currentPackage) { if (CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeDeclaration.name)) return; @@ -607,7 +641,7 @@ protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boo char[][] interfaceNames = getInterfaceNames(typeDeclaration); int kind = TypeDeclaration.kind(typeDeclaration.modifiers); char[] implicitSuperclassName = TypeConstants.CharArray_JAVA_LANG_OBJECT; - ISourceElementRequestor.TypeInfo typeInfo = kind == TypeDeclaration.MODULE_DECL ? new ISourceElementRequestor.ModuleInfo(): new ISourceElementRequestor.TypeInfo(); + ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo(); typeInfo.typeAnnotated = ((typeDeclaration.bits & ASTNode.HasTypeAnnotations) != 0); if (isInRange) { int currentModifiers = typeDeclaration.modifiers; @@ -643,7 +677,6 @@ protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boo typeInfo.annotations = typeDeclaration.annotations; typeInfo.extraFlags = ExtraFlags.getExtraFlags(typeDeclaration); typeInfo.node = typeDeclaration; - fillModuleInfo(typeDeclaration, typeInfo, kind); this.requestor.enterType(typeInfo); switch (kind) { case TypeDeclaration.CLASS_DECL : @@ -720,11 +753,7 @@ protected void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boo this.nestedTypeIndex--; } } -private void fillModuleInfo(TypeDeclaration typeDeclaration, ISourceElementRequestor.TypeInfo typeInfo, int kind) { - if (kind != TypeDeclaration.MODULE_DECL) return; - ModuleDeclaration mod = (ModuleDeclaration)typeDeclaration; - ModuleInfo modInfo = (ModuleInfo)typeInfo; - modInfo.moduleName = mod.moduleName; +private void fillModuleInfo(ModuleDeclaration mod, ISourceElementRequestor.ModuleInfo modInfo) { if (mod.requiresCount > 0) { ISourceElementRequestor.RequiresInfo reqs[] = new ISourceElementRequestor.RequiresInfo[mod.requiresCount]; for (int i = 0; i < mod.requiresCount; i++) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java index 21c469ea49..3c4c496942 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java @@ -41,7 +41,6 @@ import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.ImportReference; import org.eclipse.jdt.internal.compiler.ast.Literal; import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; -import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; import org.eclipse.jdt.internal.compiler.ast.OperatorIds; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; @@ -501,7 +500,17 @@ private LocalVariable[] acceptMethodParameters(Argument[] arguments, JavaElement } return result; } +public void enterModule(ModuleInfo info) { + Object parentInfo = this.infoStack.peek(); + JavaElement parentHandle= (JavaElement) this.handleStack.peek(); + JavaElement handle = createModuleHandle(parentHandle, info); + + this.infoStack.push(info); + this.handleStack.push(handle); + + addToChildren(parentInfo, handle); +} /** * @see ISourceElementRequestor */ @@ -509,15 +518,9 @@ public void enterType(TypeInfo typeInfo) { Object parentInfo = this.infoStack.peek(); JavaElement parentHandle= (JavaElement) this.handleStack.peek(); - JavaElement handle = null; - if (typeInfo instanceof ModuleInfo) { - handle = createModuleHandle(parentHandle, (ModuleInfo) typeInfo); - } else { - handle = createTypeHandle(parentHandle, typeInfo); - //NB: occurenceCount is computed in resolveDuplicates - resolveDuplicates((SourceType) handle); - } - + JavaElement handle = createTypeHandle(parentHandle, typeInfo); + //NB: occurenceCount is computed in resolveDuplicates + resolveDuplicates((SourceType) handle); this.infoStack.push(typeInfo); this.handleStack.push(handle); @@ -585,7 +588,7 @@ private void acceptProvidedServices(ServicesInfo serInfo, JavaElementInfo parent addToChildren(parentInfo, handle); } private org.eclipse.jdt.internal.core.ModuleDescriptionInfo createModuleInfo(ModuleInfo modInfo, org.eclipse.jdt.internal.core.SourceModule handle) { - org.eclipse.jdt.internal.core.ModuleDescriptionInfo info = org.eclipse.jdt.internal.core.ModuleDescriptionInfo.createModule((ModuleDeclaration) modInfo.node); + org.eclipse.jdt.internal.core.ModuleDescriptionInfo info = org.eclipse.jdt.internal.core.ModuleDescriptionInfo.createModule(modInfo.node); info.setHandle(handle); info.setSourceRangeStart(modInfo.declarationStart); info.setFlags(modInfo.modifiers); @@ -819,32 +822,34 @@ public void exitMethod(int declarationEnd, Expression defaultValue) { this.handleStack.pop(); this.infoStack.pop(); } +public void exitModule(int declarationEnd) { + ModuleInfo moduleInfo = (ModuleInfo) this.infoStack.peek(); + SourceModule handle = (SourceModule) this.handleStack.peek(); + JavaProject proj = (JavaProject) handle.getAncestor(IJavaElement.JAVA_PROJECT); + if (proj != null) { + try { + org.eclipse.jdt.internal.core.SourceModule moduleDecl = handle; + org.eclipse.jdt.internal.core.ModuleDescriptionInfo info = createModuleInfo(moduleInfo, moduleDecl); + info.setSourceRangeEnd(declarationEnd); + info.children = getChildren(info); + this.unitInfo.setModule(moduleDecl); + proj.setModuleDescription(moduleDecl); + } catch (JavaModelException e) { + // Unexpected while creating + } + } + this.handleStack.pop(); + this.infoStack.pop(); +} /** * @see ISourceElementRequestor */ public void exitType(int declarationEnd) { TypeInfo typeInfo = (TypeInfo) this.infoStack.peek(); - if (typeInfo instanceof ModuleInfo) { - SourceModule handle = (SourceModule) this.handleStack.peek(); - JavaProject proj = (JavaProject) handle.getAncestor(IJavaElement.JAVA_PROJECT); - if (proj != null) { - try { - org.eclipse.jdt.internal.core.SourceModule moduleDecl = handle; - org.eclipse.jdt.internal.core.ModuleDescriptionInfo info = createModuleInfo((ModuleInfo) typeInfo, moduleDecl); - info.setSourceRangeEnd(declarationEnd); - info.children = getChildren(info); - this.unitInfo.setModule(moduleDecl); - proj.setModuleDescription(moduleDecl); - } catch (JavaModelException e) { - // Unexpected while creating - } - } - } else { - SourceType handle = (SourceType) this.handleStack.peek(); - SourceTypeElementInfo info = createTypeInfo(typeInfo, handle); - info.setSourceRangeEnd(declarationEnd); - info.children = getChildren(typeInfo); - } + SourceType handle = (SourceType) this.handleStack.peek(); + SourceTypeElementInfo info = createTypeInfo(typeInfo, handle); + info.setSourceRangeEnd(declarationEnd); + info.children = getChildren(typeInfo); this.handleStack.pop(); this.infoStack.pop(); } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java index 27941fdcb1..b1db2847b0 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java @@ -396,9 +396,6 @@ public void enterType(TypeInfo typeInfo) { case TypeDeclaration.ENUM_DECL: enterEnum(typeInfo); break; - case TypeDeclaration.MODULE_DECL: - enterModule((ModuleInfo) typeInfo); - break; } } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java index 321a569e9d..3e6f13802c 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java @@ -2911,14 +2911,14 @@ private void reportMatching(ProvidesStatement[] provides, ModuleDeclaration modu if (intf != null) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(intf); if (level != null) - this.patternLocator.matchReportReference(intf, ips, null, null, module.binding, level.intValue(), this); + this.patternLocator.matchReportReference(intf, ips, null, null, module.moduleBinding, level.intValue(), this); } TypeReference[] impls = service.implementations; for (TypeReference impl : impls) { if (impl != null) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(impl); if (level != null) - this.patternLocator.matchReportReference(impl, ips, null, null, module.binding, level.intValue(), this); + this.patternLocator.matchReportReference(impl, ips, null, null, module.moduleBinding, level.intValue(), this); } } } @@ -2927,16 +2927,14 @@ private void reportMatching(ProvidesStatement[] provides, ModuleDeclaration modu private void reportMatching(UsesStatement[] uses, ModuleDeclaration module, MatchingNodeSet nodeSet, IModuleDescription moduleDesc) { if (uses != null && uses.length > 0) { try { - String[] usedServices = moduleDesc.getUsedServices(); for (int i = 0, l = uses.length; i < l; ++i) { UsesStatement service = uses[i]; - String usedService = usedServices[i]; - + TypeReference intf = service.serviceInterface; if (intf != null) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(intf); if (level != null) { - this.patternLocator.matchReportReference(intf, moduleDesc, null, null, module.binding, level.intValue(), this); + this.patternLocator.matchReportReference(intf, moduleDesc, null, null, module.moduleBinding, level.intValue(), this); } } } @@ -2952,8 +2950,9 @@ private void reportMatching(UsesStatement[] uses, ModuleDeclaration module, Matc * search pattern (i.e. the ones in the matching nodes set) */ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int accuracy, MatchingNodeSet nodeSet, int occurrenceCount) throws CoreException { - if (TypeDeclaration.kind(type.modifiers) == TypeDeclaration.MODULE_DECL) { - reportMatching((ModuleDeclaration) type, parent, accuracy, nodeSet, occurrenceCount); + if (type.isModuleInfo()) { + ModuleDeclaration mod = type.scope.compilationUnitScope().referenceContext.moduleDeclaration; + reportMatching(mod, parent, accuracy, nodeSet, occurrenceCount); return; } // create type handle |