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