use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.
the class IntroduceParameterRefactorTest method testIntroduceParameter.
@Test
public void testIntroduceParameter() throws Exception {
setIgnoredCommands("Assign statement to new field", ActionMessages.GenerateConstructorsAction_ellipsisLabel, ActionMessages.GenerateConstructorsAction_label);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
// @formatter:off
buf.append("package test1;\n" + "public class E {\n" + " public void foo(){\r\n" + " greeting();\r\n" + " }\r\n" + "\r\n" + " private void greeting() {\r\n" + " System.out.println(\"Hello World\");\r\n" + " }\n" + "}\n");
// @formatter:on
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range range = new Range(new Position(7, 30), new Position(7, 30));
testIntroduceParameterCommand(cu, range);
when(clientPreferences.isAdvancedIntroduceParameterRefactoringSupported()).thenReturn(false);
testIntroduceParameterAction(cu, range);
}
use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.
the class ImplementationsHandlerTest method testInterfaceImplementation.
@Test
public void testInterfaceImplementation() {
URI uri = project.getFile("src/org/sample/IFoo.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);
TextDocumentPositionParams param = new TextDocumentPositionParams();
// Position over IFoo
param.setPosition(new Position(2, 20));
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<? extends Location> implementations = handler.findImplementations(param, monitor);
assertNotNull("findImplementations should not return null", implementations);
assertEquals(2, implementations.size());
Location foo2 = implementations.get(0);
assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java"));
assertEquals(JDTUtils.newLineRange(2, 13, 17), foo2.getRange());
Location foo3 = implementations.get(1);
assertTrue("Unexpected implementation : " + foo3.getUri(), foo3.getUri().contains("org/sample/Foo3.java"));
assertEquals(JDTUtils.newLineRange(5, 13, 17), foo3.getRange());
}
use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.
the class ImplementationsHandlerTest method testMethodSuperInvocationImplementation.
@Test
public void testMethodSuperInvocationImplementation() {
URI uri = project.getFile("src/org/sample/FooChild.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);
TextDocumentPositionParams param = new TextDocumentPositionParams();
// Position over super.someMethod
param.setPosition(new Position(5, 14));
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<? extends Location> implementations = handler.findImplementations(param, monitor);
assertNotNull("findImplementations should not return null", implementations);
assertEquals(implementations.toString(), 1, implementations.size());
Location foo = implementations.get(0);
assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/Foo.java"));
// check range points to someMethod() position
assertEquals(new Position(8, 13), foo.getRange().getStart());
assertEquals(new Position(8, 23), foo.getRange().getEnd());
}
use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.
the class ImplementationsHandlerTest method testMethodImplementation.
@Test
public void testMethodImplementation() {
URI uri = project.getFile("src/org/sample/IFoo.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);
TextDocumentPositionParams param = new TextDocumentPositionParams();
// Position over IFoo#someMethod
param.setPosition(new Position(4, 14));
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<? extends Location> implementations = handler.findImplementations(param, monitor);
assertNotNull("findImplementations should not return null", implementations);
assertEquals(implementations.toString(), 1, implementations.size());
Location foo2 = implementations.get(0);
assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java"));
// check range points to someMethod() position
assertEquals(new Position(4, 16), foo2.getRange().getStart());
assertEquals(new Position(4, 26), foo2.getRange().getEnd());
}
use of org.eclipse.lsp4j.Position in project eclipse.jdt.ls by eclipse.
the class ImplementationsHandlerTest method testUnimplementedClassImplementation_includeDefinition.
@Test
public void testUnimplementedClassImplementation_includeDefinition() {
URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);
TextDocumentPositionParams param = new TextDocumentPositionParams();
// Position over AbstractFoo.
param.setPosition(new Position(14, 13));
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<? extends Location> implementations = handler.findImplementations(param, monitor);
assertNotNull("findImplementations should not return null", implementations);
assertEquals(implementations.toString(), 1, implementations.size());
Location foo = implementations.get(0);
assertTrue("Unexpected implementation : " + foo.getUri(), foo.getUri().contains("org/sample/AbstractFoo.java"));
// check range points to AbstractFoo class declaration position
assertEquals(new Position(2, 22), foo.getRange().getStart());
assertEquals(new Position(2, 33), foo.getRange().getEnd());
}
Aggregations