use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class CodeLensHandlerTest method testResolveImplementationsCodeLens.
@SuppressWarnings("unchecked")
@Test
public void testResolveImplementationsCodeLens() {
String source = "src/java/IFoo.java";
String payload = createCodeLensImplementationsRequest(source, 5, 17, 21);
CodeLens lens = getParams(payload);
Range range = lens.getRange();
assertRange(5, 17, 21, range);
CodeLens result = handler.resolve(lens, monitor);
assertNotNull(result);
// Check if command found
Command command = result.getCommand();
assertNotNull(command);
assertEquals("2 implementations", command.getTitle());
assertEquals("java.show.implementations", command.getCommand());
// Check codelens args
List<Object> args = command.getArguments();
assertEquals(3, args.size());
// Check we point to the Bar class
String sourceUri = args.get(0).toString();
assertTrue(sourceUri.endsWith("IFoo.java"));
// CodeLens position
Position p = (Position) args.get(1);
assertEquals(5, p.getLine());
assertEquals(17, p.getCharacter());
// Reference location
List<Location> locations = (List<Location>) args.get(2);
assertEquals(2, locations.size());
Location loc = locations.get(0);
assertTrue(loc.getUri().endsWith("src/java/Foo2.java"));
assertRange(5, 13, 17, loc.getRange());
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class AdvancedExtractTest method testMoveInstanceMethod.
@Test
public void testMoveInstanceMethod() throws Exception {
when(preferenceManager.getClientPreferences().isMoveRefactoringSupported()).thenReturn(true);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
// @formatter:off
pack1.createCompilationUnit("Second.java", "package test1;\n" + "\n" + "public class Second {\n" + " public void bar() {\n" + " }\n" + "}", false, null);
// @formatter:on
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" Second s;\n");
buf.append(" public void print() {\n");
buf.append(" /*[*//*]*/s.bar();\n");
buf.append(" }\n");
buf.append("}");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getRange(cu, null);
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, selection);
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> moveAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.REFACTOR_MOVE);
Assert.assertNotNull(moveAction);
Command moveCommand = CodeActionHandlerTest.getCommand(moveAction);
Assert.assertNotNull(moveCommand);
Assert.assertEquals(RefactorProposalUtility.APPLY_REFACTORING_COMMAND_ID, moveCommand.getCommand());
Assert.assertNotNull(moveCommand.getArguments());
Assert.assertEquals(3, moveCommand.getArguments().size());
Assert.assertEquals(RefactorProposalUtility.MOVE_INSTANCE_METHOD_COMMAND, moveCommand.getArguments().get(0));
Assert.assertTrue(moveCommand.getArguments().get(2) instanceof RefactorProposalUtility.MoveMemberInfo);
Assert.assertEquals("print()", ((RefactorProposalUtility.MoveMemberInfo) moveCommand.getArguments().get(2)).displayName);
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class AdvancedExtractTest method testExtractMethod.
@Test
public void testExtractMethod() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public int foo(boolean b1, boolean b2) {\n");
buf.append(" int n = 0;\n");
buf.append(" int i = 0;\n");
buf.append(" /*[*/\n");
buf.append(" if (b1)\n");
buf.append(" i = 1;\n");
buf.append(" if (b2)\n");
buf.append(" n = n + i;\n");
buf.append(" /*]*/\n");
buf.append(" return n;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getRange(cu, null);
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, selection);
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> extractMethodAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.REFACTOR_EXTRACT_METHOD);
Assert.assertNotNull(extractMethodAction);
Command extractMethodCommand = CodeActionHandlerTest.getCommand(extractMethodAction);
Assert.assertNotNull(extractMethodCommand);
Assert.assertEquals(RefactorProposalUtility.APPLY_REFACTORING_COMMAND_ID, extractMethodCommand.getCommand());
Assert.assertNotNull(extractMethodCommand.getArguments());
Assert.assertEquals(2, extractMethodCommand.getArguments().size());
Assert.assertEquals(RefactorProposalUtility.EXTRACT_METHOD_COMMAND, extractMethodCommand.getArguments().get(0));
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class AdvancedExtractTest method testMoveInnerType.
@Test
public void testMoveInnerType() throws Exception {
when(preferenceManager.getClientPreferences().isMoveRefactoringSupported()).thenReturn(true);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" class Inner {\n");
buf.append(" /*[*//*]*/\n");
buf.append(" }\n");
buf.append("}");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getRange(cu, null);
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, selection);
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> moveAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.REFACTOR_MOVE);
Assert.assertNotNull(moveAction);
Command moveCommand = CodeActionHandlerTest.getCommand(moveAction);
Assert.assertNotNull(moveCommand);
Assert.assertEquals(RefactorProposalUtility.APPLY_REFACTORING_COMMAND_ID, moveCommand.getCommand());
Assert.assertNotNull(moveCommand.getArguments());
Assert.assertEquals(3, moveCommand.getArguments().size());
Assert.assertEquals(RefactorProposalUtility.MOVE_TYPE_COMMAND, moveCommand.getArguments().get(0));
Assert.assertTrue(moveCommand.getArguments().get(2) instanceof RefactorProposalUtility.MoveTypeInfo);
Assert.assertEquals(fJProject1.getProject().getName(), ((RefactorProposalUtility.MoveTypeInfo) moveCommand.getArguments().get(2)).projectName);
Assert.assertEquals("Inner", ((RefactorProposalUtility.MoveTypeInfo) moveCommand.getArguments().get(2)).displayName);
Assert.assertEquals("test1.E", ((RefactorProposalUtility.MoveTypeInfo) moveCommand.getArguments().get(2)).enclosingTypeName);
Assert.assertTrue(((RefactorProposalUtility.MoveTypeInfo) moveCommand.getArguments().get(2)).isMoveAvaiable());
}
use of org.eclipse.lsp4j.Command in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method createMXMLNamespaceCommand.
private Command createMXMLNamespaceCommand(IDefinition definition, String prefix, String uri) {
Command xmlnsCommand = new Command();
xmlnsCommand.setTitle("Add Namespace " + uri);
xmlnsCommand.setCommand(COMMAND_XMLNS);
xmlnsCommand.setArguments(Arrays.asList(prefix, uri, namespaceStartIndex, namespaceEndIndex));
return xmlnsCommand;
}
Aggregations