Skip to content

Commit

Permalink
Fix testTypeParameterConstructors03
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Nov 22, 2024
1 parent bbd1ea1 commit 3902f21
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public static IBinding getBinding(ASTNode astNode) {
if (astNode instanceof ClassInstanceCreation ref) {
return ref.resolveConstructorBinding();
}
if (astNode instanceof TypeParameter ref) {
return ref.resolveBinding();
}
// TODO more...
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ private SearchMatch toMatch(org.eclipse.jdt.core.dom.ASTNode node, int accuracy,
}
return new TypeReferenceMatch(element, accuracy, node.getStartPosition(), node.getLength(), DOMASTNodeUtils.insideDocComment(node), getParticipant(), resource);
}
if (node instanceof org.eclipse.jdt.core.dom.TypeParameter) {
IJavaElement element = DOMASTNodeUtils.getEnclosingJavaElement(node);
return new TypeParameterReferenceMatch(element, accuracy, node.getStartPosition(), node.getLength(), DOMASTNodeUtils.insideDocComment(node), getParticipant(), resource);
}
if (node instanceof Name name) {
IBinding b = name.resolveBinding();
IJavaElement enclosing = DOMASTNodeUtils.getEnclosingJavaElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ private <T extends ASTNode> boolean defaultVisitImplementationWithFunc(
public boolean visit(AnnotationTypeDeclaration node) {
return defaultVisitImplementation(node, x -> this.patternLocator.match(node, this.nodeSet, this.locator));
}

@Override
public boolean visit(TypeParameter node) {
return defaultVisitImplementation(node, x -> this.patternLocator.match(node, this.nodeSet, this.locator));
}
@Override
public boolean visit(MethodDeclaration node) {
return defaultVisitImplementation(node, x -> this.patternLocator.match(node, this.nodeSet, this.locator));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ public int match(Type node, MatchingNodeSet nodeSet, MatchLocator locator) {
return IMPOSSIBLE_MATCH;
}

@Override
public int match(org.eclipse.jdt.core.dom.TypeParameter node, MatchingNodeSet nodeSet, MatchLocator locator) {
if (this.pattern.findReferences) {
if (matchesName(this.pattern.name, node.getName().toString().toCharArray())) {
int level = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
return nodeSet.addMatch(node, level);
}
}
return IMPOSSIBLE_MATCH;
}


/*
* Verify whether a type parameter matches name pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,13 @@ public String toString() {
return "Locator for " + this.pattern.toString(); //$NON-NLS-1$
}

private boolean hasPackageDeclarationAncestor(org.eclipse.jdt.core.dom.ASTNode node) {
if( node instanceof PackageDeclaration) {
return true;
}
return node == null ? false : hasPackageDeclarationAncestor(node.getParent());
}

@Override
public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding, MatchLocator locator) {
if (binding == null) {
Expand All @@ -1023,13 +1030,16 @@ public int resolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding binding,
if (binding instanceof ITypeBinding typeBinding) {
return resolveLevelForTypeBinding(node, typeBinding, locator);
}
if( binding instanceof IPackageBinding packageBinding && node instanceof SimpleName sn) {
if( binding instanceof IPackageBinding && node instanceof SimpleName sn) {
// var x = (B36479.C)val;
// might interpret the B36479 to be a package and C a type,
// rather than B36479 to be a type and C to be an inner-type
if( this.isDeclarationOfReferencedTypesPattern) {
return IMPOSSIBLE_MATCH;
}
if( hasPackageDeclarationAncestor(node)) {
return IMPOSSIBLE_MATCH;
}
String identifier = sn.getIdentifier();
if( matchesName(this.pattern.simpleName, identifier.toCharArray())) {
return INACCURATE_MATCH;
Expand Down

0 comments on commit 3902f21

Please sign in to comment.