Search in sources :

Example 81 with Position

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

the class NavigateToDefinitionHandlerTest method testMethodInAnonymousClass.

// https://github.com/eclipse/eclipse.jdt.ls/issues/1813
@Test
public void testMethodInAnonymousClass() throws Exception {
    String className = "org.sample.App";
    int line = 12;
    int column = 28;
    importProjects("eclipse/hello");
    IProject hello = WorkspaceHelper.getProject("hello");
    String uri = ClassFileUtil.getURI(hello, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals("No definition found for " + className, 1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertEquals(3, definitions.get(0).getRange().getStart().getLine());
    assertEquals(18, definitions.get(0).getRange().getStart().getCharacter());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 82 with Position

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

the class NavigateToDefinitionHandlerTest method testSourceVersion.

@Test
public void testSourceVersion() throws Exception {
    String className = "javax.tools.Tool";
    int line = 6;
    int column = 57;
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals("No definition found for " + className, 1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertEquals(3, definitions.get(0).getRange().getStart().getLine());
    assertEquals(12, definitions.get(0).getRange().getStart().getCharacter());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 83 with Position

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

the class TypeHierarchyCommand method typeHierarchy.

public TypeHierarchyItem typeHierarchy(TypeHierarchyParams params, IProgressMonitor monitor) {
    if (params == null) {
        return null;
    }
    TextDocumentIdentifier textDocument = params.getTextDocument();
    if (textDocument == null) {
        return null;
    }
    Position position = params.getPosition();
    String uri = textDocument.getUri();
    TypeHierarchyDirection direction = params.getDirection();
    int resolve = params.getResolve();
    return getTypeHierarchy(uri, position, direction, resolve, null, monitor);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyDirection(org.eclipse.lsp4j.TypeHierarchyDirection)

Example 84 with Position

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

the class MissingEnumQuickFixTest method testMissingEnumConstant.

@Test
public void testMissingEnumConstant() throws Exception {
    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 enum Numbers { One, Two};\n");
    buf.append("    public void testing() {\n");
    buf.append("        Numbers n = Numbers.One;\n");
    buf.append("        switch (n) {\n");
    buf.append("        case Two:\n");
    buf.append("            return;\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    Range range = new Range(new Position(5, 16), new Position(5, 17));
    setIgnoredCommands(ActionMessages.GenerateConstructorsAction_ellipsisLabel, ActionMessages.GenerateConstructorsAction_label);
    List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, range);
    assertEquals(2, codeActions.size());
    Either<Command, CodeAction> codeAction = codeActions.get(0);
    CodeAction action = codeAction.getRight();
    assertEquals(CodeActionKind.QuickFix, action.getKind());
    assertEquals("Add 'default' case", action.getTitle());
    TextEdit edit = getTextEdit(codeAction);
    assertEquals("\n        default:\n            break;", edit.getNewText());
    codeAction = codeActions.get(1);
    action = codeAction.getRight();
    assertEquals(CodeActionKind.QuickFix, action.getKind());
    assertEquals("Add missing case statements", action.getTitle());
    edit = getTextEdit(codeAction);
    assertEquals("\n        case One:\n            break;\n        default:\n            break;", edit.getNewText());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Position(org.eclipse.lsp4j.Position) Command(org.eclipse.lsp4j.Command) TextEdit(org.eclipse.lsp4j.TextEdit) CodeAction(org.eclipse.lsp4j.CodeAction) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 85 with Position

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

the class RedundantInterfaceQuickFixTest method testIgnoreRedundantSuperinterface.

@Test
public void testIgnoreRedundantSuperinterface() throws Exception {
    Map<String, String> testProjectOptions = fJProject.getOptions(false);
    testProjectOptions.put(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE, JavaCore.IGNORE);
    fJProject.setOptions(testProjectOptions);
    IPackageFragment pack = fSourceFolder.createPackageFragment("test", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test;\n");
    buf.append("public class RedundantInterface implements Int1, Int2 {}\n");
    buf.append("interface Int1 {}\n");
    buf.append("interface Int2 extends Int1 {}\n");
    ICompilationUnit cu = pack.createCompilationUnit("RedundantInterface.java", buf.toString(), true, null);
    Range selection = new Range(new Position(1, 45), new Position(1, 45));
    setIgnoredCommands(ActionMessages.GenerateConstructorsAction_ellipsisLabel, ActionMessages.GenerateConstructorsAction_label);
    assertCodeActionNotExists(cu, selection, CorrectionMessages.LocalCorrectionsSubProcessor_remove_redundant_superinterface);
}
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