List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding closestMatch
public TypeBinding closestMatch()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void reportDeclaration(ASTNode reference, IJavaElement element, MatchLocator locator, SimpleSet knownTypes) throws CoreException { int maxType = -1; TypeBinding typeBinding = null; if (reference instanceof TypeReference) { typeBinding = ((TypeReference) reference).resolvedType; maxType = Integer.MAX_VALUE; } else if (reference instanceof QualifiedNameReference) { QualifiedNameReference qNameRef = (QualifiedNameReference) reference; Binding binding = qNameRef.binding; maxType = qNameRef.tokens.length - 1; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field typeBinding = qNameRef.actualReceiverType; maxType -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; break; case Binding.TYPE: //=============only type ============== if (binding instanceof TypeBinding) typeBinding = (TypeBinding) binding; break; case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: if (binding instanceof ProblemFieldBinding) { typeBinding = qNameRef.actualReceiverType; maxType -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; } else if (binding instanceof ProblemBinding) { ProblemBinding pbBinding = (ProblemBinding) binding; typeBinding = pbBinding.searchType; // second chance with recorded type so far char[] partialQualifiedName = pbBinding.name; maxType = CharOperation.occurencesOf('.', partialQualifiedName) - 1; // index of last bound token is one before the pb token if (typeBinding == null || maxType < 0) return; }/*from www .ja v a 2 s . c om*/ break; } } else if (reference instanceof SingleNameReference) { typeBinding = (TypeBinding) ((SingleNameReference) reference).binding; maxType = 1; } if (typeBinding instanceof ArrayBinding) typeBinding = ((ArrayBinding) typeBinding).leafComponentType; if (typeBinding == null || typeBinding instanceof BaseTypeBinding) return; if (typeBinding instanceof ProblemReferenceBinding) { TypeBinding original = typeBinding.closestMatch(); if (original == null) return; // original may not be set (bug 71279) typeBinding = original; } typeBinding = typeBinding.erasure(); reportDeclaration((ReferenceBinding) typeBinding, maxType, locator, knownTypes); }
From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.java
License:Open Source License
private void fixSupertypeBindings() { for (int current = this.typeIndex; current >= 0; current--) { ReferenceBinding typeBinding = this.typeBindings[current]; if ((typeBinding.tagBits & TagBits.HierarchyHasProblems) == 0) continue; if (typeBinding instanceof SourceTypeBinding) { if (typeBinding instanceof LocalTypeBinding) { LocalTypeBinding localTypeBinding = (LocalTypeBinding) typeBinding; QualifiedAllocationExpression allocationExpression = localTypeBinding.scope.referenceContext.allocation; TypeReference type;//from w w w . j av a2s . c o m if (allocationExpression != null && (type = allocationExpression.type) != null && type.resolvedType != null) { localTypeBinding.superclass = (ReferenceBinding) type.resolvedType; continue; } } ClassScope scope = ((SourceTypeBinding) typeBinding).scope; if (scope != null) { TypeDeclaration typeDeclaration = scope.referenceContext; TypeReference superclassRef = typeDeclaration == null ? null : typeDeclaration.superclass; TypeBinding superclass = superclassRef == null ? null : superclassRef.resolvedType; if (superclass != null) { superclass = superclass.closestMatch(); } if (superclass instanceof ReferenceBinding) { // ensure we are not creating a cycle (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 ) if (!(subTypeOfType((ReferenceBinding) superclass, typeBinding))) { ((SourceTypeBinding) typeBinding).superclass = (ReferenceBinding) superclass; } } TypeReference[] superInterfaces = typeDeclaration == null ? null : typeDeclaration.superInterfaces; int length; ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces(); if (superInterfaces != null && (length = superInterfaces.length) > (interfaceBindings == null ? 0 : interfaceBindings.length)) { // check for interfaceBindings being null (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=139689) interfaceBindings = new ReferenceBinding[length]; int index = 0; for (int i = 0; i < length; i++) { TypeBinding superInterface = superInterfaces[i].resolvedType; if (superInterface != null) { superInterface = superInterface.closestMatch(); } if (superInterface instanceof ReferenceBinding) { // ensure we are not creating a cycle (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 ) if (!(subTypeOfType((ReferenceBinding) superInterface, typeBinding))) { interfaceBindings[index++] = (ReferenceBinding) superInterface; } } } if (index < length) System.arraycopy(interfaceBindings, 0, interfaceBindings = new ReferenceBinding[index], 0, index); ((SourceTypeBinding) typeBinding).superInterfaces = interfaceBindings; } } } else if (typeBinding instanceof BinaryTypeBinding) { try { typeBinding.superclass(); } catch (AbortCompilation e) { // allow subsequent call to superclass() to succeed so that we don't have to catch AbortCompilation everywhere ((BinaryTypeBinding) typeBinding).tagBits &= ~TagBits.HasUnresolvedSuperclass; this.builder.hierarchy.missingTypes.add(new String(typeBinding.superclass().sourceName())); this.hasMissingSuperClass = true; } try { typeBinding.superInterfaces(); } catch (AbortCompilation e) { // allow subsequent call to superInterfaces() to succeed so that we don't have to catch AbortCompilation everywhere ((BinaryTypeBinding) typeBinding).tagBits &= ~TagBits.HasUnresolvedSuperinterfaces; } } } }