List of usage examples for org.eclipse.jdt.internal.compiler.lookup ProblemReferenceBinding ProblemReferenceBinding
public ProblemReferenceBinding(char[][] compoundName, ReferenceBinding closestMatch, int problemReason)
From source file:lombok.eclipse.agent.PatchVisibleForTesting.java
License:Open Source License
private static ReferenceBinding handleVisibleForTestingOnType(final Scope scope, final ReferenceBinding typeBinding) { if (typeBinding == null) return typeBinding; for (AnnotationBinding annotation : Each.elementIn(typeBinding.getAnnotations())) { if (!As.string(annotation.getAnnotationType()).contains("VisibleForTesting")) continue; ClassScope classScope = scope.outerMostClassScope(); if (classScope == null) continue; TypeDeclaration decl = classScope.referenceContext; if (As.string(decl.name).contains("Test")) continue; return new ProblemReferenceBinding(typeBinding.compoundName, typeBinding, ProblemReasons.NotVisible); }//from ww w . j a v a 2 s . c o m return typeBinding; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public ReferenceBinding findDirectMemberType(char[] typeName, ReferenceBinding enclosingType) { if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0) return null; // know it has no member types (nor inherited member types) ReferenceBinding enclosingReceiverType = enclosingReceiverType(); CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordReference(enclosingType, typeName); ReferenceBinding memberType = enclosingType.getMemberType(typeName); if (memberType != null) { unitScope.recordTypeReference(memberType); if (enclosingReceiverType == null) { if (memberType.canBeSeenBy(getCurrentPackage())) { return memberType; }/*from w w w . j a v a 2 s. c o m*/ // maybe some type in the compilation unit is extending some class in some package // and the selection is for some protected inner class of that superclass // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235658 if (this instanceof CompilationUnitScope) { TypeDeclaration[] types = ((CompilationUnitScope) this).referenceContext.types; if (types != null) { for (int i = 0, max = types.length; i < max; i++) { if (memberType.canBeSeenBy(enclosingType, types[i].binding)) { return memberType; } } } } } else if (memberType.canBeSeenBy(enclosingType, enclosingReceiverType)) { return memberType; } return new ProblemReferenceBinding(new char[][] { typeName }, memberType, ProblemReasons.NotVisible); } return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) { if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0) return null; // know it has no member types (nor inherited member types) ReferenceBinding enclosingSourceType = enclosingSourceType(); PackageBinding currentPackage = getCurrentPackage(); CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordReference(enclosingType, typeName); ReferenceBinding memberType = enclosingType.getMemberType(typeName); if (memberType != null) { unitScope.recordTypeReference(memberType); if (enclosingSourceType == null || (this.parent == unitScope && (enclosingSourceType.tagBits & TagBits.TypeVariablesAreConnected) == 0) ? memberType.canBeSeenBy(currentPackage) : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) return memberType; return new ProblemReferenceBinding(new char[][] { typeName }, memberType, ProblemReasons.NotVisible); }/* w ww . ja va 2 s . c o m*/ // collect all superinterfaces of receiverType until the memberType is found in a supertype ReferenceBinding currentType = enclosingType; ReferenceBinding[] interfacesToVisit = null; int nextPosition = 0; ReferenceBinding visibleMemberType = null; boolean keepLooking = true; ReferenceBinding notVisible = null; // we could hold onto the not visible field for extra error reporting while (keepLooking) { ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces == null) { // needed for statically imported types which don't know their hierarchy yet ReferenceBinding sourceType = currentType.isParameterizedType() ? ((ParameterizedTypeBinding) currentType).genericType() : currentType; if (sourceType.isHierarchyBeingConnected()) return null; // looking for an undefined member type in its own superclass ref ((SourceTypeBinding) sourceType).scope.connectTypeHierarchy(); itsInterfaces = currentType.superInterfaces(); } if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; nextPosition = interfacesToVisit.length; } else { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } if ((currentType = currentType.superclass()) == null) break; unitScope.recordReference(currentType, typeName); if ((memberType = currentType.getMemberType(typeName)) != null) { unitScope.recordTypeReference(memberType); keepLooking = false; if (enclosingSourceType == null ? memberType.canBeSeenBy(currentPackage) : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) { if (visibleMemberType == null) visibleMemberType = memberType; else return new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType, ProblemReasons.Ambiguous); } else { notVisible = memberType; } } } // walk all visible interfaces to find ambiguous references if (interfacesToVisit != null) { ProblemReferenceBinding ambiguous = null; done: for (int i = 0; i < nextPosition; i++) { ReferenceBinding anInterface = interfacesToVisit[i]; unitScope.recordReference(anInterface, typeName); if ((memberType = anInterface.getMemberType(typeName)) != null) { unitScope.recordTypeReference(memberType); if (visibleMemberType == null) { visibleMemberType = memberType; } else { ambiguous = new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType, ProblemReasons.Ambiguous); break done; } } else { ReferenceBinding[] itsInterfaces = anInterface.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } if (ambiguous != null) return ambiguous; } if (visibleMemberType != null) return visibleMemberType; if (notVisible != null) return new ProblemReferenceBinding(new char[][] { typeName }, notVisible, ProblemReasons.NotVisible); return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public ReferenceBinding findType(char[] typeName, PackageBinding declarationPackage, PackageBinding invocationPackage) { compilationUnitScope().recordReference(declarationPackage.compoundName, typeName); ReferenceBinding typeBinding = declarationPackage.getType(typeName); if (typeBinding == null) return null; if (typeBinding.isValidBinding()) { if (declarationPackage != invocationPackage && !typeBinding.canBeSeenBy(invocationPackage)) return new ProblemReferenceBinding(new char[][] { typeName }, typeBinding, ProblemReasons.NotVisible); }//from w w w .jav a2 s . co m return typeBinding; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public final ReferenceBinding getMemberType(char[] typeName, ReferenceBinding enclosingType) { ReferenceBinding memberType = findMemberType(typeName, enclosingType); if (memberType != null) return memberType; char[][] compoundName = new char[][] { typeName }; return new ProblemReferenceBinding(compoundName, null, ProblemReasons.NotFound); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public final Binding getPackage(char[][] compoundName) { compilationUnitScope().recordQualifiedReference(compoundName); Binding binding = getTypeOrPackage(compoundName[0], Binding.TYPE | Binding.PACKAGE, true); if (binding == null) { char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, environment().createMissingType(null, compoundName), ProblemReasons.NotFound); }//from w w w. j a v a 2s . co m if (!binding.isValidBinding()) { if (binding instanceof PackageBinding) { /* missing package */ char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); } return binding; } 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.getTypeOrPackage(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()); if (!(binding instanceof PackageBinding)) return packageBinding; packageBinding = (PackageBinding) binding; } return new ProblemReferenceBinding(compoundName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public final TypeBinding getType(char[] name, PackageBinding packageBinding) { if (packageBinding == null) return getType(name); Binding binding = packageBinding.getTypeOrPackage(name); if (binding == null) { return new ProblemReferenceBinding(CharOperation.arrayConcat(packageBinding.compoundName, name), null, ProblemReasons.NotFound); }// www . ja va2 s . co m if (!binding.isValidBinding()) { return new ProblemReferenceBinding( binding instanceof ReferenceBinding ? ((ReferenceBinding) binding).compoundName : CharOperation.arrayConcat(packageBinding.compoundName, name), binding instanceof ReferenceBinding ? (ReferenceBinding) ((ReferenceBinding) binding).closestMatch() : null, binding.problemId()); } ReferenceBinding typeBinding = (ReferenceBinding) binding; if (!typeBinding.canBeSeenBy(this)) return new ProblemReferenceBinding(typeBinding.compoundName, typeBinding, ProblemReasons.NotVisible); return typeBinding; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public final TypeBinding getType(char[][] compoundName, int typeNameLength) { if (typeNameLength == 1) { // Would like to remove this test and require senders to specially handle base types TypeBinding binding = getBaseType(compoundName[0]); if (binding != null) return binding; }//ww w.j a va 2 s. c o m CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordQualifiedReference(compoundName); Binding binding = getTypeOrPackage(compoundName[0], typeNameLength == 1 ? Binding.TYPE : Binding.TYPE | Binding.PACKAGE, true); if (binding == null) { char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, environment().createMissingType(compilationUnitScope().getCurrentPackage(), qName), ProblemReasons.NotFound); } if (!binding.isValidBinding()) { if (binding instanceof PackageBinding) { char[][] qName = new char[][] { compoundName[0] }; return new ProblemReferenceBinding(qName, environment().createMissingType(null, qName), ProblemReasons.NotFound); } return (ReferenceBinding) binding; } int currentIndex = 1; boolean checkVisibility = false; if (binding instanceof PackageBinding) { PackageBinding packageBinding = (PackageBinding) binding; while (currentIndex < typeNameLength) { binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]); // does not check visibility if (binding == null) { char[][] qName = CharOperation.subarray(compoundName, 0, currentIndex); return new ProblemReferenceBinding(qName, environment().createMissingType(packageBinding, qName), ProblemReasons.NotFound); } if (!binding.isValidBinding()) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), binding instanceof ReferenceBinding ? (ReferenceBinding) ((ReferenceBinding) binding).closestMatch() : null, binding.problemId()); if (!(binding instanceof PackageBinding)) break; packageBinding = (PackageBinding) binding; } if (binding instanceof PackageBinding) { char[][] qName = CharOperation.subarray(compoundName, 0, currentIndex); return new ProblemReferenceBinding(qName, environment().createMissingType(null, qName), ProblemReasons.NotFound); } checkVisibility = true; } // binding is now a ReferenceBinding ReferenceBinding typeBinding = (ReferenceBinding) binding; unitScope.recordTypeReference(typeBinding); if (checkVisibility) // handles the fall through case if (!typeBinding.canBeSeenBy(this)) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), typeBinding, ProblemReasons.NotVisible); while (currentIndex < typeNameLength) { typeBinding = getMemberType(compoundName[currentIndex++], typeBinding); if (!typeBinding.isValidBinding()) { if (typeBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding problemBinding = (ProblemReferenceBinding) typeBinding; return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), problemBinding.closestReferenceMatch(), typeBinding.problemId()); } return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), (ReferenceBinding) ((ReferenceBinding) binding).closestMatch(), typeBinding.problemId()); } } return typeBinding; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
final Binding getTypeOrPackage(char[] name, int mask, boolean needResolve) { Scope scope = this; ReferenceBinding foundType = null;/*from www .j a va 2s. c o m*/ boolean insideStaticContext = false; boolean insideTypeAnnotation = false; if ((mask & Binding.TYPE) == 0) { Scope next = scope; while ((next = scope.parent) != null) scope = next; } else { boolean inheritedHasPrecedence = compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4; done: while (true) { // done when a COMPILATION_UNIT_SCOPE is found switch (scope.kind) { case METHOD_SCOPE: MethodScope methodScope = (MethodScope) scope; AbstractMethodDeclaration methodDecl = methodScope.referenceMethod(); if (methodDecl != null) { if (methodDecl.binding != null) { TypeVariableBinding typeVariable = methodDecl.binding.getTypeVariable(name); if (typeVariable != null) return typeVariable; } else { // use the methodDecl's typeParameters to handle problem cases when the method binding doesn't exist TypeParameter[] params = methodDecl.typeParameters(); for (int i = params == null ? 0 : params.length; --i >= 0;) if (CharOperation.equals(params[i].name, name)) if (params[i].binding != null && params[i].binding.isValidBinding()) return params[i].binding; } } insideStaticContext |= methodScope.isStatic; insideTypeAnnotation = methodScope.insideTypeAnnotation; //$FALL-THROUGH$ case BLOCK_SCOPE: ReferenceBinding localType = ((BlockScope) scope).findLocalType(name); // looks in this scope only if (localType != null) { if (foundType != null && foundType != localType) return new ProblemReferenceBinding(new char[][] { name }, foundType, ProblemReasons.InheritedNameHidesEnclosingName); return localType; } break; case CLASS_SCOPE: SourceTypeBinding sourceType = ((ClassScope) scope).referenceContext.binding; if (scope == this && (sourceType.tagBits & TagBits.TypeVariablesAreConnected) == 0) { // type variables take precedence over the source type, ex. class X <X> extends X == class X <Y> extends Y // but not when we step out to the enclosing type TypeVariableBinding typeVariable = sourceType.getTypeVariable(name); if (typeVariable != null) return typeVariable; if (CharOperation.equals(name, sourceType.sourceName)) return sourceType; insideStaticContext |= sourceType.isStatic(); break; } // member types take precedence over type variables if (!insideTypeAnnotation) { // 6.5.5.1 - member types have precedence over top-level type in same unit ReferenceBinding memberType = findMemberType(name, sourceType); if (memberType != null) { // skip it if we did not find anything if (memberType.problemId() == ProblemReasons.Ambiguous) { if (foundType == null || foundType.problemId() == ProblemReasons.NotVisible) // supercedes any potential InheritedNameHidesEnclosingName problem return memberType; // make the user qualify the type, likely wants the first inherited type return new ProblemReferenceBinding(new char[][] { name }, foundType, ProblemReasons.InheritedNameHidesEnclosingName); } if (memberType.isValidBinding()) { if (sourceType == memberType.enclosingType() || inheritedHasPrecedence) { if (insideStaticContext && !memberType.isStatic() && sourceType.isGenericType()) return new ProblemReferenceBinding(new char[][] { name }, memberType, ProblemReasons.NonStaticReferenceInStaticContext); // found a valid type in the 'immediate' scope (i.e. not inherited) // OR in 1.4 mode (inherited visible shadows enclosing) if (foundType == null || (inheritedHasPrecedence && foundType.problemId() == ProblemReasons.NotVisible)) return memberType; // if a valid type was found, complain when another is found in an 'immediate' enclosing type (i.e. not inherited) if (foundType.isValidBinding() && foundType != memberType) return new ProblemReferenceBinding(new char[][] { name }, foundType, ProblemReasons.InheritedNameHidesEnclosingName); } } if (foundType == null || (foundType.problemId() == ProblemReasons.NotVisible && memberType.problemId() != ProblemReasons.NotVisible)) // only remember the memberType if its the first one found or the previous one was not visible & memberType is... foundType = memberType; } } TypeVariableBinding typeVariable = sourceType.getTypeVariable(name); if (typeVariable != null) { if (insideStaticContext) // do not consider this type modifiers: access is legite within same type return new ProblemReferenceBinding(new char[][] { name }, typeVariable, ProblemReasons.NonStaticReferenceInStaticContext); return typeVariable; } insideStaticContext |= sourceType.isStatic(); insideTypeAnnotation = false; if (CharOperation.equals(sourceType.sourceName, name)) { if (foundType != null && foundType != sourceType && foundType.problemId() != ProblemReasons.NotVisible) return new ProblemReferenceBinding(new char[][] { name }, foundType, ProblemReasons.InheritedNameHidesEnclosingName); return sourceType; } break; case COMPILATION_UNIT_SCOPE: break done; } scope = scope.parent; } if (foundType != null && foundType.problemId() != ProblemReasons.NotVisible) return foundType; } // at this point the scope is a compilation unit scope CompilationUnitScope unitScope = (CompilationUnitScope) scope; HashtableOfObject typeOrPackageCache = unitScope.typeOrPackageCache; if (typeOrPackageCache != null) { Binding cachedBinding = (Binding) typeOrPackageCache.get(name); if (cachedBinding != null) { // can also include NotFound ProblemReferenceBindings if we already know this name is not found if (cachedBinding instanceof ImportBinding) { // single type import cached in faultInImports(), replace it in the cache with the type ImportReference importReference = ((ImportBinding) cachedBinding).reference; if (importReference != null) { importReference.bits |= ASTNode.Used; } if (cachedBinding instanceof ImportConflictBinding) typeOrPackageCache.put(name, cachedBinding = ((ImportConflictBinding) cachedBinding).conflictingTypeBinding); // already know its visible else typeOrPackageCache.put(name, cachedBinding = ((ImportBinding) cachedBinding).resolvedImport); // already know its visible } if ((mask & Binding.TYPE) != 0) { if (foundType != null && foundType.problemId() != ProblemReasons.NotVisible && cachedBinding.problemId() != ProblemReasons.Ambiguous) return foundType; // problem type from above supercedes NotFound type but not Ambiguous import case if (cachedBinding instanceof ReferenceBinding) return cachedBinding; // cached type found in previous walk below } if ((mask & Binding.PACKAGE) != 0 && cachedBinding instanceof PackageBinding) return cachedBinding; // cached package found in previous walk below } } // ask for the imports + name if ((mask & Binding.TYPE) != 0) { ImportBinding[] imports = unitScope.imports; if (imports != null && typeOrPackageCache == null) { // walk single type imports since faultInImports() has not run yet nextImport: for (int i = 0, length = imports.length; i < length; i++) { ImportBinding importBinding = imports[i]; if (!importBinding.onDemand) { // GROOVY start /* old { if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) { } new */ if (CharOperation.equals(getSimpleName(importBinding), name)) { // GROOVY end Binding resolvedImport = unitScope.resolveSingleImport(importBinding, Binding.TYPE); if (resolvedImport == null) continue nextImport; if (resolvedImport instanceof TypeBinding) { ImportReference importReference = importBinding.reference; if (importReference != null) importReference.bits |= ASTNode.Used; return resolvedImport; // already know its visible } } } } } // check if the name is in the current package, skip it if its a sub-package PackageBinding currentPackage = unitScope.fPackage; unitScope.recordReference(currentPackage.compoundName, name); Binding binding = currentPackage.getTypeOrPackage(name); if (binding instanceof ReferenceBinding) { ReferenceBinding referenceType = (ReferenceBinding) binding; if ((referenceType.tagBits & TagBits.HasMissingType) == 0) { if (typeOrPackageCache != null) typeOrPackageCache.put(name, referenceType); return referenceType; // type is always visible to its own package } } // check on demand imports if (imports != null) { boolean foundInImport = false; ReferenceBinding type = null; for (int i = 0, length = imports.length; i < length; i++) { ImportBinding someImport = imports[i]; if (someImport.onDemand) { Binding resolvedImport = someImport.resolvedImport; ReferenceBinding temp = null; if (resolvedImport instanceof PackageBinding) { temp = findType(name, (PackageBinding) resolvedImport, currentPackage); } else if (someImport.isStatic()) { temp = findMemberType(name, (ReferenceBinding) resolvedImport); // static imports are allowed to see inherited member types if (temp != null && !temp.isStatic()) temp = null; } else { temp = findDirectMemberType(name, (ReferenceBinding) resolvedImport); } if (temp != type && temp != null) { if (temp.isValidBinding()) { // GROOVY - start - allow for imports expressed in source to override 'default' imports - GRECLIPSE-945 boolean conflict = true; // do we need to continue checking if (this.parent != null && foundInImport) { CompilationUnitScope cuScope = compilationUnitScope(); if (cuScope != null) { ReferenceBinding chosenBinding = cuScope.selectBinding(temp, type, someImport.reference != null); if (chosenBinding != null) { // The new binding was selected as a valid answer conflict = false; foundInImport = true; type = chosenBinding; } } } if (conflict) { // GROOVY - end ImportReference importReference = someImport.reference; if (importReference != null) { importReference.bits |= ASTNode.Used; } if (foundInImport) { // Answer error binding -- import on demand conflict; name found in two import on demand packages. temp = new ProblemReferenceBinding(new char[][] { name }, type, ProblemReasons.Ambiguous); if (typeOrPackageCache != null) typeOrPackageCache.put(name, temp); return temp; } type = temp; foundInImport = true; // GROOVY - start } // GROOVY - end } else if (foundType == null) { foundType = temp; } } } } if (type != null) { if (typeOrPackageCache != null) typeOrPackageCache.put(name, type); return type; } } } unitScope.recordSimpleReference(name); if ((mask & Binding.PACKAGE) != 0) { PackageBinding packageBinding = unitScope.environment.getTopLevelPackage(name); if (packageBinding != null) { if (typeOrPackageCache != null) typeOrPackageCache.put(name, packageBinding); return packageBinding; } } // Answer error binding -- could not find name if (foundType == null) { char[][] qName = new char[][] { name }; ReferenceBinding closestMatch = null; if ((mask & Binding.PACKAGE) != 0) { if (needResolve) { closestMatch = environment().createMissingType(unitScope.fPackage, qName); } } else { PackageBinding packageBinding = unitScope.environment.getTopLevelPackage(name); if (packageBinding == null || !packageBinding.isValidBinding()) { if (needResolve) { closestMatch = environment().createMissingType(unitScope.fPackage, qName); } } } foundType = new ProblemReferenceBinding(qName, closestMatch, ProblemReasons.NotFound); if (typeOrPackageCache != null && (mask & Binding.PACKAGE) != 0) { // only put NotFound type in cache if you know its not a package typeOrPackageCache.put(name, foundType); } } else if ((foundType.tagBits & TagBits.HasMissingType) != 0) { char[][] qName = new char[][] { name }; foundType = new ProblemReferenceBinding(qName, foundType, ProblemReasons.NotFound); if (typeOrPackageCache != null && (mask & Binding.PACKAGE) != 0) // only put NotFound type in cache if you know its not a package typeOrPackageCache.put(name, foundType); } return foundType; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public final Binding getTypeOrPackage(char[][] compoundName) { int nameLength = compoundName.length; if (nameLength == 1) { TypeBinding binding = getBaseType(compoundName[0]); if (binding != null) return binding; }// www . ja v a 2 s . c om Binding binding = getTypeOrPackage(compoundName[0], Binding.TYPE | Binding.PACKAGE, true); if (!binding.isValidBinding()) return binding; int currentIndex = 1; boolean checkVisibility = false; if (binding instanceof PackageBinding) { PackageBinding packageBinding = (PackageBinding) binding; while (currentIndex < nameLength) { binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]); if (binding == null) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null, ProblemReasons.NotFound); if (!binding.isValidBinding()) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), binding instanceof ReferenceBinding ? (ReferenceBinding) ((ReferenceBinding) binding).closestMatch() : null, binding.problemId()); if (!(binding instanceof PackageBinding)) break; packageBinding = (PackageBinding) binding; } if (binding instanceof PackageBinding) return binding; checkVisibility = true; } // binding is now a ReferenceBinding ReferenceBinding typeBinding = (ReferenceBinding) binding; ReferenceBinding qualifiedType = (ReferenceBinding) environment().convertToRawType(typeBinding, false /*do not force conversion of enclosing types*/); if (checkVisibility) // handles the fall through case if (!typeBinding.canBeSeenBy(this)) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), typeBinding, ProblemReasons.NotVisible); while (currentIndex < nameLength) { typeBinding = getMemberType(compoundName[currentIndex++], typeBinding); // checks visibility if (!typeBinding.isValidBinding()) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), (ReferenceBinding) typeBinding.closestMatch(), typeBinding.problemId()); if (typeBinding.isGenericType()) { qualifiedType = environment().createRawType(typeBinding, qualifiedType); } else { qualifiedType = (qualifiedType != null && (qualifiedType.isRawType() || qualifiedType.isParameterizedType())) ? environment().createParameterizedType(typeBinding, null, qualifiedType) : typeBinding; } } return qualifiedType; }