Fix for part one bug 486988 [1.9][code completion] Basic framework for
code completion in module-info.java
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExportReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExportReference.java
index 2fa4ffa..47b5926 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExportReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExportReference.java
@@ -54,7 +54,7 @@
boolean errorsExist = false;
ModuleDeclaration exportingModule = (ModuleDeclaration)scope.referenceContext();
ModuleBinding src = exportingModule.moduleBinding;
- PackageBinding pkg = this.resolvedPackage = src.getExportedPackage(this.pkgName);
+ PackageBinding pkg = this.resolvedPackage = src != null ? src.getExportedPackage(this.pkgName) : null;
if (pkg == null) {
// TODO: need a check for empty package as well
scope.problemReporter().invalidExportReference(IProblem.ExportedPackageDoesNotExistOrIsEmpty, this);
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 8e78d5e..6374d42 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
@@ -88,7 +88,7 @@
Set<ModuleBinding> requiredModules = new HashSet<ModuleBinding>();
for(int i = 0; i < this.requiresCount; i++) {
ModuleReference ref = this.requires[i];
- if (ref.resolve(this.scope) != null) {
+ if (ref != null && ref.resolve(this.scope) != null) {
if (!requiredModules.add(ref.binding)) {
this.scope.problemReporter().duplicateModuleReference(IProblem.DuplicateRequires, ref);
}
@@ -100,7 +100,7 @@
Set<PackageBinding> exportedPkgs = new HashSet<>();
for (int i = 0; i < this.exportsCount; i++) {
ExportReference ref = this.exports[i];
- if (ref.resolve(this.scope)) {
+ if (ref != null && ref.resolve(this.scope)) {
if (!exportedPkgs.add(ref.resolvedPackage)) {
this.scope.problemReporter().invalidExportReference(IProblem.DuplicateExports, ref);
}
@@ -108,7 +108,7 @@
}
for(int i = 0; i < this.usesCount; i++) {
Set<TypeBinding> allTypes = new HashSet<TypeBinding>();
- if (this.uses[i].resolveType(this.scope) != null) {
+ if (this.uses[i] != null && this.uses[i].resolveType(this.scope) != null) {
if (!allTypes.add(this.uses[i].resolvedType)) {
this.scope.problemReporter().duplicateTypeReference(IProblem.DuplicateUses, this.uses[i]);
}
@@ -116,9 +116,9 @@
}
Map<TypeBinding, TypeBinding> services = new HashMap<TypeBinding, TypeBinding>(this.servicesCount);
for(int i = 0; i < this.servicesCount; i++) {
- if (this.interfaces[i].resolveType(this.scope) != null) {
+ if (this.interfaces[i] != null && this.interfaces[i].resolveType(this.scope) != null) {
TypeBinding inf = this.interfaces[i].resolvedType;
- if (this.implementations[i].resolveType(this.scope) != null) {
+ if (this.implementations[i] != null && this.implementations[i].resolveType(this.scope) != null) {
ReferenceBinding imp = (ReferenceBinding) this.implementations[i].resolvedType;
if (inf.isValidBinding() && imp.isValidBinding()) {
validate(this.interfaces[i], this.implementations[i]);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
index 06b9496..f78b23d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java
@@ -1038,7 +1038,7 @@
return;
}
if (partialMatch) {
- seekModuleAwarePartialPackageFragmentsPartial(name, requestor, context);
+ seekModuleAwarePartialPackageFragments(name, requestor, context);
return;
}
@@ -1046,44 +1046,11 @@
int pkgIndex = this.packageFragments.getIndex(splittedName);
if (pkgIndex == -1)
return;
- Object value = this.packageFragments.valueTable[pkgIndex];
- // reuse existing String[]
- String[] pkgName = (String[]) this.packageFragments.keyTable[pkgIndex];
- context.getEnvironment().forEach(r -> {
- if (value instanceof PackageFragmentRoot) {
- Object toCompare = value;
- // TODO: need better representation of IModuleEnvironment and IModulePathEntry
- // in the model to avoid comparison based on instance
- if (r instanceof JavaProject) {
- toCompare = ((PackageFragmentRoot)value).getJavaProject();
- }
- if (value.equals(toCompare)) {
- PackageFragmentRoot root = (PackageFragmentRoot) value;
- requestor.acceptPackageFragment(root.getPackageFragment(pkgName));
- }
- } else {
- IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
- if (roots != null) {
- for (int i = 0, length = roots.length; i < length; i++) {
- if (requestor.isCanceled())
- return;
- PackageFragmentRoot root = (PackageFragmentRoot) roots[i];
- Object toCompare = root;
- if (r instanceof JavaProject) {
- toCompare = root.getJavaProject();
- }
- if (root.equals(toCompare))
- requestor.acceptPackageFragment(root.getPackageFragment(pkgName));
- }
- }
- }
- });
-
- //checkModulePackages(requestor, context, pkgIndex);
+ checkModulePackages(requestor, context, pkgIndex);
}
- private void seekModuleAwarePartialPackageFragmentsPartial(String name, IJavaElementRequestor requestor, IModuleContext context) {
+ private void seekModuleAwarePartialPackageFragments(String name, IJavaElementRequestor requestor, IModuleContext context) {
boolean allPrefixMatch = CharOperation.equals(name.toCharArray(), CharOperation.ALL_PREFIX);
Arrays.stream(this.packageFragments.keyTable)
.filter(k -> k != null)