/** * Answer the package of the given qualified name and visible in this module, * or {@code null} if no such package exists. * Accessibility (based on package exports) is <strong>not</strong> checked. * <p> * May answer a {@link SplitPackageBinding}. * </p> */ public PackageBinding getVisiblePackage(char[][] qualifiedPackageName) { return getVisiblePackage(qualifiedPackageName, true); } PackageBinding getVisiblePackage(char[][] qualifiedPackageName, boolean considerRequiredModules) {
/** * 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 && parent != LookupEnvironment.TheNotFoundPackage) { binding = getVisiblePackage(parent, packageName); } if (binding != null) return addPackage(binding, false); return null; }
/** * 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, true); } PackageBinding binding = null; PackageBinding parent = getVisiblePackage(parentPackageName); if (parent != null && parent != LookupEnvironment.TheNotFoundPackage) { binding = getVisiblePackage(parent, packageName, true); } if (binding != null) return addPackage(binding, false); return null; }
PackageBinding combineWithSiblings(PackageBinding childPackage, char[] name, ModuleBinding module) { ModuleBinding primaryModule = childPackage != null ? childPackage.enclosingModule : this.enclosingModule; // see if other incarnations contribute to the child package, too: boolean activeSave = primaryModule.isPackageLookupActive; primaryModule.isPackageLookupActive = true; try { for (PackageBinding incarnation : this.incarnations) { ModuleBinding moduleBinding = incarnation.enclosingModule; if (moduleBinding == module) continue; PackageBinding next = moduleBinding.getVisiblePackage(incarnation, name, false); childPackage = combine(next, childPackage, primaryModule); } return childPackage; } finally { primaryModule.isPackageLookupActive = activeSave; } }
PackageBinding getVisiblePackage(char[][] qualifiedPackageName, boolean considerRequiredModules) { if (qualifiedPackageName == null || qualifiedPackageName.length == 0) { return this.environment.defaultPackage; } PackageBinding parent = getTopLevelPackage(qualifiedPackageName[0]); if (parent == null || parent == LookupEnvironment.TheNotFoundPackage) return null; // check each sub package for (int i = 1; i < qualifiedPackageName.length; i++) { PackageBinding binding = getVisiblePackage(parent, qualifiedPackageName[i], considerRequiredModules); if (binding == null || binding == LookupEnvironment.TheNotFoundPackage) { return null; } parent = binding; } return parent; }
PackageBinding combineWithSiblings(PackageBinding childPackage, char[] name, ModuleBinding module) { ModuleBinding primaryModule = childPackage != null ? childPackage.enclosingModule : this.enclosingModule; // see if other incarnations contribute to the child package, too: boolean activeSave = primaryModule.isPackageLookupActive; primaryModule.isPackageLookupActive = true; try { for (PackageBinding incarnation : this.incarnations) { ModuleBinding moduleBinding = incarnation.enclosingModule; if (moduleBinding == module) continue; PackageBinding next = moduleBinding.getVisiblePackage(incarnation, name); // TODO(SHMOD): reduce split-package work during this invocation? childPackage = combine(next, childPackage, primaryModule); } return childPackage; } finally { primaryModule.isPackageLookupActive = activeSave; } }
private PackageBinding combineWithPackagesFromOtherRelevantModules(PackageBinding currentBinding, char[][] compoundName, char[][] declaringModuleNames) { boolean save = this.isPackageLookupActive; this.isPackageLookupActive = true; try { char[] singleName = compoundName[compoundName.length-1]; PackageBinding parent = currentBinding != null ? currentBinding.parent : null; for (ModuleBinding moduleBinding : otherRelevantModules(declaringModuleNames)) { if (!moduleBinding.isPackageLookupActive) { PackageBinding nextBinding = parent != null ? moduleBinding.getVisiblePackage(parent, singleName, false) : moduleBinding.getVisiblePackage(compoundName, false); currentBinding = SplitPackageBinding.combine(nextBinding, currentBinding, this); } } return currentBinding; } finally { this.isPackageLookupActive = save; } }
/** * Answer the package of the given qualified name and visible in this module, * or {@code null} if no such package exists. * Accessibility (based on package exports) is <strong>not</strong> checked. * <p> * May answer a {@link SplitPackageBinding}. * </p> */ public PackageBinding getVisiblePackage(char[][] qualifiedPackageName) { if (qualifiedPackageName == null || qualifiedPackageName.length == 0) { return this.environment.defaultPackage; } PackageBinding parent = getTopLevelPackage(qualifiedPackageName[0]); if (parent == null || parent == LookupEnvironment.TheNotFoundPackage) return null; // check each sub package for (int i = 1; i < qualifiedPackageName.length; i++) { PackageBinding binding = getVisiblePackage(parent, qualifiedPackageName[i]); if (binding == null || binding == LookupEnvironment.TheNotFoundPackage) { return null; } parent = binding; } return parent; }
private PackageBinding combineWithPackagesFromRequired(PackageBinding currentBinding, char[][] compoundName) { boolean save = this.isPackageLookupActive; this.isPackageLookupActive = true; try { for (ModuleBinding moduleBinding : getAllRequiredModules()) if (!moduleBinding.isPackageLookupActive) currentBinding = SplitPackageBinding.combine(moduleBinding.getVisiblePackage(compoundName), currentBinding, this); return currentBinding; } finally { this.isPackageLookupActive = save; } }
public void checkPackageConflict(CompilationUnitScope scope) { ModuleBinding module = scope.module(); PackageBinding visiblePackage = module.getVisiblePackage(this.tokens); if (visiblePackage instanceof SplitPackageBinding) { Set<ModuleBinding> declaringMods = new HashSet<>(); for (PackageBinding incarnation : ((SplitPackageBinding) visiblePackage).incarnations) { if (incarnation.enclosingModule != module && module.canAccess(incarnation)) declaringMods.add(incarnation.enclosingModule); } if (!declaringMods.isEmpty()) { scope.problemReporter().conflictingPackagesFromOtherModules(this, declaringMods); } } }
public void checkPackageConflict(CompilationUnitScope scope) { ModuleBinding module = scope.module(); PackageBinding visiblePackage = module.getVisiblePackage(this.tokens); if (visiblePackage instanceof SplitPackageBinding) { Set<ModuleBinding> declaringMods = new HashSet<>(); for (PackageBinding incarnation : ((SplitPackageBinding) visiblePackage).incarnations) { if (incarnation.enclosingModule != module && module.canAccess(incarnation)) declaringMods.add(incarnation.enclosingModule); } if (!declaringMods.isEmpty()) { scope.problemReporter().conflictingPackagesFromOtherModules(this, declaringMods); } } }
@Override public void addExports(char[] packageName, char[][] targetModules) { PackageBinding declaredPackage = getVisiblePackage(CharOperation.splitOn('.', packageName)); if (declaredPackage != null && declaredPackage.isValidBinding()) addResolvedExport(declaredPackage, targetModules); }
@Override public void addExports(char[] packageName, char[][] targetModules) { PackageBinding declaredPackage = getVisiblePackage(CharOperation.splitOn('.', packageName)); if (declaredPackage != null && declaredPackage.isValidBinding()) addResolvedExport(declaredPackage, targetModules); }
@Override public void addReads(char[] requiredModuleName) { ModuleBinding requiredModule = this.environment.getModule(requiredModuleName); if (requiredModule != null) { int len = this.requires.length; if (len == 0) { this.requires = new ModuleBinding[] { requiredModule }; } else { System.arraycopy(this.requires, 0, this.requires = new ModuleBinding[len+1], 0, len); this.requires[len] = requiredModule; } } else { // TODO(SHMOD) report error } // update known packages: HashtableOfPackage knownPackages = this.environment.knownPackages; for (int i = 0; i < knownPackages.valueTable.length; i++) { PackageBinding packageBinding = knownPackages.valueTable[i]; if (packageBinding == null) continue; PackageBinding newBinding = requiredModule.getVisiblePackage(packageBinding.compoundName); newBinding = SplitPackageBinding.combine(newBinding, packageBinding, this); if (packageBinding != newBinding) { knownPackages.valueTable[i] = newBinding; if (this.declaredPackages.containsKey(newBinding.readableName())) this.declaredPackages.put(newBinding.readableName(), newBinding); } } } @Override
@Override public void addReads(char[] requiredModuleName) { ModuleBinding requiredModule = this.environment.getModule(requiredModuleName); if (requiredModule != null) { int len = this.requires.length; if (len == 0) { this.requires = new ModuleBinding[] { requiredModule }; } else { System.arraycopy(this.requires, 0, this.requires = new ModuleBinding[len+1], 0, len); this.requires[len] = requiredModule; } } else { // TODO(SHMOD) report error } // update known packages: HashtableOfPackage knownPackages = this.environment.knownPackages; for (int i = 0; i < knownPackages.valueTable.length; i++) { PackageBinding packageBinding = knownPackages.valueTable[i]; if (packageBinding == null) continue; PackageBinding newBinding = requiredModule.getVisiblePackage(packageBinding.compoundName); newBinding = SplitPackageBinding.combine(newBinding, packageBinding, this); if (packageBinding != newBinding) { knownPackages.valueTable[i] = newBinding; if (this.declaredPackages.containsKey(newBinding.readableName())) this.declaredPackages.put(newBinding.readableName(), newBinding); } } } @Override
PackageBinding getDeclaredPackage(char[][] parentName, char[] name) { // check caches: char[][] subPkgCompoundName = CharOperation.arrayConcat(parentName, name); char[] fullFlatName = CharOperation.concatWith(subPkgCompoundName, '.'); PackageBinding pkg = this.declaredPackages.get(fullFlatName); if (pkg != null) return pkg; PackageBinding parent = parentName.length == 0 ? null : getVisiblePackage(parentName); PackageBinding binding = new PackageBinding(subPkgCompoundName, parent, this.environment, this); // remember this.declaredPackages.put(fullFlatName, binding); if (parent == null) { this.environment.knownPackages.put(name, binding); } return binding; } // Given parent is visible in this module, see if there is sub package named name visible in this module
PackageBinding getDeclaredPackage(char[][] parentName, char[] name) { // check caches: char[][] subPkgCompoundName = CharOperation.arrayConcat(parentName, name); char[] fullFlatName = CharOperation.concatWith(subPkgCompoundName, '.'); PackageBinding pkg = this.declaredPackages.get(fullFlatName); if (pkg != null) return pkg; PackageBinding parent = parentName.length == 0 ? null : getVisiblePackage(parentName); PackageBinding binding = new PackageBinding(subPkgCompoundName, parent, this.environment, this); // remember this.declaredPackages.put(fullFlatName, binding); if (parent == null) { this.environment.knownPackages.put(name, binding); } return binding; } // Given parent is visible in this module, see if there is sub package named name visible in this module
/** * Return a package binding if there exists a package named name in this module's context and it can be seen by this module. * A package can be seen by this module if it is declared in this module or any other module read by this module * (JLS 7.4.3 for packages based on JLS 7.3 for compilation units). * Package exports are not considered for visibility check (only when checking "uniquely visible" (JLS 7.4.3)). * <p> * The returned package may be a {@link SplitPackageBinding}, if more than one package of the given name is visible. * </p> * <p> * When asked via the unnamed module or an automatic module all other named modules are considered visible. * </p> */ public PackageBinding getTopLevelPackage(char[] name) { // check caches: PackageBinding binding = this.declaredPackages.get(name); if (binding != null) return binding; binding = this.environment.getPackage0(name); if (binding != null) return binding; binding = getVisiblePackage(null, name, true); // remember: if (binding != null) { this.environment.knownPackages.put(name, binding); binding = addPackage(binding, false); } else { this.environment.knownPackages.put(name, LookupEnvironment.TheNotFoundPackage); } return binding; }
protected PackageBinding resolvePackageReference(Scope scope) { if (this.resolvedPackage != null) return this.resolvedPackage; ModuleDeclaration exportingModule = scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleBinding src = exportingModule.binding; this.resolvedPackage = src != null ? src.getVisiblePackage(this.pkgRef.tokens) : null; int problemId = IProblem.PackageDoesNotExistOrIsEmpty; if (this.resolvedPackage == null) { // TODO: need a check for empty package as well scope.problemReporter().invalidPackageReference(problemId, this, computeSeverity(problemId)); } else { if (!this.resolvedPackage.isDeclaredIn(src)) { this.resolvedPackage = null; // TODO(SHMOD): specific error? scope.problemReporter().invalidPackageReference(problemId, this, computeSeverity(problemId)); } } return this.resolvedPackage; }
protected PackageBinding resolvePackageReference(Scope scope) { if (this.resolvedPackage != null) return this.resolvedPackage; ModuleDeclaration exportingModule = scope.compilationUnitScope().referenceContext.moduleDeclaration; ModuleBinding src = exportingModule.binding; this.resolvedPackage = src != null ? src.getVisiblePackage(this.pkgRef.tokens) : null; int problemId = IProblem.PackageDoesNotExistOrIsEmpty; if (this.resolvedPackage == null) { // TODO: need a check for empty package as well scope.problemReporter().invalidPackageReference(problemId, this, computeSeverity(problemId)); } else { if (!this.resolvedPackage.isDeclaredIn(src)) { this.resolvedPackage = null; // TODO(SHMOD): specific error? scope.problemReporter().invalidPackageReference(problemId, this, computeSeverity(problemId)); } } return this.resolvedPackage; }