Search in sources :

Example 96 with Position

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

the class NavigateToTypeDefinitionHandlerTest method testClass.

private void testClass(String className, int line, int column) throws JavaModelException {
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.typeDefinition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals("No definition found for " + className, 1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertTrue(definitions.get(0).getRange().getStart().getLine() >= 0);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 97 with Position

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

the class PrepareRenameHandlerTest method testRenameJavadoc.

@Test
public void testRenameJavadoc() throws JavaModelException, BadLocationException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    String[] codes = { "package test1;\n", "public class E {\n", "	/**\n", "	 *@param i int\n", "	 */\n", "   public int foo(int i|*) {\n", "		E e = new E();\n", "		e.foo();\n", "   }\n", "}\n" };
    StringBuilder builder = new StringBuilder();
    Position pos = mergeCode(builder, codes);
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);
    Either<Range, PrepareRenameResult> result = prepareRename(cu, pos, "i2");
    assertNotNull(result.getLeft());
    assertTrue(result.getLeft().getStart().getLine() > 0);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Position(org.eclipse.lsp4j.Position) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) Range(org.eclipse.lsp4j.Range) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 98 with Position

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

the class PrepareRenameHandlerTest method testRenameLocalVariable.

@Test
public void testRenameLocalVariable() throws JavaModelException, BadLocationException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    String[] codes = { "package test1;\n", "public class E {\n", "   public int bar() {\n", "		String str = new String();\n", "   	str.length();\n", "   }\n", "   public int foo() {\n", "		String str = new String();\n", "   	str|*.length()\n", "   }\n", "}\n" };
    StringBuilder builder = new StringBuilder();
    Position pos = mergeCode(builder, codes);
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);
    Either<Range, PrepareRenameResult> result = prepareRename(cu, pos, "newname");
    assertNotNull(result.getLeft());
    assertTrue(result.getLeft().getStart().getLine() > 0);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Position(org.eclipse.lsp4j.Position) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) Range(org.eclipse.lsp4j.Range) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 99 with Position

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

the class PrepareRenameHandlerTest method testRenamePackage.

@Test(expected = ResponseErrorException.class)
public void testRenamePackage() throws JavaModelException, BadLocationException {
    when(clientPreferences.isResourceOperationSupported()).thenReturn(true);
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    IPackageFragment pack2 = sourceFolder.createPackageFragment("parent.test2", false, null);
    String[] codes1 = { "package test1;\n", "import parent.test2.B;\n", "public class A {\n", "   public void foo(){\n", "		B b = new B();\n", "		b.foo();\n", "	}\n", "}\n" };
    String[] codes2 = { "package parent.test2|*;\n", "public class B {\n", "	public B() {}\n", "   public void foo() {}\n", "}\n" };
    StringBuilder builderA = new StringBuilder();
    mergeCode(builderA, codes1);
    pack1.createCompilationUnit("A.java", builderA.toString(), false, null);
    StringBuilder builderB = new StringBuilder();
    Position pos = mergeCode(builderB, codes2);
    ICompilationUnit cuB = pack2.createCompilationUnit("B.java", builderB.toString(), false, null);
    prepareRename(cuB, pos, "parent.newpackage");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Position(org.eclipse.lsp4j.Position) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 100 with Position

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

the class PrepareRenameHandlerTest method mergeCode.

private Position mergeCode(StringBuilder builder, String[] codes) {
    Position pos = null;
    for (int i = 0; i < codes.length; i++) {
        int ind = codes[i].indexOf("|*");
        if (ind > 0) {
            pos = new Position(i, ind);
            codes[i] = codes[i].replace("|*", "");
        }
        builder.append(codes[i]);
    }
    return pos;
}
Also used : Position(org.eclipse.lsp4j.Position)

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