Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2019-07-04 17:30:57 +0000
committerTill Brychcy2019-07-04 17:31:34 +0000
commita73c2353d7810c3b248c523da998d659181ac7d8 (patch)
tree58a91be8b82060e808e3c71ceadb0f5e79310562
parent50ecbd5c524eb4fbbb539a28ce70a3d0ec8c30cb (diff)
downloadeclipse.jdt.core-I20190704-1800.tar.gz
eclipse.jdt.core-I20190704-1800.tar.xz
eclipse.jdt.core-I20190704-1800.zip
Bug 547181 - [9][impl] Reconsider representation and lookup of packagesI20190704-1800
(SplitPackageBinding) simplifications: - use PlainPackageBinding - eliminate ModuleBinding.getPackage Change-Id: I3d55d8a22d6c6c03b535b820a4312f957b7eee65
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java10
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java46
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java22
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java3
6 files changed, 21 insertions, 67 deletions
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java
index 81a5f8a957..592eae84df 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl9.java
@@ -174,15 +174,7 @@ public class ElementsImpl9 extends ElementsImpl {
final char[][] compoundName = CharOperation.splitOn('.', name.toString().toCharArray());
PackageBinding p = null;
if (mBinding != null) {
-
- int length = compoundName.length;
- if (length > 1) {
- char[][] parent = new char[compoundName.length - 1][];
- System.arraycopy(compoundName, 0, parent, 0, length - 1);
- p = mBinding.getPackage(parent, compoundName[length - 1]);
- } else {
- p = mBinding.getTopLevelPackage(compoundName[0]);
- }
+ p = mBinding.getVisiblePackage(compoundName);
} else {
p = _env.getLookupEnvironment().createPackage(compoundName);
}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
index 62e8caedee..2b67e46236 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl.java
@@ -34,7 +34,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
-import org.eclipse.jdt.internal.compiler.lookup.SplitPackageBinding;
+import org.eclipse.jdt.internal.compiler.lookup.PlainPackageBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
public class ModuleElementImpl extends ElementImpl implements ModuleElement {
@@ -54,10 +54,6 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
this.binding = binding;
}
- private PackageBinding getModulesPackageBinding(PackageBinding binding) {
- return binding.getIncarnation(this.binding);
- }
-
@Override
public ElementKind getKind() {
return ElementKind.MODULE;
@@ -82,40 +78,28 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
@Override
public List<? extends Element> getEnclosedElements() {
ModuleBinding module = this.binding;
- Set<PackageBinding> unique = new HashSet<>();
- for (PackageBinding p : module.declaredPackages.values()) {
- if (p == null)
- continue;
- if (p instanceof SplitPackageBinding) {
- // select from incarnations the unique package containing CUs, if any:
- for (PackageBinding incarnation : ((SplitPackageBinding) p).incarnations) {
- if (incarnation.enclosingModule == module && incarnation.hasCompilationUnit(true)) {
- unique.add(getModulesPackageBinding(p));
- }
- }
+ Set<PlainPackageBinding> unique = new HashSet<>();
+ for (PlainPackageBinding p : module.declaredPackages.values()) {
+ if (!p.hasCompilationUnit(true))
continue;
- } else {
- if (!p.hasCompilationUnit(true))
- continue;
- }
- unique.add(getModulesPackageBinding(p));
+ unique.add(p);
}
if (module.isUnnamed()) {
- PackageBinding def = module.environment.defaultPackage;
+ PlainPackageBinding def = module.environment.defaultPackage;
// FIXME: Does it have any impact for unnamed modules - default package combo?
if (def != null && def.hasCompilationUnit(true)) {
unique.add(def);
}
} else {
- for (PackageBinding pBinding : this.binding.getExports()) {
- unique.add(getModulesPackageBinding(pBinding));
+ for (PlainPackageBinding pBinding : this.binding.getExports()) {
+ unique.add(pBinding);
}
- for (PackageBinding pBinding : this.binding.getOpens()) {
- unique.add(getModulesPackageBinding(pBinding));
+ for (PlainPackageBinding pBinding : this.binding.getOpens()) {
+ unique.add(pBinding);
}
}
List<Element> enclosed = new ArrayList<>(unique.size());
- for (PackageBinding p : unique) {
+ for (PlainPackageBinding p : unique) {
PackageElement pElement = (PackageElement) _env.getFactory().newElement(p);
enclosed.add(pElement);
}
@@ -146,9 +130,8 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
if (this.directives == null)
this.directives = new ArrayList<>();
- PackageBinding[] packs = this.binding.getExports();
- for (PackageBinding exp : packs) {
- exp = getModulesPackageBinding(exp);
+ PlainPackageBinding[] packs = this.binding.getExports();
+ for (PlainPackageBinding exp : packs) {
this.directives.add(new ExportsDirectiveImpl(exp));
}
Set<ModuleBinding> transitive = new HashSet<>();
@@ -173,8 +156,7 @@ public class ModuleElementImpl extends ElementImpl implements ModuleElement {
this.directives.add(new ProvidesDirectiveImpl(tBinding));
}
packs = this.binding.getOpens();
- for (PackageBinding exp : packs) {
- exp = getModulesPackageBinding(exp);
+ for (PlainPackageBinding exp : packs) {
this.directives.add(new OpensDirectiveImpl(exp));
}
return this.directives;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
index 0f3f6d2f13..35d796223c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
@@ -764,13 +764,14 @@ private PackageBinding computePackageFrom(char[][] constantPoolName, boolean isM
if ((packageBinding = parent.getPackage0(constantPoolName[i])) == null || packageBinding == TheNotFoundPackage) {
if (this.useModuleSystem) {
if (this.module.isUnnamed()) {
+ char[][] currentCompoundName = CharOperation.arrayConcat(parent.compoundName, constantPoolName[i]);
char[][] declaringModules = ((IModuleAwareNameEnvironment) this.nameEnvironment).getModulesDeclaringPackage(
- CharOperation.arrayConcat(parent.compoundName, constantPoolName[i]), ModuleBinding.ANY);
+ currentCompoundName, ModuleBinding.ANY);
if (declaringModules != null) {
for (char[] mod : declaringModules) {
ModuleBinding declaringModule = this.root.getModule(mod);
if (declaringModule != null)
- packageBinding = SplitPackageBinding.combine(declaringModule.getPackage(parent.compoundName, constantPoolName[i]), packageBinding, this.module);
+ packageBinding = SplitPackageBinding.combine(declaringModule.getVisiblePackage(currentCompoundName), packageBinding, this.module);
}
}
} else {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
index 5b481021e3..6922d17913 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
@@ -673,28 +673,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
}
/**
- * Answer a package, that is a member named <em>packageName</em> of the parent package
- * named <em>parentPackageName</em>.
- * Considers all packages that are visible to the current module,
- * i.e., we consider locally declared packages and packages in all modules
- * read by the current module.
- * Accessibility (via package exports) is <strong>not</strong> checked.
- */
- public PackageBinding getPackage(char[][] parentPackageName, char[] packageName) {
- // Returns a package binding if there exists such a package in the context of this module and it is observable
- // A package is observable if it is declared in this module or it is exported by some required module
- if (parentPackageName == null || parentPackageName.length == 0) {
- return getVisiblePackage(null, packageName);
- }
- PackageBinding binding = null;
- PackageBinding parent = getVisiblePackage(parentPackageName);
- if (parent != null) {
- binding = getVisiblePackage(parent, packageName);
- }
- return binding;
- }
-
- /**
* Check if the given package is declared in this module,
* and if so, remember this fact for later.
* The package can be a {@code SplitPackageBinding} in which case
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
index 4a79811893..506564509a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
@@ -140,7 +140,7 @@ public char[] computeUniqueKey(boolean isLeaf) {
}
protected PackageBinding findPackage(char[] name, ModuleBinding module) {
// delegate to the module to consider the module graph:
- return module.getPackage(this.compoundName, name);
+ return module.getVisiblePackage(CharOperation.arrayConcat(this.compoundName, name));
}
/* Answer the subpackage named name; ask the oracle for the package if its not in the cache.
* Answer null if it could not be resolved.
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
index bfa5a25ca9..ee0440328a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
@@ -163,9 +163,10 @@ public class SplitPackageBinding extends PackageBinding {
@Override
protected PackageBinding findPackage(char[] name, ModuleBinding module) {
+ char[][] subpackageCompoundName = CharOperation.arrayConcat(this.compoundName, name);
Set<PackageBinding> candidates = new HashSet<>();
for (ModuleBinding candidateModule : this.declaringModules) {
- PackageBinding candidate = super.findPackage(name, candidateModule);
+ PackageBinding candidate = candidateModule.getVisiblePackage(subpackageCompoundName);
if (candidate != null
&& candidate != LookupEnvironment.TheNotFoundPackage
&& ((candidate.tagBits & TagBits.HasMissingType) == 0))

Back to the top