Search in sources :

Example 1 with PrepareRenameResult

use of org.eclipse.lsp4j.PrepareRenameResult 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 2 with PrepareRenameResult

use of org.eclipse.lsp4j.PrepareRenameResult 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 3 with PrepareRenameResult

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

the class PrepareRenameHandlerTest method testRenameTypeWithResourceChanges.

@Test
public void testRenameTypeWithResourceChanges() throws JavaModelException, BadLocationException {
    when(clientPreferences.isResourceOperationSupported()).thenReturn(true);
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    String[] codes = { "package test1;\n", "public class E|* {\n", "   public E() {\n", "   }\n", "   public int bar() {\n", "   }\n", "   public int foo() {\n", "		this.bar();\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 4 with PrepareRenameResult

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

the class PrepareRenameHandlerTest method testRenameParameter.

@Test
public void testRenameParameter() throws JavaModelException, BadLocationException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    String[] codes = { "package test1;\n", "public class E {\n", "   public int foo(String str) {\n", "  		str|*.length();\n", "   }\n", "   public int bar(String str) {\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 5 with PrepareRenameResult

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

the class PrepareRenameHandlerTest method testRenameField.

@Test
public void testRenameField() throws JavaModelException, BadLocationException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    String[] codes = { "package test1;\n", "public class E {\n", "	private int myValue = 2;\n", "   public void bar() {\n", "		myValue|* = 3;\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)

Aggregations

PrepareRenameResult (org.eclipse.lsp4j.PrepareRenameResult)16 Range (org.eclipse.lsp4j.Range)15 Position (org.eclipse.lsp4j.Position)14 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)9 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)9 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)9 Test (org.junit.Test)9 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)4 RenameParams (org.eclipse.lsp4j.RenameParams)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.jupiter.api.Test)2 JsonArray (com.google.gson.JsonArray)1 AstNode (com.sonar.sslr.api.AstNode)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1