Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 adding log for counting search matches found #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I observed this too with my PR.

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
Loading