Skip to content

Commit

Permalink
fixing missing erasure matches
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-hurley committed Jul 11, 2024
1 parent 7902cac commit dabd3e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.konveyor.tackle.core.internal.symbol;

import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.ConstructorInvocation;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.search.SearchMatch;

import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo;

/*
* SearchEngine we use often gives us more matches than needed when
* query contains a * and/or contains a fqn. e.g. java.io.paths.get*
Expand Down Expand Up @@ -78,6 +78,10 @@ public boolean visit(MethodInvocation node) {
// get fqn of the method being called
ITypeBinding declaringClass = binding.getDeclaringClass();
if (declaringClass != null) {
// Handle Erasure results
if (declaringClass.getErasure() != null) {
declaringClass = declaringClass.getErasure();
}
String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName();
// match fqn with query pattern
if (fullyQualifiedName.matches(this.query)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ default boolean queryQualificationMatches(String query, ICompilationUnit unit, L
// for a query, java.io.paths.File*, queryQualification is java.io.paths
queryQualification = query.substring(0, dotIndex);
}
String packageQueryQualification = "";
int packageDotIndex = queryQualification.lastIndexOf('.');
if (packageDotIndex > 0) {
// for a query, java.io.paths.File*, queryQualification is java.io.paths
packageQueryQualification = queryQualification.substring(0, packageDotIndex);
}

// check if the match was found in the same package as the query was looking for
if (queryQualification != "" && location.getUri().contains(queryQualification.replaceAll(".", "/"))) {
return true;
Expand All @@ -196,7 +203,7 @@ default boolean queryQualificationMatches(String query, ICompilationUnit unit, L
try {
// check if the package declaration on the unit matches query
for (IPackageDeclaration packageDecl : unit.getPackageDeclarations()) {
if (queryQualification != "" && packageDecl.getElementName().matches(queryQualification)) {
if (packageQueryQualification!= "" && packageDecl.getElementName().matches(packageQueryQualification)) {
return true;
}
}
Expand Down

0 comments on commit dabd3e5

Please sign in to comment.