diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java index 0baeac0eb0d..fa9f6e4e5f1 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java @@ -513,7 +513,7 @@ public int resolveLevel(Binding binding) { return level; } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding instanceof IMethodBinding constructor) { int level= matchConstructor(constructor); if (level== IMPOSSIBLE_MATCH) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java index 3cfd80ad6c7..24f59e21d19 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java @@ -499,7 +499,7 @@ public int resolveLevel(Binding binding) { return matchField((FieldBinding) binding, true); } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding == null) return INACCURATE_MATCH; if(binding instanceof IVariableBinding variableBinding) { if (variableBinding.isRecordComponent()) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java index bea38c39987..a8d8cadff82 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java @@ -176,7 +176,7 @@ public int resolveLevel(Binding binding) { return matchLocalVariable((LocalVariableBinding) binding, true); } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (!(binding instanceof IVariableBinding)) { return IMPOSSIBLE_MATCH; } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java index 4451e17a8aa..4ea8b06fd1a 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java @@ -963,7 +963,7 @@ public int resolveLevel(Binding binding) { return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding instanceof IMethodBinding method) { boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric; int methodLevel = matchMethod(method, skipVerif); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java index 64441f24385..25be46a7d19 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java @@ -390,7 +390,7 @@ public int resolveLevel(Binding binding) { return IMPOSSIBLE_MATCH; } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if( binding instanceof IPackageBinding ipb) { String n = ipb.getName(); String patternName = new String(this.pattern.pkgName); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java index b59b89032a2..b3efbaa625f 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java @@ -871,7 +871,9 @@ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualification // return resolveLevelForType(qualifiedPattern(simpleNamePattern, qualificationPattern), type); char[] qualifiedPattern = getQualifiedPattern(simpleNamePattern, qualificationPattern); int level = resolveLevelForType(qualifiedPattern, binding); - if (level == ACCURATE_MATCH || binding == null) return level; + if (level == ACCURATE_MATCH || binding == null) + return level; + ITypeBinding type = binding.isArray() ? binding.getComponentType() : binding; char[] sourceName = null; if (type.isMember() || type.isLocal()) { @@ -883,7 +885,11 @@ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualification } else if (qualificationPattern == null) { sourceName = getQualifiedSourceName(binding).toCharArray(); } - if (sourceName == null) return IMPOSSIBLE_MATCH; + if (sourceName == null) + return IMPOSSIBLE_MATCH; + return resolveLevelForTypeSourceName(qualifiedPattern, sourceName, type); +} +protected int resolveLevelForTypeSourceName(char[] qualifiedPattern, char[] sourceName, ITypeBinding type) { switch (this.matchMode) { case SearchPattern.R_PREFIX_MATCH: if (CharOperation.prefixEquals(qualifiedPattern, sourceName, this.isCaseSensitive)) { @@ -1233,7 +1239,7 @@ public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, MatchLocator loca // each subtype should override if needed return IMPOSSIBLE_MATCH; } -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { // each subtype should override if needed return IMPOSSIBLE_MATCH; } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocatorVisitor.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocatorVisitor.java index d6a09739c02..bd1bc372875 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocatorVisitor.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocatorVisitor.java @@ -39,7 +39,7 @@ private boolean defaultVisitImplementationWithFunc( Function bindingFunc) { int level = levelFunc.apply(node); if ((level & PatternLocator.MATCH_LEVEL_MASK) == PatternLocator.POSSIBLE_MATCH && (this.nodeSet.mustResolve || this.patternLocator.mustResolve)) { - level = this.patternLocator.resolveLevel(bindingFunc.apply(node), this.locator); + level = this.patternLocator.resolveLevel(node, bindingFunc.apply(node), this.locator); } this.nodeSet.addMatch(node, level); return true; @@ -155,7 +155,7 @@ public boolean visit(SimpleName node) { int level = this.patternLocator.match(node, this.nodeSet, this.locator); if ((level & PatternLocator.MATCH_LEVEL_MASK) == PatternLocator.POSSIBLE_MATCH && (this.nodeSet.mustResolve || this.patternLocator.mustResolve)) { IBinding b = node.resolveBinding(); - level = this.patternLocator.resolveLevel(b, this.locator); + level = this.patternLocator.resolveLevel(node, b, this.locator); } this.nodeSet.addMatch(node, level); return level == 0; @@ -172,8 +172,8 @@ public boolean visit(SingleVariableDeclaration node) { public boolean visit(EnumConstantDeclaration node) { int level = this.patternLocator.match(node, this.nodeSet, this.locator); if ((level & PatternLocator.MATCH_LEVEL_MASK) == PatternLocator.POSSIBLE_MATCH && (this.nodeSet.mustResolve || this.patternLocator.mustResolve)) { - int l1 = this.patternLocator.resolveLevel(node.resolveVariable(), this.locator); - int l2 = this.patternLocator.resolveLevel(node.resolveConstructorBinding(), this.locator); + int l1 = this.patternLocator.resolveLevel(node, node.resolveVariable(), this.locator); + int l2 = this.patternLocator.resolveLevel(node, node.resolveConstructorBinding(), this.locator); level = Math.max(l1, l2); } this.nodeSet.addMatch(node, level); @@ -186,7 +186,7 @@ public boolean visit(QualifiedName node) { } int level = this.patternLocator.match(node, this.nodeSet, this.locator); if ((level & PatternLocator.MATCH_LEVEL_MASK) == PatternLocator.POSSIBLE_MATCH && (this.nodeSet.mustResolve || this.patternLocator.mustResolve)) { - level = this.patternLocator.resolveLevel(node.resolveBinding(), this.locator); + level = this.patternLocator.resolveLevel(node, node.resolveBinding(), this.locator); } this.nodeSet.addMatch(node, level); if( (level & PatternLocator.MATCH_LEVEL_MASK) == PatternLocator.IMPOSSIBLE_MATCH ) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java index be4cc115ec2..236a666456f 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java @@ -176,7 +176,7 @@ public int resolveLevel(Binding binding) { return level; } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof ITypeBinding)) return IMPOSSIBLE_MATCH; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationLocator.java index 20ce4c797b1..bb585c80342 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationLocator.java @@ -127,7 +127,7 @@ public int resolveLevel(Binding binding) { } } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof ITypeBinding)) return IMPOSSIBLE_MATCH; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeParameterLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeParameterLocator.java index 76d4fb65dba..e54ee72f13a 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeParameterLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeParameterLocator.java @@ -187,7 +187,7 @@ public int resolveLevel(Binding binding) { return matchTypeParameter((TypeVariableBinding) binding, true); } @Override - public int resolveLevel(IBinding binding, MatchLocator locator) { + public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof ITypeBinding)) return IMPOSSIBLE_MATCH; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java index f3ce13482ca..0fa58a57fd1 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java @@ -1002,13 +1002,47 @@ public String toString() { return "Locator for " + this.pattern.toString(); //$NON-NLS-1$ } @Override -public int resolveLevel(IBinding binding, MatchLocator locator) { +public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) { if (binding == null) { return INACCURATE_MATCH; } if (binding instanceof ITypeBinding typeBinding) { - return resolveLevelForType(this.pattern.simpleName, this.pattern.qualification, typeBinding); + int newLevel = resolveLevelForType(this.pattern.simpleName, this.pattern.qualification, typeBinding); + if( newLevel == IMPOSSIBLE_MATCH ) { + String qualNameFromBinding = typeBinding.getQualifiedName(); + if( !qualNameFromBinding.contains(".") && this.pattern.qualification != null && this.pattern.qualification.length > 0 ) { + // we need to find out if we import this thing at all + org.eclipse.jdt.core.dom.CompilationUnit cu = findCU(node); + List imports = cu.imports(); + for( Object id : imports) { + ImportDeclaration idd = (ImportDeclaration)id; + if( idd.getName() instanceof QualifiedName qn) { + if( qn.getName().toString().equals(qualNameFromBinding)) { + char[] qualifiedPattern = getQualifiedPattern(this.pattern.simpleName, this.pattern.qualification); + // we were imported as qualified name... + int level3 = resolveLevelForTypeSourceName(qualifiedPattern, qn.toString().toCharArray(), typeBinding); + if( level3 == ACCURATE_MATCH ) { + return INACCURATE_MATCH; + } + return level3; + } + } + + } + } + } + return newLevel; } return IMPOSSIBLE_MATCH; } + +private org.eclipse.jdt.core.dom.CompilationUnit findCU(org.eclipse.jdt.core.dom.ASTNode node) { + if( node == null ) + return null; + if( node instanceof org.eclipse.jdt.core.dom.CompilationUnit cu) { + return cu; + } + return findCU(node.getParent()); +} + }