Search in sources :

Example 56 with Position

use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.

the class CallHierarchyHandler method callHierarchyOutgoingCalls.

public List<CallHierarchyOutgoingCall> callHierarchyOutgoingCalls(CallHierarchyOutgoingCallsParams params, IProgressMonitor monitor) {
    Assert.isNotNull(params, "params");
    CallHierarchyItem item = params.getItem();
    Assert.isNotNull(item, "call item");
    Position position = item.getRange().getStart();
    int line = position.getLine();
    int character = position.getCharacter();
    try {
        return getOutgoingCallItemsAt(item.getUri(), line, character, monitor);
    } catch (JavaModelException e) {
        JavaLanguageServerPlugin.log(e);
    } catch (OperationCanceledException e) {
    // do nothing
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Position(org.eclipse.lsp4j.Position) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem)

Example 57 with Position

use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.

the class TypeHierarchyCommandTest method testSubTypeHierarchy.

@Test
public void testSubTypeHierarchy() throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    TypeHierarchyParams params = new TypeHierarchyParams();
    String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
    Position position = new Position(2, 43);
    params.setTextDocument(identifier);
    params.setResolve(2);
    params.setDirection(TypeHierarchyDirection.Children);
    params.setPosition(position);
    TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
    assertNotNull(item);
    assertEquals(item.getName(), "Builder");
    assertNull(item.getParents());
    assertEquals(item.getChildren().size(), 9);
    for (TypeHierarchyItem child : item.getChildren()) {
        List<TypeHierarchyItem> subChild = child.getChildren();
        assertNotNull(subChild);
        if (subChild.size() == 1) {
            assertEquals(subChild.get(0).getName(), "ReflectionToStringBuilder");
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 58 with Position

use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.

the class JSONUtilityTest method testJsonElementToObject.

@Test
public void testJsonElementToObject() {
    Gson gson = new Gson();
    Position position = new Position(5, 5);
    JsonElement element = gson.toJsonTree(position);
    Position position2 = JSONUtility.toModel(element, Position.class);
    assertEquals(position, position2);
}
Also used : Position(org.eclipse.lsp4j.Position) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 59 with Position

use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.

the class JSONUtilityTest method testObjectToObject.

@Test
public void testObjectToObject() {
    Position position = new Position(5, 5);
    Position position2 = JSONUtility.toModel(position, Position.class);
    assertSame(position, position2);
}
Also used : Position(org.eclipse.lsp4j.Position) Test(org.junit.Test)

Example 60 with Position

use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.

the class AssignToVariableRefactorTest method testAssignStatementToField.

@Test
public void testAssignStatementToField() throws Exception {
    setIgnoredCommands("Assign statement to new local variable", ActionMessages.GenerateConstructorsAction_ellipsisLabel, ActionMessages.GenerateConstructorsAction_label);
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public static void main(String[] args) {\n");
    buf.append("        E test = new E();\n");
    buf.append("        test.foo();\n");
    buf.append("    }\n");
    buf.append("    public int foo() {\n");
    buf.append("        return 1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    Range range = new Range(new Position(4, 10), new Position(4, 10));
    testAssignField(cu, range);
    range = new Range(new Position(4, 15), new Position(4, 15));
    testAssignField(cu, range);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Aggregations

Position (org.eclipse.lsp4j.Position)240 Test (org.junit.Test)149 Range (org.eclipse.lsp4j.Range)103 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)95 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)73 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)50 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)36 Location (org.eclipse.lsp4j.Location)34 List (java.util.List)29 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)29 URI (java.net.URI)27 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)23 ArrayList (java.util.ArrayList)21 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)18 TextEdit (org.eclipse.lsp4j.TextEdit)15 CompletionList (org.eclipse.lsp4j.CompletionList)14 Document (org.eclipse.xtext.ide.server.Document)14 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)13 Command (org.eclipse.lsp4j.Command)12