jlahoda-jackpot commented on a change in pull request #2324:
URL: https://github.com/apache/netbeans/pull/2324#discussion_r475134897
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
+ TypeElement te =
e.getKey().resolve(cc);
+
+ for (String ident :
e.getValue()) {
+ if
(ident.equals(getSimpleName(te, null, false))) {
Review comment:
Jackpot:
warning: Passing possible null to not-null argument
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
Review comment:
Jackpot:
warning: Can use functional operations
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
Review comment:
Jackpot:
warning: Can use functional operations
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
+ TypeElement te =
e.getKey().resolve(cc);
+
+ for (String ident :
e.getValue()) {
Review comment:
Jackpot:
warning: Can use functional operations
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
+ TypeElement te =
e.getKey().resolve(cc);
+
+ for (String ident :
e.getValue()) {
+ if
(ident.equals(getSimpleName(te, null, false))) {
+ TreePath path =
cc.getTrees().getPath(te);
+
+ if (path != null) {
+ final String
symbolName = te.getSimpleName().toString();
+ final
ElementKind kind = te.getKind();
+
SymbolInformation symbol = new SymbolInformation(symbolName,
Utils.elementKind2SymbolKind(kind), tree2Location(cc, path),
te.getQualifiedName().toString());
+
+
symbol.setDeprecated(false);
+
symbols.add(symbol);
+ }
+ }
+ for (Element ne :
te.getEnclosedElements()) {
Review comment:
Jackpot:
warning: Can use functional operations
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
+ TypeElement te =
e.getKey().resolve(cc);
+
+ for (String ident :
e.getValue()) {
+ if
(ident.equals(getSimpleName(te, null, false))) {
+ TreePath path =
cc.getTrees().getPath(te);
+
+ if (path != null) {
+ final String
symbolName = te.getSimpleName().toString();
Review comment:
Jackpot:
warning: Dereferencing possible null pointer
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
*/
package org.netbeans.modules.java.lsp.server.workspace;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
/**
*
* @author lahvac
*/
public class WorkspaceServiceImpl implements WorkspaceService {
+ private static final RequestProcessor WORKER = new
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
@Override
- public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends SymbolInformation>>
symbol(WorkspaceSymbolParams params) {
+ String query = params.getQuery();
+ if (query.isEmpty()) {
+ //cannot query "all":
+ return CompletableFuture.completedFuture(Collections.emptyList());
+ }
+ System.err.println("query=" + query);
+ boolean exact = false;
+ if (query.endsWith(" ")) {
+ query = query.substring(0, query.length() - 1);
+ exact = true;
+ }
+ String queryFin = query;
+ boolean exactFin = exact;
+ AtomicBoolean cancel = new AtomicBoolean();
+ CompletableFuture<List<? extends SymbolInformation>> result = new
CompletableFuture<List<? extends SymbolInformation>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ try {
+ List<SymbolInformation> symbols = new ArrayList<>();
+ ResultHandler handler = new ResultHandler() {
+ @Override
+ public void setHighlightText(String text) {
+ }
+
+ private Map<ElementHandle<TypeElement>, List<String>>
type2Idents;
+
+ @Override
+ public void runRoot(FileObject root, ClassIndexImpl ci,
Exec exec) throws IOException, InterruptedException {
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ try {
+ type2Idents = new HashMap<>();
+ exec.run();
+ Map<FileObject, Map<ElementHandle<TypeElement>,
List<String>>> sources = new HashMap<>();
+ for (Entry<ElementHandle<TypeElement>,
List<String>> e : type2Idents.entrySet()) {
+ FileObject sourceFile =
SourceUtils.getFile(e.getKey(), cpInfo);
+ sources.computeIfAbsent(sourceFile, s -> new
HashMap<>())
+ .put(e.getKey(), e.getValue());
+ }
+ if (!sources.isEmpty()) {
+ JavaSource.create(cpInfo, sources.keySet())
+ .runUserActionTask(cc -> {
+ if
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+ return ;
+ }
+ for
(Entry<ElementHandle<TypeElement>, List<String>> e :
sources.get(cc.getFileObject()).entrySet()) {
+ TypeElement te =
e.getKey().resolve(cc);
+
+ for (String ident :
e.getValue()) {
+ if
(ident.equals(getSimpleName(te, null, false))) {
+ TreePath path =
cc.getTrees().getPath(te);
+
+ if (path != null) {
+ final String
symbolName = te.getSimpleName().toString();
+ final
ElementKind kind = te.getKind();
+
SymbolInformation symbol = new SymbolInformation(symbolName,
Utils.elementKind2SymbolKind(kind), tree2Location(cc, path),
te.getQualifiedName().toString());
+
+
symbol.setDeprecated(false);
+
symbols.add(symbol);
+ }
+ }
+ for (Element ne :
te.getEnclosedElements()) {
Review comment:
Jackpot:
warning: Dereferencing possible null pointer
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
##########
@@ -0,0 +1,215 @@
+/*
+ * 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.java.lsp.server;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.LineMap;
+import com.sun.source.tree.Tree;
+import com.sun.source.util.TreePath;
Review comment:
Jackpot:
warning: Unused Import
##########
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();
+ indexingComplete.await();
+ List<? extends SymbolInformation> symbols =
server.getWorkspaceService().symbol(new WorkspaceSymbolParams("Tes")).get();
+ List<String> actual = symbols.stream().map(si -> si.getKind() + ":" +
si.getName() + ":" + si.getContainerName() + ":" + si.getDeprecated() + ":" +
toString(si.getLocation())).collect(Collectors.toList());
+ assertEquals(Arrays.asList("Class:Test:Test:false:Test.java:0:0-3:1",
+
"Constructor:():Test:false:Test.java:0:7-0:7",
+ "Method:():Test:false:Test.java:2:4-2:38",
+
"Class:TestNested:Test.TestNested:false:Test.java:1:4-1:37",
+
"Constructor:():Test.TestNested:false:Test.java:1:18-1:18"),
+ actual);
+ }
+
+ private String toString(Location location) {
Review comment:
Jackpot:
warning: toString is never used
----------------------------------------------------------------
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