use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class SyntaxServerTest method testDocumentSymbol.
@Test
public void testDocumentSymbol() throws Exception {
when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(Boolean.TRUE);
URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
DocumentSymbolParams params = new DocumentSymbolParams(identifier);
List<Either<SymbolInformation, DocumentSymbol>> result = server.documentSymbol(params).join();
assertNotNull(result);
assertEquals(2, result.size());
Either<SymbolInformation, DocumentSymbol> symbol = result.get(0);
assertTrue(symbol.isRight());
assertEquals("java", symbol.getRight().getName());
assertEquals(SymbolKind.Package, symbol.getRight().getKind());
symbol = result.get(1);
assertTrue(symbol.isRight());
assertEquals("Foo", symbol.getRight().getName());
assertEquals(SymbolKind.Class, symbol.getRight().getKind());
List<DocumentSymbol> children = symbol.getRight().getChildren();
assertNotNull(children);
assertEquals(1, children.size());
assertEquals("main(String[])", children.get(0).getName());
assertEquals(SymbolKind.Method, children.get(0).getKind());
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandlerTest method testClass.
private void testClass(String className, boolean hierarchical) throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
if (!hierarchical) {
List<? extends SymbolInformation> symbols = getSymbols(className);
for (SymbolInformation symbol : symbols) {
Location loc = symbol.getLocation();
assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", loc != null && isValid(loc.getRange()));
}
} else {
List<? extends DocumentSymbol> hierarchicalSymbols = getHierarchicalSymbols(className);
for (DocumentSymbol symbol : hierarchicalSymbols) {
Range fullRange = symbol.getRange();
Range selectionRange = symbol.getSelectionRange();
assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", fullRange != null && isValid(fullRange) && selectionRange != null && isValid(selectionRange));
}
}
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandlerTest method testSyntheticMember.
@Test
public void testSyntheticMember() throws Exception {
String className = "org.apache.commons.lang3.text.StrTokenizer";
List<? extends SymbolInformation> symbols = getSymbols(className);
boolean overloadedMethod1Found = false;
boolean overloadedMethod2Found = false;
String overloadedMethod1 = "getCSVInstance(String)";
String overloadedMethod2 = "reset()";
for (SymbolInformation symbol : symbols) {
Location loc = symbol.getLocation();
assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.", loc != null && isValid(loc.getRange()));
assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid name", symbol.getName().startsWith("access$"));
assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + "- invalid name", symbol.getName().equals("<clinit>"));
if (overloadedMethod1.equals(symbol.getName())) {
overloadedMethod1Found = true;
}
if (overloadedMethod2.equals(symbol.getName())) {
overloadedMethod2Found = true;
}
}
assertTrue("The " + overloadedMethod1 + " method hasn't been found", overloadedMethod1Found);
assertTrue("The " + overloadedMethod2 + " method hasn't been found", overloadedMethod2Found);
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandlerTest method getSymbols.
private List<? extends SymbolInformation> getSymbols(String className) throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
String uri = ClassFileUtil.getURI(project, className);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
DocumentSymbolParams params = new DocumentSymbolParams();
params.setTextDocument(identifier);
when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(false);
// @formatter:off
List<SymbolInformation> symbols = new DocumentSymbolHandler(preferenceManager).documentSymbol(params, monitor).stream().map(Either::getLeft).collect(toList());
// @formatter:on
assertFalse("No symbols found for " + className, symbols.isEmpty());
return symbols;
}
use of org.eclipse.lsp4j.SymbolInformation in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandlerTest method testDeprecated.
@Test
public void testDeprecated() throws Exception {
when(preferenceManager.getClientPreferences().isSymbolTagSupported()).thenReturn(true);
String className = "org.sample.Bar";
List<? extends SymbolInformation> symbols = getSymbols(className);
SymbolInformation deprecated = symbols.stream().filter(symbol -> symbol.getName().equals("MyInterface")).findFirst().orElse(null);
assertNotNull(deprecated);
assertEquals(SymbolKind.Interface, deprecated.getKind());
assertNotNull(deprecated.getTags());
assertTrue("Should have deprecated tag", deprecated.getTags().contains(SymbolTag.Deprecated));
SymbolInformation notDeprecated = symbols.stream().filter(symbol -> symbol.getName().equals("MyClass")).findFirst().orElse(null);
assertNotNull(notDeprecated);
assertEquals(SymbolKind.Class, notDeprecated.getKind());
if (notDeprecated.getTags() != null) {
assertFalse("Should not have deprecated tag", deprecated.getTags().contains(SymbolTag.Deprecated));
}
}
Aggregations