/** * Answer the qualified name of the receiver's package separated by periods * or an empty string if its the default package. * * For example, {java.util}. */ public char[] qualifiedPackageName() { PackageBinding packageBinding = getPackage(); return packageBinding == null || packageBinding.compoundName == CharOperation.NO_CHAR_CHAR ? CharOperation.NO_CHAR : packageBinding.readableName(); }
private PackageBinding findPackage(char[] name) { if (!this.environment.isPackage(this.compoundName, name)) return null; char[][] subPkgCompoundName = CharOperation.arrayConcat(this.compoundName, name); PackageBinding subPackageBinding = new PackageBinding(subPkgCompoundName, this, this.environment); addPackage(subPackageBinding); return subPackageBinding; } /* Answer the subpackage named name; ask the oracle for the package if its not in the cache.
PackageBinding getPackage(char[] name, ModuleBinding mod) { PackageBinding binding = getPackage0(name); if (binding != null) { if (binding == LookupEnvironment.TheNotFoundPackage) return null; else return binding; } if ((binding = findPackage(name, mod)) != null) return binding; // not found so remember a problem package binding in the cache for future lookups addNotFoundPackage(name); return null; } /** Answer the subpackage named name if it exists in the cache.
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { if ("package-info".equals(new String(typeDeclaration.name))) { context.enter(factory.Package().getOrCreate(new String(typeDeclaration.binding.fPackage.readableName())), typeDeclaration); return true; } else { CtModule module; // skip the type declaration that are already declared if (typeDeclaration.binding == null && getFactory().getEnvironment().isIgnoreDuplicateDeclarations()) { return false; } if (typeDeclaration.binding.module != null && !typeDeclaration.binding.module.isUnnamed() && typeDeclaration.binding.module.shortReadableName() != null && typeDeclaration.binding.module.shortReadableName().length > 0) { module = factory.Module().getOrCreate(String.valueOf(typeDeclaration.binding.module.shortReadableName())); } else { module = factory.Module().getUnnamedModule(); } CtPackage pack; if (typeDeclaration.binding.fPackage.shortReadableName() != null && typeDeclaration.binding.fPackage.shortReadableName().length > 0) { pack = factory.Package().getOrCreate(new String(typeDeclaration.binding.fPackage.shortReadableName()), module); } else { pack = module.getRootPackage(); } context.enter(pack, typeDeclaration); pack.addType(helper.createType(typeDeclaration)); return true; } }
ReferenceBinding getType(char[] name) { ReferenceBinding referenceBinding = getType0(name); if (referenceBinding == null) { if ((referenceBinding = this.environment.askForType(this, name)) == null) { // not found so remember a problem type binding in the cache for future lookups addNotFoundType(name); return null; } } if (referenceBinding == LookupEnvironment.TheNotFoundType) return null; referenceBinding = (ReferenceBinding) BinaryTypeBinding.resolveType(referenceBinding, this.environment, false /* no raw conversion for now */); if (referenceBinding.isNestedType()) return new ProblemReferenceBinding(new char[][]{ name }, referenceBinding, ProblemReasons.InternalNameProvided); return referenceBinding; } /* Answer the type named name if it exists in the cache.
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, boolean needFieldsAndMethods, AccessRestriction accessRestriction) { BinaryTypeBinding binaryBinding = new BinaryTypeBinding(packageBinding, binaryType, this); // resolve any array bindings which reference the unresolvedType ReferenceBinding cachedType = packageBinding.getType0(binaryBinding.compoundName[binaryBinding.compoundName.length - 1]); if (cachedType != null && !cachedType.isUnresolvedType()) { if (cachedType.isBinaryBinding()) // sanity check... at this point the cache should ONLY contain unresolved types return (BinaryTypeBinding) cachedType; // it is possible with a large number of source files (exceeding AbstractImageBuilder.MAX_AT_ONCE) that a member type can be in the cache as an UnresolvedType, // but because its enclosingType is resolved while its created (call to BinaryTypeBinding constructor), its replaced with a source type return null; } packageBinding.addType(binaryBinding); setAccessRestriction(binaryBinding, accessRestriction); binaryBinding.cachePartsFrom(binaryType, needFieldsAndMethods); return binaryBinding; }
public Binding getTypeOrPackage(char[] name) { ReferenceBinding referenceBinding = getType0(name); if (referenceBinding != null && referenceBinding != LookupEnvironment.TheNotFoundType) { referenceBinding = (ReferenceBinding) BinaryTypeBinding.resolveType(referenceBinding, this.environment, false /* no raw conversion for now */); PackageBinding packageBinding = getPackage0(name); if (packageBinding != null && packageBinding != LookupEnvironment.TheNotFoundPackage) { return packageBinding; addNotFoundType(name); if ((packageBinding = findPackage(name)) != null) { return packageBinding; return referenceBinding; // found cached missing type - check if package conflict addNotFoundPackage(name);
public EcjPsiPackage(@NonNull EcjPsiManager manager, @NonNull PackageBinding binding) { super(manager, binding); mPackageBinding = binding; PsiModifierList modifierList = this; Binding pkgInfoBinding = binding.getTypeOrPackage(PACKAGE_INFO); if (pkgInfoBinding instanceof ReferenceBinding) { PsiClass pkgInfoClass = manager.findClass(pkgInfoBinding); if (pkgInfoClass != null) { modifierList = pkgInfoClass.getModifierList(); } } mModifierList = modifierList; }
public final Binding getOnlyPackage(char[][] compoundName) { compilationUnitScope().recordQualifiedReference(compoundName); Binding binding = getTypeOrPackage(compoundName[0], Binding.PACKAGE, true); if (binding == null || !binding.isValidBinding()) { char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); } if (!(binding instanceof PackageBinding)) { return null; // compoundName does not start with a package } int currentIndex = 1, length = compoundName.length; PackageBinding packageBinding = (PackageBinding) binding; while (currentIndex < length) { binding = packageBinding.getPackage(compoundName[currentIndex++]); if (binding == null) { return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null /* no closest match since search for pkg*/, ProblemReasons.NotFound); } if (!binding.isValidBinding()) { return new ProblemReferenceBinding( CharOperation.subarray(compoundName, 0, currentIndex), binding instanceof ReferenceBinding ? (ReferenceBinding)((ReferenceBinding)binding).closestMatch() : null, binding.problemId()); } packageBinding = (PackageBinding) binding; } return packageBinding; }
void addPackage(PackageBinding element) { if ((element.tagBits & TagBits.HasMissingType) == 0) clearMissingTagBit(); this.knownPackages.put(element.compoundName[element.compoundName.length - 1], element); } void addType(ReferenceBinding element) {
void addType(ReferenceBinding element) { if ((element.tagBits & TagBits.HasMissingType) == 0) clearMissingTagBit(); if (this.knownTypes == null) this.knownTypes = new HashtableOfType(25); this.knownTypes.put(element.compoundName[element.compoundName.length - 1], element); if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) if (element.isAnnotationType() || element instanceof UnresolvedReferenceBinding) // unresolved types don't yet have the modifiers set checkIfNullAnnotationType(element); }
if (this.environment.isProcessingAnnotations && this.environment.isMissingType(typeDecl.name)) throw new SourceTypeCollisionException(); // resolved a type ref before APT generated the type ReferenceBinding typeBinding = this.fPackage.getType0(typeDecl.name); continue nextType; if (this.fPackage != this.environment.defaultPackage && this.fPackage.getPackage(typeDecl.name) != null) {
@Override public void consumePackage(char[] pkgName) { this.compoundName = CharOperation.splitOn('/', pkgName); this.compilerBinding = new PackageBinding(this.compoundName, null, this.environment, this.environment.module); //TODO(SHMOD) enclosingModule }
public MissingTypeBinding createMissingType(PackageBinding packageBinding, char[][] compoundName) { // create a proxy for the missing BinaryType if (packageBinding == null) { packageBinding = computePackageFrom(compoundName, true /* missing */); if (packageBinding == TheNotFoundPackage) packageBinding = this.defaultPackage; } MissingTypeBinding missingType = new MissingTypeBinding(packageBinding, compoundName, this); if (missingType.id != TypeIds.T_JavaLangObject) { // make Object be its superclass - it could in turn be missing as well ReferenceBinding objectType = getType(TypeConstants.JAVA_LANG_OBJECT); if (objectType == null) { objectType = createMissingType(null, TypeConstants.JAVA_LANG_OBJECT); // create a proxy for the missing Object type } missingType.setMissingSuperclass(objectType); } packageBinding.addType(missingType); if (this.missingTypes == null) this.missingTypes = new ArrayList(3); this.missingTypes.add(missingType); return missingType; }
@Override PackageBinding addPackage(PackageBinding element, ModuleBinding module, boolean enrichWithSplitSiblings) { char[] simpleName = element.compoundName[element.compoundName.length-1]; // enrich if (enrichWithSplitSiblings) element = combineWithSiblings(element, simpleName, module); PackageBinding visible = this.knownPackages.get(simpleName); visible = SplitPackageBinding.combine(element, visible, this.enclosingModule); this.knownPackages.put(simpleName, visible); PackageBinding incarnation = getIncarnation(element.enclosingModule); if (incarnation != null) incarnation.addPackage(element, module, enrichWithSplitSiblings); return element; }
@Override protected PackageBinding findPackage(char[] name, ModuleBinding module) { Set<PackageBinding> candidates = new HashSet<>(); for (ModuleBinding candidateModule : this.declaringModules) { PackageBinding candidate = super.findPackage(name, candidateModule); if (candidate != null && candidate != LookupEnvironment.TheNotFoundPackage && ((candidate.tagBits & TagBits.HasMissingType) == 0)) { candidates.add(candidate); } } int count = candidates.size(); PackageBinding result = null; if (count == 1) { result = candidates.iterator().next(); } else if (count > 1) { Iterator<PackageBinding> iterator = candidates.iterator(); SplitPackageBinding split = new SplitPackageBinding(iterator.next(), this.enclosingModule); while (iterator.hasNext()) split.add(iterator.next()); result = split; } if (result == null) addNotFoundPackage(name); else addPackage(result, module); return result; }
ReferenceBinding getType(char[] name) { ReferenceBinding referenceBinding = getType0(name); if (referenceBinding == null) { if ((referenceBinding = this.environment.askForType(this, name)) == null) { // not found so remember a problem type binding in the cache for future lookups addNotFoundType(name); return null; } } if (referenceBinding == LookupEnvironment.TheNotFoundType) return null; referenceBinding = (ReferenceBinding) BinaryTypeBinding.resolveType(referenceBinding, this.environment, false /* no raw conversion for now */); if (referenceBinding.isNestedType()) return new ProblemReferenceBinding(new char[][]{ name }, referenceBinding, ProblemReasons.InternalNameProvided); return referenceBinding; } /* Answer the type named name if it exists in the cache.
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, boolean needFieldsAndMethods, AccessRestriction accessRestriction) { BinaryTypeBinding binaryBinding = new BinaryTypeBinding(packageBinding, binaryType, this); // resolve any array bindings which reference the unresolvedType ReferenceBinding cachedType = packageBinding.getType0(binaryBinding.compoundName[binaryBinding.compoundName.length - 1]); if (cachedType != null && !cachedType.isUnresolvedType()) { if (cachedType.isBinaryBinding()) // sanity check... at this point the cache should ONLY contain unresolved types return (BinaryTypeBinding) cachedType; // it is possible with a large number of source files (exceeding AbstractImageBuilder.MAX_AT_ONCE) that a member type can be in the cache as an UnresolvedType, // but because its enclosingType is resolved while its created (call to BinaryTypeBinding constructor), its replaced with a source type return null; } packageBinding.addType(binaryBinding); setAccessRestriction(binaryBinding, accessRestriction); binaryBinding.cachePartsFrom(binaryType, needFieldsAndMethods); return binaryBinding; }
ImportBinding[] getDefaultImports() { // initialize the default imports if necessary... share the default java.lang.* import if (this.environment.defaultImports != null) return this.environment.defaultImports; Binding importBinding = this.environment.getTopLevelPackage(TypeConstants.JAVA); if (importBinding != null) importBinding = ((PackageBinding) importBinding).getTypeOrPackage(TypeConstants.JAVA_LANG[1]); if (importBinding == null || !importBinding.isValidBinding()) { // create a proxy for the missing BinaryType problemReporter().isClassPathCorrect( TypeConstants.JAVA_LANG_OBJECT, this.referenceContext, this.environment.missingClassFileLocation); BinaryTypeBinding missingObject = this.environment.createMissingType(null, TypeConstants.JAVA_LANG_OBJECT); importBinding = missingObject.fPackage; } return this.environment.defaultImports = new ImportBinding[] {new ImportBinding(TypeConstants.JAVA_LANG, true, importBinding, null)}; } // NOT Public API
public final Binding getOnlyPackage(char[][] compoundName) { compilationUnitScope().recordQualifiedReference(compoundName); Binding binding = getTypeOrPackage(compoundName[0], Binding.PACKAGE, true); if (binding == null || !binding.isValidBinding()) { char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); } if (!(binding instanceof PackageBinding)) { return null; // compoundName does not start with a package } int currentIndex = 1, length = compoundName.length; PackageBinding packageBinding = (PackageBinding) binding; while (currentIndex < length) { binding = packageBinding.getPackage(compoundName[currentIndex++]); if (binding == null) { return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null /* no closest match since search for pkg*/, ProblemReasons.NotFound); } if (!binding.isValidBinding()) { return new ProblemReferenceBinding( CharOperation.subarray(compoundName, 0, currentIndex), binding instanceof ReferenceBinding ? (ReferenceBinding)((ReferenceBinding)binding).closestMatch() : null, binding.problemId()); } packageBinding = (PackageBinding) binding; } return packageBinding; }