List of usage examples for org.eclipse.jdt.internal.compiler.lookup ProblemReferenceBinding closestMatch
ReferenceBinding closestMatch
To view the source code for org.eclipse.jdt.internal.compiler.lookup ProblemReferenceBinding closestMatch.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException { if (this.isDeclarationOfReferencedTypesPattern) { if ((element = findElement(element, accuracy)) != null) { SimpleSet knownTypes = ((DeclarationOfReferencedTypesPattern) this.pattern).knownTypes; while (binding instanceof ReferenceBinding) { ReferenceBinding typeBinding = (ReferenceBinding) binding; reportDeclaration(typeBinding, 1, locator, knownTypes); binding = typeBinding.enclosingType(); }/*from w ww .j a v a 2s . c o m*/ } return; } // return if this is not necessary to report if (this.pattern.hasTypeArguments() && !this.isEquivalentMatch && !this.isErasureMatch) { return; } // Return if fine grain is on and does not concern import reference if ((this.pattern.fineGrain != 0 && (this.pattern.fineGrain & IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE) == 0)) { return; } // Create search match this.match = locator.newTypeReferenceMatch(element, binding, accuracy, importRef); // set match raw flag and rule this.match.setRaw(true); if (this.pattern.hasTypeArguments()) { // binding is raw => only compatible erasure if pattern has type arguments this.match.setRule(this.match.getRule() & (~SearchPattern.R_FULL_MATCH)); } // Try to find best selection for match TypeBinding typeBinding = null; boolean lastButOne = false; if (binding instanceof ReferenceBinding) { typeBinding = (ReferenceBinding) binding; } else if (binding instanceof FieldBinding) { // may happen for static import typeBinding = ((FieldBinding) binding).declaringClass; lastButOne = importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0); } else if (binding instanceof MethodBinding) { // may happen for static import typeBinding = ((MethodBinding) binding).declaringClass; lastButOne = importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0); } if (typeBinding != null) { int lastIndex = importRef.tokens.length - 1; if (lastButOne) { // for field or method static import, use last but one token lastIndex--; } if (typeBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding pbBinding = (ProblemReferenceBinding) typeBinding; typeBinding = pbBinding.closestMatch(); lastIndex = pbBinding.compoundName.length - 1; } // try to match all enclosing types for which the token matches as well. while (typeBinding != null && lastIndex >= 0) { if (resolveLevelForType(typeBinding) != IMPOSSIBLE_MATCH) { if (locator.encloses(element)) { long[] positions = importRef.sourcePositions; // index now depends on pattern type signature int index = lastIndex; if (this.pattern.qualification != null) { index = lastIndex - this.pattern.segmentsSize; } if (index < 0) index = 0; int start = (int) ((positions[index]) >>> 32); int end = (int) positions[lastIndex]; // report match this.match.setOffset(start); this.match.setLength(end - start + 1); locator.report(this.match); } return; } lastIndex--; typeBinding = typeBinding.enclosingType(); } } locator.reportAccurateTypeReference(this.match, importRef, this.pattern.simpleName); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void matchReportReference(QualifiedNameReference qNameRef, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { Binding binding = qNameRef.binding; TypeBinding typeBinding = null;/*from w w w.ja v a2s . c o m*/ int lastIndex = qNameRef.tokens.length - 1; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field typeBinding = qNameRef.actualReceiverType; lastIndex -= 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 ProblemReferenceBinding) { typeBinding = (TypeBinding) binding; } else if (binding instanceof ProblemFieldBinding) { typeBinding = qNameRef.actualReceiverType; lastIndex -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; } else if (binding instanceof ProblemBinding) { typeBinding = ((ProblemBinding) binding).searchType; } break; } if (typeBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding pbBinding = (ProblemReferenceBinding) typeBinding; typeBinding = pbBinding.closestMatch(); lastIndex = pbBinding.compoundName.length - 1; } // Create search match to report if (this.match == null) { this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, qNameRef); } // try to match all enclosing types for which the token matches as well. if (typeBinding instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) typeBinding; while (refBinding != null && lastIndex >= 0) { if (resolveLevelForType(refBinding) == ACCURATE_MATCH) { if (locator.encloses(element)) { long[] positions = qNameRef.sourcePositions; // index now depends on pattern type signature int index = lastIndex; if (this.pattern.qualification != null) { index = lastIndex - this.pattern.segmentsSize; } if (index < 0) index = 0; int start = (int) ((positions[index]) >>> 32); int end = (int) positions[lastIndex]; this.match.setOffset(start); this.match.setLength(end - start + 1); // Look if there's a need to special report for parameterized type matchReportReference(qNameRef, lastIndex, refBinding, locator); } return; } lastIndex--; refBinding = refBinding.enclosingType(); } } locator.reportAccurateTypeReference(this.match, qNameRef, this.pattern.simpleName); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void matchReportReference(QualifiedTypeReference qTypeRef, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { TypeBinding typeBinding = qTypeRef.resolvedType; int lastIndex = qTypeRef.tokens.length - 1; if (typeBinding instanceof ArrayBinding) typeBinding = ((ArrayBinding) typeBinding).leafComponentType; if (typeBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding pbBinding = (ProblemReferenceBinding) typeBinding; typeBinding = pbBinding.closestMatch(); lastIndex = pbBinding.compoundName.length - 1; }/*from www. j av a2s. co m*/ // Create search match to report if (this.match == null) { this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, qTypeRef); } // try to match all enclosing types for which the token matches as well if (typeBinding instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) typeBinding; while (refBinding != null && lastIndex >= 0) { if (resolveLevelForType(refBinding) != IMPOSSIBLE_MATCH) { if (locator.encloses(element)) { long[] positions = qTypeRef.sourcePositions; // index now depends on pattern type signature int index = lastIndex; if (this.pattern.qualification != null) { index = lastIndex - this.pattern.segmentsSize; } if (index < 0) index = 0; int start = (int) ((positions[index]) >>> 32); int end = (int) positions[lastIndex]; this.match.setOffset(start); this.match.setLength(end - start + 1); // Look if there's a need to special report for parameterized type matchReportReference(qTypeRef, lastIndex, refBinding, locator); } return; } lastIndex--; refBinding = refBinding.enclosingType(); } } locator.reportAccurateTypeReference(this.match, qTypeRef, this.pattern.simpleName); }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java
License:Open Source License
/** * Look in the local cache, if we don't find it then ask JDT. If JDT responds with a SourceTypeBinding then it has been found. * If JDT responds with some other kind of binding, we consider that 'not found as source' and return null. * /*from w w w. j a va 2 s . c o m*/ * Not quite the right name for this method, because on an incremental build it will find BinaryTypeBindings for types that were * SourceTypeBindings during the full build * */ // FIXASC (optimization) cache any non SourceTypeBinding found and use that information in the lookupClassNodeForBinary public ClassNode lookupClassNodeForSource(String typename, JDTResolver jdtResolver) { ClassNode node = typenameToClassNodeCache.get(typename); if (node != null) { return node; } char[][] compoundName = CharOperation.splitOn('.', typename.toCharArray()); TypeBinding jdtBinding = null; try { jdtBinding = getType(compoundName, compoundName.length); } catch (AbortCompilation t) { if (t.silentException instanceof AbortIncrementalBuildException) { jdtBinding = null; } else { throw t; } } if (jdtBinding != null) { if (jdtBinding instanceof SourceTypeBinding) { ClassNode classNode = jdtResolver.convertToClassNode(jdtBinding); if (classNode != null) { typenameToClassNodeCache.put(typename, classNode); } return classNode; } else if (jdtBinding instanceof BinaryTypeBinding) { ClassNode newNode = jdtResolver.convertToClassNode(jdtBinding); if (newNode != null) { typenameToClassNodeCache.put(typename, newNode); } return newNode; } } // FIXASC better to look it up properly as a member type rather than catch the problem and unwrap! if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) { ProblemReferenceBinding prBinding = (ProblemReferenceBinding) jdtBinding; if (prBinding.problemId() == ProblemReasons.InternalNameProvided) { jdtBinding = prBinding.closestMatch(); // FIXASC caching for this too? if (jdtBinding != null && (jdtBinding instanceof SourceTypeBinding)) { return jdtResolver.convertToClassNode(jdtBinding); } if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) { return jdtResolver.convertToClassNode(jdtBinding); } } } return null; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java
License:Open Source License
public ClassNode lookupClassNodeForBinary(String typename, JDTResolver jdtResolver) { char[][] compoundName = CharOperation.splitOn('.', typename.toCharArray()); TypeBinding jdtBinding = getType(compoundName, compoundName.length); if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) { // log("GCUScope.lookupClassNodeForBinary(): JDTBinding for '" + typename + "' found to be " // + jdtBinding.getClass().getSimpleName()); ClassNode classNode = jdtResolver.convertToClassNode(jdtBinding); return classNode; }//w ww .java 2s.c om if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) { ProblemReferenceBinding prBinding = (ProblemReferenceBinding) jdtBinding; if (prBinding.problemId() == ProblemReasons.InternalNameProvided) { jdtBinding = prBinding.closestMatch(); if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) { return jdtResolver.convertToClassNode(jdtBinding); } } } return null; }