diff options
author | Till Brychcy | 2019-07-02 20:15:17 +0000 |
---|---|---|
committer | Till Brychcy | 2019-07-02 20:15:17 +0000 |
commit | bb25e29c367ff12180b5092261f8df5715444abb (patch) | |
tree | 0cd9f5034a2a2fc092e8f9569005576c90731551 | |
parent | 1fbf13c28311e9090a4ae402b14adbc440f874ec (diff) | |
download | eclipse.jdt.core-bb25e29c367ff12180b5092261f8df5715444abb.tar.gz eclipse.jdt.core-bb25e29c367ff12180b5092261f8df5715444abb.tar.xz eclipse.jdt.core-bb25e29c367ff12180b5092261f8df5715444abb.zip |
Bug 547181 - [9][impl] Reconsider representation and lookup of packagesI20190702-1800
(SplitPackageBinding)
Simplifications (orginally suggested in
https://git.eclipse.org/r/#/c/143581/)
- remove param considerRequiredModules that was always true, simplify
accordingly
- remove unnessary code
Change-Id: I53bc585923ecba31feb7006c7aa6754117d5cadc
2 files changed, 13 insertions, 28 deletions
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 46aba9e14c..7082388ce7 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 @@ -774,7 +774,7 @@ private PackageBinding computePackageFrom(char[][] constantPoolName, boolean isM } } } else { - packageBinding = this.module.getVisiblePackage(parent, constantPoolName[i], true); + packageBinding = this.module.getVisiblePackage(parent, constantPoolName[i]); } } if (packageBinding == null || packageBinding == TheNotFoundPackage) { @@ -1094,11 +1094,8 @@ public PackageBinding createPackage(char[][] compoundName) { packageBinding = getPackage0(compoundName[0]); if (packageBinding == null || packageBinding == TheNotFoundPackage) { packageBinding = new PlainPackageBinding(compoundName[0], this, this.module); - this.knownPackages.put(compoundName[0], packageBinding); - if (this.module != null) { - packageBinding = this.module.addPackage(packageBinding, true); - this.knownPackages.put(compoundName[0], packageBinding); // update in case of split package - } + packageBinding = this.module.addPackage(packageBinding, true); + this.knownPackages.put(compoundName[0], packageBinding); // update in case of split package } } @@ -1647,8 +1644,7 @@ PackageBinding getTopLevelPackage(char[] name) { return packageBinding; } if (this.useModuleSystem) { - if (this.module != null) - packageBinding = this.module.getTopLevelPackage(name); + packageBinding = this.module.getTopLevelPackage(name); } else { if (this.nameEnvironment.isPackage(null, name)) { this.knownPackages.put(name, packageBinding = new PlainPackageBinding(name, this, this.module)); 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 a32ae2d34f..3fd3111b1b 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 @@ -103,7 +103,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule { char[][] declaringModuleNames = moduleEnv.getUniqueModulesDeclaringPackage(compoundName, nameForLookup()); if (declaringModuleNames != null && CharOperation.containsEqual(declaringModuleNames, this.moduleName)) { declaredPackage = getOrCreateDeclaredPackage(compoundName); - this.declaredPackages.put(flatName, declaredPackage); } } return declaredPackage; @@ -543,11 +542,10 @@ public class ModuleBinding extends Binding implements IUpdatableModule { PackageBinding binding = this.environment.getPackage0(name); if (binding != null) return binding; - binding = getVisiblePackage(null, name, true); + binding = getVisiblePackage(null, name); // remember: if (binding != null) { this.environment.knownPackages.put(name, binding); - binding = addPackage(binding, false); // no further lookup needed, binding is already complete (split?) } else { this.environment.knownPackages.put(name, LookupEnvironment.TheNotFoundPackage); } @@ -559,7 +557,7 @@ public class ModuleBinding extends Binding implements IUpdatableModule { } // Given parent is visible in this module, see if there is sub package named name visible in this module - PackageBinding getVisiblePackage(PackageBinding parent, char[] name, boolean considerRequiredModules) { + PackageBinding getVisiblePackage(PackageBinding parent, char[] name) { // check caches in PackageBinding/LookupEnvironment, which contain the full SplitPackageBinding if appropriate: PackageBinding pkg; if (parent != null) @@ -580,7 +578,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule { PackageBinding binding = this.declaredPackages.get(fullFlatName); char[][] declaringModuleNames = null; - boolean packageMayBeIncomplete = !considerRequiredModules; if (this.environment.useModuleSystem) { IModuleAwareNameEnvironment moduleEnv = (IModuleAwareNameEnvironment) this.environment.nameEnvironment; declaringModuleNames = moduleEnv.getUniqueModulesDeclaringPackage(subPkgCompoundName, nameForLookup()); @@ -598,7 +595,7 @@ public class ModuleBinding extends Binding implements IUpdatableModule { // declared here, not yet known, so create it now: binding = new PlainPackageBinding(subPkgCompoundName, parent, this.environment, this); } - } else if (considerRequiredModules) { + } else { // visible but foreign (when current is unnamed or auto): for (char[] declaringModuleName : declaringModuleNames) { ModuleBinding declaringModule = this.environment.root.getModule(declaringModuleName); @@ -623,14 +620,11 @@ public class ModuleBinding extends Binding implements IUpdatableModule { } // enrich with split-siblings from visible modules: - if (considerRequiredModules) { - if (parent != null && binding != null) - parent.addPackage(binding, this); // preliminarily add to avoid creating duplicates, will be updated below - binding = combineWithPackagesFromOtherRelevantModules(binding, subPkgCompoundName, declaringModuleNames); - } + if (parent != null && binding != null) + parent.addPackage(binding, this); // preliminarily add to avoid creating duplicates, will be updated below + binding = combineWithPackagesFromOtherRelevantModules(binding, subPkgCompoundName, declaringModuleNames); if (binding == null || !binding.isValidBinding()) { if (parent != null - && !packageMayBeIncomplete // don't remember package that may still lack some siblings && !(parent instanceof SplitPackageBinding)) // don't store problem into SPB, because from different focus things may look differently { if (binding == null) { @@ -647,8 +641,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule { } else if (parent != null) { binding = parent.addPackage(binding, this); } - if (packageMayBeIncomplete) - return binding; return addPackage(binding, false); } @@ -661,9 +653,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule { * </p> */ public PackageBinding getVisiblePackage(char[][] qualifiedPackageName) { - return getVisiblePackage(qualifiedPackageName, true); - } - PackageBinding getVisiblePackage(char[][] qualifiedPackageName, boolean considerRequiredModules) { if (qualifiedPackageName == null || qualifiedPackageName.length == 0) { return this.environment.defaultPackage; } @@ -674,7 +663,7 @@ public class ModuleBinding extends Binding implements IUpdatableModule { // check each sub package for (int i = 1; i < qualifiedPackageName.length; i++) { - PackageBinding binding = getVisiblePackage(parent, qualifiedPackageName[i], considerRequiredModules); + PackageBinding binding = getVisiblePackage(parent, qualifiedPackageName[i]); if (binding == null || binding == LookupEnvironment.TheNotFoundPackage) { return null; } @@ -695,12 +684,12 @@ public class ModuleBinding extends Binding implements IUpdatableModule { // 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, true); + return getVisiblePackage(null, packageName); } PackageBinding binding = null; PackageBinding parent = getVisiblePackage(parentPackageName); if (parent != null && parent != LookupEnvironment.TheNotFoundPackage) { - binding = getVisiblePackage(parent, packageName, true); + binding = getVisiblePackage(parent, packageName); } if (binding != null) return addPackage(binding, false); |