Search in sources :

Example 46 with SymbolInformation

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());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) URI(java.net.URI) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Test(org.junit.Test)

Example 47 with SymbolInformation

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));
        }
    }
}
Also used : DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 48 with SymbolInformation

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);
}
Also used : SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 49 with SymbolInformation

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;
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) SymbolInformation(org.eclipse.lsp4j.SymbolInformation)

Example 50 with SymbolInformation

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));
    }
}
Also used : SymbolInformation(org.eclipse.lsp4j.SymbolInformation) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

SymbolInformation (org.eclipse.lsp4j.SymbolInformation)54 Location (org.eclipse.lsp4j.Location)24 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 List (java.util.List)10 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)10 SymbolKind (org.eclipse.lsp4j.SymbolKind)9 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)8 ImmutableList (com.google.common.collect.ImmutableList)7 EnhancedSymbolInformation (org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation)7 URI (java.net.URI)6 Path (java.nio.file.Path)6 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)6 Range (org.eclipse.lsp4j.Range)5 Paths (java.nio.file.Paths)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Optional (java.util.Optional)4