From 30bc142484d2dd9bb937e52ad7b49b6127b3afb2 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Thu, 19 Oct 2023 10:26:40 -0400 Subject: [PATCH] When there are errors in the resource files matches are always inaccurate (#78) Signed-off-by: Shawn Hurley --- .../SampleDelegateCommandHandler.java | 9 +++- .../SymbolInformationTypeRequestor.java | 47 +++++++++++++------ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java index 1fd3f48..a4b3638 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java @@ -17,6 +17,7 @@ import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler; import org.eclipse.jdt.ls.core.internal.JobHelpers; import org.eclipse.jdt.ls.core.internal.ProjectUtils; +import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.lsp4j.SymbolInformation; public class SampleDelegateCommandHandler implements IDelegateCommandHandler { @@ -138,12 +139,12 @@ private static List search(String projectName, String query, IJavaProject[] targetProjects; IJavaProject project = ProjectUtils.getJavaProject(projectName); - logInfo("Searching in project: " + project + " Query: " + query); if (project != null) { targetProjects = new IJavaProject[] { project }; } else { targetProjects= ProjectUtils.getJavaProjects(); } + logInfo("Searching in target project: " + targetProjects); // For Partial results, we are going to filter out based on a list in the engine @@ -157,6 +158,12 @@ private static List search(String projectName, String query, logInfo("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); + } + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(targetProjects, s); logInfo("scope: " + scope); diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SymbolInformationTypeRequestor.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SymbolInformationTypeRequestor.java index 1cb9e24..6e396d0 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SymbolInformationTypeRequestor.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SymbolInformationTypeRequestor.java @@ -12,6 +12,7 @@ import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.search.SearchMatch; import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.lsp4j.SymbolInformation; import io.konveyor.tackle.core.internal.symbol.SymbolProvider; @@ -48,6 +49,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException { return; } + if (match.isInsideDocComment()) { logInfo("found match inside doc comment: " + match); return; @@ -61,22 +63,26 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException { } - if ((!this.query.contains("?") && !this.query.contains("*")) && match.getAccuracy() == SearchMatch.A_INACCURATE) { - var e = (IJavaElement) match.getElement(); - //TODO: This is a hack, this will give use some clue of what we are looking at, if the search is exact then this should match - // I don't love this, but seems to be the right way - logInfo("attempting: " + e.getHandleIdentifier()); - // Adding specific case for annotations, they will always be inaccurrate. - if (!e.getHandleIdentifier().contains(query) && !(this.symbolKind == 4 || this.symbolKind == 5 || this.symbolKind == 1)) { - logInfo("exact match is looking for accurate results" + match); - return; + var e = (IJavaElement) match.getElement(); + if (shouldCheckAccuracy(e)) { + + if ((!this.query.contains("?") && !this.query.contains("*")) && match.getAccuracy() == SearchMatch.A_INACCURATE) { + + //TODO: This is a hack, this will give use some clue of what we are looking at, if the search is exact then this should match + // I don't love this, but seems to be the right way + logInfo("attempting: " + e.getHandleIdentifier()); + // Adding specific case for annotations, they will always be inaccurrate. + if (!e.getHandleIdentifier().contains(query) && !(this.symbolKind == 4 || this.symbolKind == 5 || this.symbolKind == 1 || this.symbolKind == 3)) { + logInfo("exact match is looking for accurate results" + match); + return; + } } - } - if ((this.query.contains("?") && (this.query.contains("(") || this.query.contains(")"))) && match.getAccuracy() == SearchMatch.A_INACCURATE) { - if(!this.query.contains("*")) { - logInfo("exact match is looking for accurate results " + match); - return; + if ((this.query.contains("?") && (this.query.contains("(") || this.query.contains(")"))) && match.getAccuracy() == SearchMatch.A_INACCURATE) { + if(!this.query.contains("*")) { + logInfo("exact match is looking for accurate results " + match); + return; + } } } @@ -97,4 +103,17 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException { public List getSymbols() { return this.symbols; } + + // 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 + // inaccurate but this will give us a quick win when there are not issues in the java projects/compilation units. + private boolean shouldCheckAccuracy(IJavaElement element) throws CoreException{ + var errors = ResourceUtils.getErrorMarkers(element.getPrimaryElement().getResource()); + if (!errors.isEmpty()) { + logInfo("unable to check accuracy for element: " + element + " got errors: " + errors); + return false; + } + return true; + } }