From 90c6314cfe1460b12b1f4f7f6a87a11bf169e0e5 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Mon, 22 Jul 2024 11:50:19 -0400 Subject: [PATCH] :bug: handle when a default search will have invalid query for a particular location (#105) Signed-off-by: Shawn Hurley --- .../SampleDelegateCommandHandler.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 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 5de1d84..b992cee 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 @@ -7,7 +7,6 @@ import java.util.List; import java.util.regex.Pattern; -import io.konveyor.tackle.core.internal.query.AnnotationQuery; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; @@ -26,6 +25,8 @@ import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.lsp4j.SymbolInformation; +import io.konveyor.tackle.core.internal.query.AnnotationQuery; + public class SampleDelegateCommandHandler implements IDelegateCommandHandler { public static final String COMMAND_ID = "io.konveyor.tackle.samplecommand"; @@ -96,15 +97,25 @@ private static SearchPattern mapLocationToSearchPatternLocation(int location, St } if (location == 0) { - logInfo("default query passed, searching everything"); + logInfo("default query passed " + query + ", searching everything"); ArrayList l = new ArrayList(); // Searching for Type, Method, and Constructor's. - l.add(getPatternSingleQuery(10, query)); - l.add(getPatternSingleQuery(2, query)); - l.add(getPatternSingleQuery(3, query)); - + var p = getPatternSingleQuery(10, query); + if (p != null) { + l.add(p); + } + p = getPatternSingleQuery(2, query); + if (p != null) { + l.add(p); + } + p = getPatternSingleQuery(3, query); + if (p != null) { + l.add(p); + } + logInfo("list of p: " + p); + // Get the end pattern - SearchPattern p = l.subList(1, l.size()).stream().reduce(l.get(0), (SearchPattern::createOrPattern)); + p = l.subList(1, l.size()).stream().reduce(l.get(0), (SearchPattern::createOrPattern)); return p; }