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);
}
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);
}
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);
}
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");
}
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;
}
Aggregations