use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class IntroduceParameterRefactorTest method testIntroduceParameterAction.
private void testIntroduceParameterAction(ICompilationUnit cu, Range range) throws JavaModelException {
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, range);
assertEquals(1, codeActions.size());
Either<Command, CodeAction> codeAction = codeActions.get(0);
CodeAction action = codeAction.getRight();
assertEquals(JavaCodeActionKind.REFACTOR_INTRODUCE_PARAMETER, action.getKind());
assertEquals("Introduce Parameter...", action.getTitle());
Command c = action.getCommand();
assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
assertEquals(1, c.getArguments().size());
WorkspaceEdit workspaceEdit = (WorkspaceEdit) c.getArguments().get(0);
Map<String, List<TextEdit>> changes = workspaceEdit.getChanges();
List<TextEdit> textEdits = changes.values().iterator().next();
assertEquals(1, textEdits.size());
TextEdit textEdit = textEdits.get(0);
assertEquals("\"Hello World\");\r\n }\r\n\r\n private void greeting(String string) {\r\n System.out.println(string", textEdit.getNewText());
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class IntroduceParameterRefactorTest method testIntroduceParameterCommand.
private void testIntroduceParameterCommand(ICompilationUnit cu, Range range) throws JavaModelException {
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, range);
assertEquals(1, codeActions.size());
Either<Command, CodeAction> codeAction = codeActions.get(0);
CodeAction action = codeAction.getRight();
assertEquals(JavaCodeActionKind.REFACTOR_INTRODUCE_PARAMETER, action.getKind());
assertEquals("Introduce Parameter...", action.getTitle());
Command c = action.getCommand();
assertEquals(RefactorProposalUtility.APPLY_REFACTORING_COMMAND_ID, c.getCommand());
assertNotNull(c.getArguments());
assertEquals(RefactorProposalUtility.INTRODUCE_PARAMETER_COMMAND, c.getArguments().get(0));
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class ReorgQuickFixTest method testWrongPackageStatementInEnum.
@Test
public void testWrongPackageStatementInEnum() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public enum E {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu);
Either<Command, CodeAction> codeAction = findAction(codeActions, "Change package declaration to 'test1'");
assertNotNull(codeAction);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public enum E {\n");
buf.append("}\n");
assertEquals(buf.toString(), evaluateCodeActionCommand(codeAction));
codeAction = findAction(codeActions, "Move 'E.java' to package 'test2'");
assertNotNull(codeAction);
assertRenameFileOperation(codeAction, ResourceUtils.fixURI(cu.getResource().getRawLocationURI()).replace("test1", "test2"));
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateAccessorsActionTest method testGenerateAccessorsDisabled_emptyFields.
@Test
public void testGenerateAccessorsDisabled_emptyFields() throws JavaModelException {
// @formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "public class A {\r\n" + "}", true, null);
// @formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "class A");
List<Either<Command, CodeAction>> codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> generateAccessorsAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.SOURCE_GENERATE_ACCESSORS);
Assert.assertNull(generateAccessorsAction);
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateAccessorsActionTest method testGenerateAccessorsEnabled.
@Test
public void testGenerateAccessorsEnabled() throws JavaModelException {
// @formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "public class A {\r\n" + " String name;\r\n" + "}", true, null);
// @formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "String name");
List<Either<Command, CodeAction>> codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> generateAccessorsAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.SOURCE_GENERATE_ACCESSORS);
Assert.assertNotNull(generateAccessorsAction);
Command generateAccessorsCommand = CodeActionHandlerTest.getCommand(generateAccessorsAction);
Assert.assertNotNull(generateAccessorsCommand);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, generateAccessorsCommand.getCommand());
}
Aggregations