Skip to content

Commit 4982782

Browse files
mickaelistriadatho7561
authored andcommitted
[Search] Improve filters when matching super-type
1 parent 47d5840 commit 4982782

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/core/search/matching/DOMSuperTypeReferenceLocator.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.Set;
1414

15+
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
1516
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
1617
import org.eclipse.jdt.core.dom.IBinding;
1718
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -43,12 +44,15 @@ public LocatorResponse match(org.eclipse.jdt.core.dom.LambdaExpression node, Nod
4344

4445
@Override
4546
public LocatorResponse match(Type node, NodeSetWrapper nodeSet, MatchLocator locator) {
46-
if (Set.of(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY, ClassInstanceCreation.TYPE_PROPERTY).contains(node)) {
47+
if (!Set.of(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY, ClassInstanceCreation.TYPE_PROPERTY).contains(node.getLocationInParent())) {
4748
return toResponse(IMPOSSIBLE_MATCH);
4849
}
4950
if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY && node.getParent() instanceof ClassInstanceCreation newInst && newInst.getAnonymousClassDeclaration() == null) {
5051
return toResponse(IMPOSSIBLE_MATCH);
5152
}
53+
if (node.getParent() instanceof AbstractTypeDeclaration decl && !DOMTypeDeclarationLocator.matchSearchForTypeSuffix(decl, this.locator.pattern.typeSuffix)) {
54+
return toResponse(IMPOSSIBLE_MATCH);
55+
}
5256
if (this.locator.pattern.superSimpleName == null) {
5357
int level = nodeSet.addMatch(node, this.locator.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
5458
return toResponse(level, true);
@@ -82,23 +86,18 @@ public LocatorResponse resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBind
8286

8387
var type = (ITypeBinding) binding;
8488
int level = IMPOSSIBLE_MATCH;
85-
if (this.locator.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES) {
89+
if (this.locator.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES || node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) {
8690
level = this.resolveLevelForType(this.locator.pattern.superSimpleName, this.locator.pattern.superQualification,
87-
type.getSuperclass());
91+
type);
8892
if (level == ACCURATE_MATCH)
8993
return toResponse(ACCURATE_MATCH);
9094
}
9195

92-
if (this.locator.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_CLASSES) {
93-
for (ITypeBinding superInterface : type.getInterfaces()) {
94-
int newLevel = this.resolveLevelForType(this.locator.pattern.superSimpleName, this.locator.pattern.superQualification,
95-
superInterface);
96-
if (newLevel > level) {
97-
if (newLevel == ACCURATE_MATCH)
98-
return toResponse(ACCURATE_MATCH);
99-
level = newLevel;
100-
}
101-
}
96+
if (this.locator.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_CLASSES || node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
97+
level = this.resolveLevelForType(this.locator.pattern.superSimpleName, this.locator.pattern.superQualification,
98+
type);
99+
if (level == ACCURATE_MATCH)
100+
return toResponse(ACCURATE_MATCH);
102101
}
103102
return toResponse(level);
104103
}

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/core/search/matching/DOMTypeDeclarationLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public LocatorResponse match(AbstractTypeDeclaration node, NodeSetWrapper nodeSe
4545
return toResponse(IMPOSSIBLE_MATCH);
4646
}
4747

48-
private boolean matchSearchForTypeSuffix(AbstractTypeDeclaration type, char typeSuffix) {
48+
static boolean matchSearchForTypeSuffix(AbstractTypeDeclaration type, char typeSuffix) {
4949
return switch (typeSuffix) {
5050
case IIndexConstants.CLASS_SUFFIX -> type instanceof TypeDeclaration decl && !decl.isInterface();
5151
case IIndexConstants.CLASS_AND_INTERFACE_SUFFIX -> type instanceof TypeDeclaration;

0 commit comments

Comments
 (0)