Skip to content

Commit

Permalink
🐛 adding log for counting search matches found (#102)
Browse files Browse the repository at this point in the history
* 🐛 adding log for counting search matches found

Signed-off-by: Shawn Hurley <[email protected]>

* Adding KONVEYOR_LOG prefix to make provider able to log
fixing missing erasure matches

Signed-off-by: Shawn Hurley <[email protected]>

---------

Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Jul 12, 2024
1 parent acdb072 commit 68082cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.io.File;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
Expand Down Expand Up @@ -162,18 +157,20 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri
// For Partial results, we are going to filter out based on a list in the engine
int s = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES;
if (analsysisMode.equals(sourceOnlyAnalysisMode)) {
logInfo("source-only analysis mode only scoping to Sources");
logInfo("KONVEYOR_LOG: source-only analysis mode only scoping to Sources");
s = IJavaSearchScope.SOURCES;
} else {
logInfo("waiting for source downloads");
logInfo("KONVEYOR_LOG: waiting for source downloads");
waitForJavaSourceDownloads();
logInfo("waited for source downloads");
logInfo("KONVEYOR_LOG: waited for source downloads");
}

for (IJavaProject iJavaProject : targetProjects) {
var errors = ResourceUtils.getErrorMarkers(iJavaProject.getProject());
var warnings = ResourceUtils.getWarningMarkers(iJavaProject.getProject());
logInfo("for project: " + iJavaProject + " found errors: " + errors + " warnings: " + warnings);
logInfo("KONVEYOR_LOG:" +
" found errors: " + errors.toString().replace("\n", " ") +
" warnings: " + warnings.toString().replace("\n", " "));
}

IJavaSearchScope scope;
Expand Down Expand Up @@ -221,10 +218,10 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri
pattern = mapLocationToSearchPatternLocation(location, query);
} catch (Exception e) {
// TODO Auto-generated catch block
logInfo("Unable to get search pattern: " + e);
logInfo("KONVEYOR_LOG: Unable to get search pattern: " + e.toString().replace("\n", " "));
throw e;
}
logInfo("pattern: " + pattern);
logInfo("KONVEYOR_LOG: pattern: " + pattern.toString().replace("\n", " "));

SearchEngine searchEngine = new SearchEngine();

Expand All @@ -240,9 +237,14 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri
searchEngine.search(pattern, participents, scope, requestor, monitor);
} catch (Exception e) {
//TODO: handle exception
logInfo("unable to get search " + e);
logInfo("KONVEYOR_LOG: unable to get search " + e.toString().replace("\n", " "));
}

logInfo("KONVEYOR_LOG: got: " + requestor.getAllSearchMatches() +
" search matches for " + query +
" location " + location
+ " matches" + requestor.getSymbols().size());

return requestor.getSymbols();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class SymbolInformationTypeRequestor extends SearchRequestor {
private List<SymbolInformation> symbols;
private int maxResults;
private int numberSearchMatches;
private boolean sourceOnly;
private boolean isSymbolTagSupported;
private IProgressMonitor monitor;
Expand All @@ -35,6 +36,7 @@ public SymbolInformationTypeRequestor(List<SymbolInformation> symbols, int maxRe
this.monitor = monitor;
this.symbolKind = symbolKind;
this.query = query;
this.numberSearchMatches = 0;
if (maxResults == 0) {
this.maxResults = 10000;
}
Expand All @@ -43,6 +45,7 @@ public SymbolInformationTypeRequestor(List<SymbolInformation> symbols, int maxRe

@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
this.numberSearchMatches = this.numberSearchMatches + 1;
if (maxResults > 0 && symbols.size() >= maxResults) {
monitor.setCanceled(true);
logInfo("maxResults > 0 && symbols.size() >= maxResults");
Expand Down Expand Up @@ -80,6 +83,10 @@ public List<SymbolInformation> getSymbols() {
return this.symbols;
}

public int getAllSearchMatches() {
return this.numberSearchMatches;
}

// This will determine if there are error markers for the primary element that is associated with this
// element. This then will tell us if there is a reason that some results may be inaccurrate.
// TODO: We still need for each provider, to actually determine if it is a match when
Expand Down
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 68082cb

Please sign in to comment.