jlahoda-jackpot commented on a change in pull request #2324:
URL: https://github.com/apache/netbeans/pull/2324#discussion_r475134956



##########
File path: 
java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ServerTest.java
##########
@@ -848,6 +869,71 @@ public void logMessage(MessageParams arg0) {
         assertEquals(2, codeActions.size());
     }
 
+    public void testWorkspaceSymbols() throws Exception {
+        File src = new File(getWorkDir(), "Test.java");
+        src.getParentFile().mkdirs();
+        try (Writer w = new FileWriter(new File(src.getParentFile(), 
".test-project"))) {}

Review comment:
       Jackpot:
   warning: Variable w is never read

##########
File path: 
java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ServerTest.java
##########
@@ -848,6 +869,71 @@ public void logMessage(MessageParams arg0) {
         assertEquals(2, codeActions.size());
     }
 
+    public void testWorkspaceSymbols() throws Exception {
+        File src = new File(getWorkDir(), "Test.java");
+        src.getParentFile().mkdirs();
+        try (Writer w = new FileWriter(new File(src.getParentFile(), 
".test-project"))) {}
+        String code = "public class Test {\n" +
+                      "    public static class TestNested {}\n" +
+                      "    public static void testMethod() {}\n" +
+                      "}\n";
+        try (Writer w = new FileWriter(src)) {
+            w.write(code);
+        }
+        CountDownLatch indexingComplete = new CountDownLatch(1);
+        Launcher<LanguageServer> serverLauncher = 
LSPLauncher.createClientLauncher(new LanguageClient() {
+            @Override
+            public void telemetryEvent(Object arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void publishDiagnostics(PublishDiagnosticsParams params) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void showMessage(MessageParams params) {
+                if (Server.INDEXING_COMPLETED.equals(params.getMessage())) {
+                    indexingComplete.countDown();
+                } else {
+                    throw new UnsupportedOperationException("Unexpected 
message.");
+                }
+            }
+
+            @Override
+            public CompletableFuture<MessageActionItem> 
showMessageRequest(ShowMessageRequestParams arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void logMessage(MessageParams arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        }, client.getInputStream(), client.getOutputStream());
+        serverLauncher.startListening();
+        LanguageServer server = serverLauncher.getRemoteProxy();
+        InitializeParams initParams = new InitializeParams();
+        initParams.setRootUri(getWorkDir().toURI().toString());
+        InitializeResult result = server.initialize(initParams).get();

Review comment:
       Jackpot:
   warning: Variable result is never read

##########
File path: 
java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ServerTest.java
##########
@@ -848,6 +869,71 @@ public void logMessage(MessageParams arg0) {
         assertEquals(2, codeActions.size());
     }
 
+    public void testWorkspaceSymbols() throws Exception {
+        File src = new File(getWorkDir(), "Test.java");
+        src.getParentFile().mkdirs();
+        try (Writer w = new FileWriter(new File(src.getParentFile(), 
".test-project"))) {}
+        String code = "public class Test {\n" +
+                      "    public static class TestNested {}\n" +
+                      "    public static void testMethod() {}\n" +
+                      "}\n";
+        try (Writer w = new FileWriter(src)) {
+            w.write(code);
+        }
+        CountDownLatch indexingComplete = new CountDownLatch(1);
+        Launcher<LanguageServer> serverLauncher = 
LSPLauncher.createClientLauncher(new LanguageClient() {
+            @Override
+            public void telemetryEvent(Object arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void publishDiagnostics(PublishDiagnosticsParams params) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void showMessage(MessageParams params) {
+                if (Server.INDEXING_COMPLETED.equals(params.getMessage())) {
+                    indexingComplete.countDown();
+                } else {
+                    throw new UnsupportedOperationException("Unexpected 
message.");
+                }
+            }
+
+            @Override
+            public CompletableFuture<MessageActionItem> 
showMessageRequest(ShowMessageRequestParams arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            @Override
+            public void logMessage(MessageParams arg0) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        }, client.getInputStream(), client.getOutputStream());
+        serverLauncher.startListening();
+        LanguageServer server = serverLauncher.getRemoteProxy();
+        InitializeParams initParams = new InitializeParams();
+        initParams.setRootUri(getWorkDir().toURI().toString());

Review comment:
       Jackpot:
   warning: Use Utilities API for URI/File conversion

##########
File path: 
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -117,145 +119,187 @@ public void computeSymbolNames(final Context context, 
final Result result) {
             final Cache cache = scanInProgress ?
                 Cache.create(textToSearch, st) :
                 null;
-            String prefix = null;
-            final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
-            if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
-                prefix = textToSearch.substring(0, dotIndex);
-                textToSearch = textToSearch.substring(dotIndex+1);
-            }
-            final String textToHighLight = textToSearch;
-            ClassIndex.NameKind _kind;
-            boolean _caseSensitive;
-            switch (st) {
-                case PREFIX:
-                    _kind = ClassIndex.NameKind.PREFIX;
-                    _caseSensitive = true;
-                    break;
-                case REGEXP:
-                    _kind = ClassIndex.NameKind.REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = true;
-                    break;
-                case CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
-                    _caseSensitive = false;
-                    break;
-                case EXACT_NAME:
-                    _kind = ClassIndex.NameKind.SIMPLE_NAME;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_PREFIX:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_EXACT_NAME:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_REGEXP:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = false;
-                    break;
-                default:
-                    throw new IllegalArgumentException();
-            }
-            final String ident = textToSearch;
-            final ClassIndex.NameKind kind = _kind;
-            final boolean caseSensitive = _caseSensitive;
-            final Pair<NameMatcher,Boolean> restriction;
-            if (prefix != null) {
-                restriction = compileName(prefix,caseSensitive);
-                result.setHighlightText(textToHighLight);
-            } else {
-                restriction = null;
-            }
-            try {
-                final ClassIndexManager manager = 
ClassIndexManager.getDefault();
-
-                Collection<FileObject> roots = QuerySupport.findRoots(
-                        (Project)null,
-                        Collections.singleton(ClassPath.SOURCE),
-                        Collections.<String>emptySet(),
-                        Collections.<String>emptySet());
-
-                final Set<URL> rootUrls = new HashSet<>();
-                for(FileObject root : roots) {
-                    if (canceled) {
-                        return;
+            doComputeSymbols(st, textToSearch, new ResultHandler() {
+                private FileObject root;
+                private ProjectInformation projectInfo;
+                private ClassIndexImpl ci;
+                @Override
+                public void setHighlightText(String text) {
+                    result.setHighlightText(text);
+                }
+
+                @Override
+                public void runRoot(FileObject root, ClassIndexImpl ci, Exec 
exec) throws IOException, InterruptedException {
+                    try {
+                        Project project = FileOwnerQuery.getOwner(root);
+
+                        this.root = root;
+                        this.projectInfo = project == null ?
+                                null :
+                                
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
+                        this.ci = ci;
+                        exec.run();
+                    } finally {
+                        this.root = null;
+                        this.projectInfo = null;
+                        this.ci = null;
                     }
-                    rootUrls.add(root.toURL());
                 }
 
-                if (LOGGER.isLoggable(Level.FINE)) {
-                    LOGGER.log(Level.FINE, "Querying following roots:"); 
//NOI18N
-                    for (URL url : rootUrls) {
-                        LOGGER.log(Level.FINE, "  {0}", url); //NOI18N
+                @Override
+                public void handleResult(ElementHandle<TypeElement> owner, 
String ident, boolean caseSensitive) {
+                    final AsyncJavaSymbolDescriptor d = new 
AsyncJavaSymbolDescriptor(
+                            projectInfo,
+                            root,
+                            ci,
+                            owner,
+                            ident,
+                            caseSensitive);
+                    result.addResult(d);
+                    if (cache != null) {
+                        cache.offer(d);
                     }
-                    LOGGER.log(Level.FINE, "-------------------------"); 
//NOI18N
                 }
-                //Perform all queries in single op
-                IndexManager.priorityAccess(new IndexManager.Action<Void>() {
-                    @Override
-                    public Void run() throws IOException, InterruptedException 
{
-                        for (URL url : rootUrls) {
-                            if (canceled) {
-                                return null;
-                            }
-                            final FileObject root = 
URLMapper.findFileObject(url);
-                            if (root == null) {
-                                continue;
-                            }
-
-                            final Project project = 
FileOwnerQuery.getOwner(root);
-                            final ProjectInformation projectInfo = project == 
null ?
-                                    null :
-                                    
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
-                            final ClassIndexImpl impl = 
manager.getUsagesQuery(root.toURL(), true);
-                            if (impl != null) {
+            }, true, canceled);
+        } finally {
+            clearCancel();
+        }
+    }
+
+    public static void doComputeSymbols(SearchType st, String textToSearch, 
ResultHandler handler, boolean async, AtomicBoolean canceled) {
+        String prefix = null;
+        final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
+        if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
+            prefix = textToSearch.substring(0, dotIndex);
+            textToSearch = textToSearch.substring(dotIndex+1);
+        }
+        final String textToHighLight = textToSearch;
+        ClassIndex.NameKind _kind;
+        boolean _caseSensitive;
+        switch (st) {
+            case PREFIX:
+                _kind = ClassIndex.NameKind.PREFIX;
+                _caseSensitive = true;
+                break;
+            case REGEXP:
+                _kind = ClassIndex.NameKind.REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = true;
+                break;
+            case CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
+                _caseSensitive = false;
+                break;
+            case EXACT_NAME:
+                _kind = ClassIndex.NameKind.SIMPLE_NAME;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_PREFIX:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_EXACT_NAME:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_REGEXP:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = false;
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+        final String ident = textToSearch;
+        final ClassIndex.NameKind kind = _kind;
+        final boolean caseSensitive = _caseSensitive;
+        final Pair<NameMatcher,Boolean> restriction;
+        if (prefix != null) {
+            restriction = compileName(prefix,caseSensitive);
+            handler.setHighlightText(textToHighLight);
+        } else {
+            restriction = null;
+        }
+        try {
+            final ClassIndexManager manager = ClassIndexManager.getDefault();
+
+            Collection<FileObject> roots = QuerySupport.findRoots(
+                    (Project)null,
+                    Collections.singleton(ClassPath.SOURCE),
+                    Collections.<String>emptySet(),
+                    Collections.<String>emptySet());
+
+            final Set<URL> rootUrls = new HashSet<>();
+            for(FileObject root : roots) {
+                if (canceled.get()) {
+                    return;
+                }
+                rootUrls.add(root.toURL());
+            }
+
+            if (LOGGER.isLoggable(Level.FINE)) {
+                LOGGER.log(Level.FINE, "Querying following roots:"); //NOI18N
+                for (URL url : rootUrls) {

Review comment:
       Jackpot:
   warning: Can use functional operations

##########
File path: 
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -29,6 +29,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;

Review comment:
       Jackpot:
   warning: Unused Import

##########
File path: 
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -117,145 +119,187 @@ public void computeSymbolNames(final Context context, 
final Result result) {
             final Cache cache = scanInProgress ?
                 Cache.create(textToSearch, st) :
                 null;
-            String prefix = null;
-            final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
-            if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
-                prefix = textToSearch.substring(0, dotIndex);
-                textToSearch = textToSearch.substring(dotIndex+1);
-            }
-            final String textToHighLight = textToSearch;
-            ClassIndex.NameKind _kind;
-            boolean _caseSensitive;
-            switch (st) {
-                case PREFIX:
-                    _kind = ClassIndex.NameKind.PREFIX;
-                    _caseSensitive = true;
-                    break;
-                case REGEXP:
-                    _kind = ClassIndex.NameKind.REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = true;
-                    break;
-                case CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
-                    _caseSensitive = false;
-                    break;
-                case EXACT_NAME:
-                    _kind = ClassIndex.NameKind.SIMPLE_NAME;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_PREFIX:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_EXACT_NAME:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_REGEXP:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = false;
-                    break;
-                default:
-                    throw new IllegalArgumentException();
-            }
-            final String ident = textToSearch;
-            final ClassIndex.NameKind kind = _kind;
-            final boolean caseSensitive = _caseSensitive;
-            final Pair<NameMatcher,Boolean> restriction;
-            if (prefix != null) {
-                restriction = compileName(prefix,caseSensitive);
-                result.setHighlightText(textToHighLight);
-            } else {
-                restriction = null;
-            }
-            try {
-                final ClassIndexManager manager = 
ClassIndexManager.getDefault();
-
-                Collection<FileObject> roots = QuerySupport.findRoots(
-                        (Project)null,
-                        Collections.singleton(ClassPath.SOURCE),
-                        Collections.<String>emptySet(),
-                        Collections.<String>emptySet());
-
-                final Set<URL> rootUrls = new HashSet<>();
-                for(FileObject root : roots) {
-                    if (canceled) {
-                        return;
+            doComputeSymbols(st, textToSearch, new ResultHandler() {
+                private FileObject root;
+                private ProjectInformation projectInfo;
+                private ClassIndexImpl ci;
+                @Override
+                public void setHighlightText(String text) {
+                    result.setHighlightText(text);
+                }
+
+                @Override
+                public void runRoot(FileObject root, ClassIndexImpl ci, Exec 
exec) throws IOException, InterruptedException {
+                    try {
+                        Project project = FileOwnerQuery.getOwner(root);
+
+                        this.root = root;
+                        this.projectInfo = project == null ?
+                                null :
+                                
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
+                        this.ci = ci;
+                        exec.run();
+                    } finally {
+                        this.root = null;
+                        this.projectInfo = null;
+                        this.ci = null;
                     }
-                    rootUrls.add(root.toURL());
                 }
 
-                if (LOGGER.isLoggable(Level.FINE)) {
-                    LOGGER.log(Level.FINE, "Querying following roots:"); 
//NOI18N
-                    for (URL url : rootUrls) {
-                        LOGGER.log(Level.FINE, "  {0}", url); //NOI18N
+                @Override
+                public void handleResult(ElementHandle<TypeElement> owner, 
String ident, boolean caseSensitive) {
+                    final AsyncJavaSymbolDescriptor d = new 
AsyncJavaSymbolDescriptor(
+                            projectInfo,
+                            root,
+                            ci,
+                            owner,
+                            ident,
+                            caseSensitive);
+                    result.addResult(d);
+                    if (cache != null) {
+                        cache.offer(d);
                     }
-                    LOGGER.log(Level.FINE, "-------------------------"); 
//NOI18N
                 }
-                //Perform all queries in single op
-                IndexManager.priorityAccess(new IndexManager.Action<Void>() {
-                    @Override
-                    public Void run() throws IOException, InterruptedException 
{
-                        for (URL url : rootUrls) {
-                            if (canceled) {
-                                return null;
-                            }
-                            final FileObject root = 
URLMapper.findFileObject(url);
-                            if (root == null) {
-                                continue;
-                            }
-
-                            final Project project = 
FileOwnerQuery.getOwner(root);
-                            final ProjectInformation projectInfo = project == 
null ?
-                                    null :
-                                    
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
-                            final ClassIndexImpl impl = 
manager.getUsagesQuery(root.toURL(), true);
-                            if (impl != null) {
+            }, true, canceled);
+        } finally {
+            clearCancel();
+        }
+    }
+
+    public static void doComputeSymbols(SearchType st, String textToSearch, 
ResultHandler handler, boolean async, AtomicBoolean canceled) {
+        String prefix = null;
+        final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
+        if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
+            prefix = textToSearch.substring(0, dotIndex);
+            textToSearch = textToSearch.substring(dotIndex+1);
+        }
+        final String textToHighLight = textToSearch;
+        ClassIndex.NameKind _kind;
+        boolean _caseSensitive;
+        switch (st) {
+            case PREFIX:
+                _kind = ClassIndex.NameKind.PREFIX;
+                _caseSensitive = true;
+                break;
+            case REGEXP:
+                _kind = ClassIndex.NameKind.REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = true;
+                break;
+            case CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
+                _caseSensitive = false;
+                break;
+            case EXACT_NAME:
+                _kind = ClassIndex.NameKind.SIMPLE_NAME;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_PREFIX:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_EXACT_NAME:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_REGEXP:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = false;
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+        final String ident = textToSearch;
+        final ClassIndex.NameKind kind = _kind;
+        final boolean caseSensitive = _caseSensitive;
+        final Pair<NameMatcher,Boolean> restriction;
+        if (prefix != null) {
+            restriction = compileName(prefix,caseSensitive);
+            handler.setHighlightText(textToHighLight);
+        } else {
+            restriction = null;
+        }
+        try {
+            final ClassIndexManager manager = ClassIndexManager.getDefault();
+
+            Collection<FileObject> roots = QuerySupport.findRoots(
+                    (Project)null,
+                    Collections.singleton(ClassPath.SOURCE),
+                    Collections.<String>emptySet(),
+                    Collections.<String>emptySet());
+
+            final Set<URL> rootUrls = new HashSet<>();
+            for(FileObject root : roots) {
+                if (canceled.get()) {
+                    return;
+                }
+                rootUrls.add(root.toURL());
+            }
+
+            if (LOGGER.isLoggable(Level.FINE)) {
+                LOGGER.log(Level.FINE, "Querying following roots:"); //NOI18N
+                for (URL url : rootUrls) {
+                    LOGGER.log(Level.FINE, "  {0}", url); //NOI18N
+                }
+                LOGGER.log(Level.FINE, "-------------------------"); //NOI18N
+            }
+            //Perform all queries in single op
+            IndexManager.priorityAccess(new IndexManager.Action<Void>() {

Review comment:
       Jackpot:
   warning: This anonymous inner class creation can be turned into a lambda 
expression.

##########
File path: 
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -117,145 +119,187 @@ public void computeSymbolNames(final Context context, 
final Result result) {
             final Cache cache = scanInProgress ?
                 Cache.create(textToSearch, st) :
                 null;
-            String prefix = null;
-            final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
-            if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
-                prefix = textToSearch.substring(0, dotIndex);
-                textToSearch = textToSearch.substring(dotIndex+1);
-            }
-            final String textToHighLight = textToSearch;
-            ClassIndex.NameKind _kind;
-            boolean _caseSensitive;
-            switch (st) {
-                case PREFIX:
-                    _kind = ClassIndex.NameKind.PREFIX;
-                    _caseSensitive = true;
-                    break;
-                case REGEXP:
-                    _kind = ClassIndex.NameKind.REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = true;
-                    break;
-                case CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
-                    _caseSensitive = false;
-                    break;
-                case EXACT_NAME:
-                    _kind = ClassIndex.NameKind.SIMPLE_NAME;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_PREFIX:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_EXACT_NAME:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_REGEXP:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = false;
-                    break;
-                default:
-                    throw new IllegalArgumentException();
-            }
-            final String ident = textToSearch;
-            final ClassIndex.NameKind kind = _kind;
-            final boolean caseSensitive = _caseSensitive;
-            final Pair<NameMatcher,Boolean> restriction;
-            if (prefix != null) {
-                restriction = compileName(prefix,caseSensitive);
-                result.setHighlightText(textToHighLight);
-            } else {
-                restriction = null;
-            }
-            try {
-                final ClassIndexManager manager = 
ClassIndexManager.getDefault();
-
-                Collection<FileObject> roots = QuerySupport.findRoots(
-                        (Project)null,
-                        Collections.singleton(ClassPath.SOURCE),
-                        Collections.<String>emptySet(),
-                        Collections.<String>emptySet());
-
-                final Set<URL> rootUrls = new HashSet<>();
-                for(FileObject root : roots) {
-                    if (canceled) {
-                        return;
+            doComputeSymbols(st, textToSearch, new ResultHandler() {
+                private FileObject root;
+                private ProjectInformation projectInfo;
+                private ClassIndexImpl ci;
+                @Override
+                public void setHighlightText(String text) {
+                    result.setHighlightText(text);
+                }
+
+                @Override
+                public void runRoot(FileObject root, ClassIndexImpl ci, Exec 
exec) throws IOException, InterruptedException {
+                    try {
+                        Project project = FileOwnerQuery.getOwner(root);
+
+                        this.root = root;
+                        this.projectInfo = project == null ?
+                                null :
+                                
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive

Review comment:
       Jackpot:
   warning: Use ProjectUtils API

##########
File path: 
java/java.sourceui/src/org/netbeans/modules/java/source/ui/JavaSymbolProvider.java
##########
@@ -117,145 +119,187 @@ public void computeSymbolNames(final Context context, 
final Result result) {
             final Cache cache = scanInProgress ?
                 Cache.create(textToSearch, st) :
                 null;
-            String prefix = null;
-            final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
-            if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
-                prefix = textToSearch.substring(0, dotIndex);
-                textToSearch = textToSearch.substring(dotIndex+1);
-            }
-            final String textToHighLight = textToSearch;
-            ClassIndex.NameKind _kind;
-            boolean _caseSensitive;
-            switch (st) {
-                case PREFIX:
-                    _kind = ClassIndex.NameKind.PREFIX;
-                    _caseSensitive = true;
-                    break;
-                case REGEXP:
-                    _kind = ClassIndex.NameKind.REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = true;
-                    break;
-                case CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_CAMEL_CASE:
-                    _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
-                    _caseSensitive = false;
-                    break;
-                case EXACT_NAME:
-                    _kind = ClassIndex.NameKind.SIMPLE_NAME;
-                    _caseSensitive = true;
-                    break;
-                case CASE_INSENSITIVE_PREFIX:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_EXACT_NAME:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    _caseSensitive = false;
-                    break;
-                case CASE_INSENSITIVE_REGEXP:
-                    _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
-                    textToSearch = NameMatcherFactory.wildcardsToRegexp(
-                            removeNonJavaChars(textToSearch),
-                            true);
-                    _caseSensitive = false;
-                    break;
-                default:
-                    throw new IllegalArgumentException();
-            }
-            final String ident = textToSearch;
-            final ClassIndex.NameKind kind = _kind;
-            final boolean caseSensitive = _caseSensitive;
-            final Pair<NameMatcher,Boolean> restriction;
-            if (prefix != null) {
-                restriction = compileName(prefix,caseSensitive);
-                result.setHighlightText(textToHighLight);
-            } else {
-                restriction = null;
-            }
-            try {
-                final ClassIndexManager manager = 
ClassIndexManager.getDefault();
-
-                Collection<FileObject> roots = QuerySupport.findRoots(
-                        (Project)null,
-                        Collections.singleton(ClassPath.SOURCE),
-                        Collections.<String>emptySet(),
-                        Collections.<String>emptySet());
-
-                final Set<URL> rootUrls = new HashSet<>();
-                for(FileObject root : roots) {
-                    if (canceled) {
-                        return;
+            doComputeSymbols(st, textToSearch, new ResultHandler() {
+                private FileObject root;
+                private ProjectInformation projectInfo;
+                private ClassIndexImpl ci;
+                @Override
+                public void setHighlightText(String text) {
+                    result.setHighlightText(text);
+                }
+
+                @Override
+                public void runRoot(FileObject root, ClassIndexImpl ci, Exec 
exec) throws IOException, InterruptedException {
+                    try {
+                        Project project = FileOwnerQuery.getOwner(root);
+
+                        this.root = root;
+                        this.projectInfo = project == null ?
+                                null :
+                                
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
+                        this.ci = ci;
+                        exec.run();
+                    } finally {
+                        this.root = null;
+                        this.projectInfo = null;
+                        this.ci = null;
                     }
-                    rootUrls.add(root.toURL());
                 }
 
-                if (LOGGER.isLoggable(Level.FINE)) {
-                    LOGGER.log(Level.FINE, "Querying following roots:"); 
//NOI18N
-                    for (URL url : rootUrls) {
-                        LOGGER.log(Level.FINE, "  {0}", url); //NOI18N
+                @Override
+                public void handleResult(ElementHandle<TypeElement> owner, 
String ident, boolean caseSensitive) {
+                    final AsyncJavaSymbolDescriptor d = new 
AsyncJavaSymbolDescriptor(
+                            projectInfo,
+                            root,
+                            ci,
+                            owner,
+                            ident,
+                            caseSensitive);
+                    result.addResult(d);
+                    if (cache != null) {
+                        cache.offer(d);
                     }
-                    LOGGER.log(Level.FINE, "-------------------------"); 
//NOI18N
                 }
-                //Perform all queries in single op
-                IndexManager.priorityAccess(new IndexManager.Action<Void>() {
-                    @Override
-                    public Void run() throws IOException, InterruptedException 
{
-                        for (URL url : rootUrls) {
-                            if (canceled) {
-                                return null;
-                            }
-                            final FileObject root = 
URLMapper.findFileObject(url);
-                            if (root == null) {
-                                continue;
-                            }
-
-                            final Project project = 
FileOwnerQuery.getOwner(root);
-                            final ProjectInformation projectInfo = project == 
null ?
-                                    null :
-                                    
project.getLookup().lookup(ProjectInformation.class);   //Intentionally does 
not use ProjectUtils.getInformation() it does project icon annotation which is 
expensive
-                            final ClassIndexImpl impl = 
manager.getUsagesQuery(root.toURL(), true);
-                            if (impl != null) {
+            }, true, canceled);
+        } finally {
+            clearCancel();
+        }
+    }
+
+    public static void doComputeSymbols(SearchType st, String textToSearch, 
ResultHandler handler, boolean async, AtomicBoolean canceled) {
+        String prefix = null;
+        final int dotIndex = textToSearch.lastIndexOf('.'); //NOI18N
+        if (dotIndex > 0 && dotIndex != textToSearch.length()-1) {
+            prefix = textToSearch.substring(0, dotIndex);
+            textToSearch = textToSearch.substring(dotIndex+1);
+        }
+        final String textToHighLight = textToSearch;
+        ClassIndex.NameKind _kind;
+        boolean _caseSensitive;
+        switch (st) {
+            case PREFIX:
+                _kind = ClassIndex.NameKind.PREFIX;
+                _caseSensitive = true;
+                break;
+            case REGEXP:
+                _kind = ClassIndex.NameKind.REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = true;
+                break;
+            case CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_CAMEL_CASE:
+                _kind = ClassIndex.NameKind.CAMEL_CASE_INSENSITIVE;
+                _caseSensitive = false;
+                break;
+            case EXACT_NAME:
+                _kind = ClassIndex.NameKind.SIMPLE_NAME;
+                _caseSensitive = true;
+                break;
+            case CASE_INSENSITIVE_PREFIX:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_EXACT_NAME:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                _caseSensitive = false;
+                break;
+            case CASE_INSENSITIVE_REGEXP:
+                _kind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP;
+                textToSearch = NameMatcherFactory.wildcardsToRegexp(
+                        removeNonJavaChars(textToSearch),
+                        true);
+                _caseSensitive = false;
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+        final String ident = textToSearch;
+        final ClassIndex.NameKind kind = _kind;
+        final boolean caseSensitive = _caseSensitive;
+        final Pair<NameMatcher,Boolean> restriction;
+        if (prefix != null) {
+            restriction = compileName(prefix,caseSensitive);
+            handler.setHighlightText(textToHighLight);
+        } else {
+            restriction = null;
+        }
+        try {
+            final ClassIndexManager manager = ClassIndexManager.getDefault();
+
+            Collection<FileObject> roots = QuerySupport.findRoots(
+                    (Project)null,
+                    Collections.singleton(ClassPath.SOURCE),
+                    Collections.<String>emptySet(),
+                    Collections.<String>emptySet());
+
+            final Set<URL> rootUrls = new HashSet<>();
+            for(FileObject root : roots) {
+                if (canceled.get()) {
+                    return;
+                }
+                rootUrls.add(root.toURL());
+            }
+
+            if (LOGGER.isLoggable(Level.FINE)) {
+                LOGGER.log(Level.FINE, "Querying following roots:"); //NOI18N
+                for (URL url : rootUrls) {
+                    LOGGER.log(Level.FINE, "  {0}", url); //NOI18N
+                }
+                LOGGER.log(Level.FINE, "-------------------------"); //NOI18N
+            }
+            //Perform all queries in single op
+            IndexManager.priorityAccess(new IndexManager.Action<Void>() {
+                @Override
+                public Void run() throws IOException, InterruptedException {
+                    for (URL url : rootUrls) {
+                        if (canceled.get()) {
+                            return null;
+                        }
+                        final FileObject root = URLMapper.findFileObject(url);
+                        if (root == null) {
+                            continue;
+                        }
+
+                        final ClassIndexImpl impl = 
manager.getUsagesQuery(root.toURL(), true);
+                        if (impl != null) {
+                            handler.runRoot(root, impl, () -> {
                                 final 
Map<ElementHandle<TypeElement>,Set<String>> r = new HashMap<>();
                                 impl.getDeclaredElements(ident, kind, 
DocumentUtil.typeElementConvertor(),r);
                                 if (!r.isEmpty()) {
                                     for (final 
Map.Entry<ElementHandle<TypeElement>,Set<String>> p : r.entrySet()) {
                                         final ElementHandle<TypeElement> owner 
= p.getKey();
                                         for (String symbol : p.getValue()) {
                                             if 
(matchesRestrictions(owner.getQualifiedName(), symbol, restriction, 
caseSensitive)) {
-                                                final 
AsyncJavaSymbolDescriptor d = new AsyncJavaSymbolDescriptor(
-                                                        projectInfo,
-                                                        root,
-                                                        impl,
-                                                        owner,
-                                                        symbol,
-                                                        caseSensitive);
-                                                result.addResult(d);
-                                                if (cache != null) {
-                                                    cache.offer(d);
-                                                }
+                                                handler.handleResult(owner, 
symbol, caseSensitive);
                                             }
                                         }
                                     }
                                 }
-                            }
+                            });
                         }
-                        return null;
                     }
-                });
-            } catch (IOException ioe) {
-                Exceptions.printStackTrace(ioe);
-            }
-            catch (InterruptedException ie) {
-                return;
-            }
-        } finally {
-            clearCancel();
+                    return null;
+                }
+            });
+        } catch (IOException ioe) {
+            Exceptions.printStackTrace(ioe);
+        }
+        catch (InterruptedException ie) {
+            return;

Review comment:
       Jackpot:
   warning: Unnecessary return statement

##########
File path: 
cpplite/cpplite.editor/src/org/netbeans/modules/cpplite/editor/lsp/LanguageServerImpl.java
##########
@@ -64,9 +64,10 @@
 })
 public class LanguageServerImpl implements LanguageServerProvider {
 
+    private static final boolean DEBUG = 
Boolean.getBoolean("cpplite.lsp.debug");
     private static final Logger LOG = 
Logger.getLogger(LanguageServerImpl.class.getName());
 
-    private Map<Project, LanguageServerDescription> prj2Server = new 
HashMap<>();
+    private static Map<Project, LanguageServerDescription> prj2Server = new 
HashMap<>();

Review comment:
       Jackpot:
   warning: Field prj2Server can be final

##########
File path: ide/jumpto/src/org/netbeans/spi/jumpto/symbol/SymbolProvider.java
##########
@@ -198,6 +198,7 @@ public void setSymbolProvider(SymbolDescriptor desc, 
SymbolProvider provider) {
         private boolean dirty;
         private boolean highlightTextAlreadySet;
         private int retry;
+        private boolean requiresCustomFiltering;

Review comment:
       Jackpot:
   warning: Variable requiresCustomFiltering is never read

##########
File path: 
ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/TypeProviderImpl.java
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.lsp.client.bindings;
+
+import java.util.EnumSet;
+import java.util.Set;
+import javax.swing.Icon;
+import org.eclipse.lsp4j.SymbolInformation;
+import org.eclipse.lsp4j.SymbolKind;
+import org.netbeans.spi.jumpto.type.TypeDescriptor;
+import org.netbeans.spi.jumpto.type.TypeProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=TypeProvider.class)
+public class TypeProviderImpl extends BaseSymbolProvider implements 
TypeProvider {
+
+    private static final Set<SymbolKind> TYPE_KINDS = EnumSet.of(
+            SymbolKind.Class, SymbolKind.Enum, SymbolKind.Interface,
+            SymbolKind.Struct
+    );
+
+    @Override
+    @Messages("DN_TypeProviderImpl=Language Server Type Provider")
+    public String getDisplayName() {
+        return Bundle.DN_TypeProviderImpl();
+    }
+
+    @Override
+    public void computeTypeNames(Context context, Result result) {
+        computeSymbolNames(context.getSearchType(),
+                           context.getText(),
+                           (info, simpleName) -> {
+                               if (TYPE_KINDS.contains(info.getKind())) {
+                                   result.addResult(new 
TypeDescriptorImpl(info, simpleName));
+                               }
+                           });
+    }
+
+    public static class TypeDescriptorImpl extends TypeDescriptor implements 
BaseSymbolDescriptor {
+
+        private final SymbolInformation info;
+        private final String simpleName;
+
+        public TypeDescriptorImpl(SymbolInformation info, String simpleName) {
+            this.info = info;
+            this.simpleName = simpleName;
+        }
+
+        public SymbolInformation getInfo() {

Review comment:
       Jackpot:
   warning: Add @Override Annotation




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to