use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateAccessorsActionTest method testGenerateAccessorsForRecordEnabled.
@Test
public void testGenerateAccessorsForRecordEnabled() throws Exception {
importProjects("eclipse/java16");
IProject project = WorkspaceHelper.getProject("java16");
IJavaProject javaProject = JavaCore.create(project);
IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath().append("src").append("main").append("java"));
assertNotNull(root);
IPackageFragment packageFragment = root.createPackageFragment("p", true, null);
// @formatter:off
ICompilationUnit unit = packageFragment.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "public record A(String name, int age) {\r\n" + "}", true, null);
// @formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "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.assertNotNull(generateAccessorsAction);
Command generateAccessorsCommand = CodeActionHandlerTest.getCommand(generateAccessorsAction);
Assert.assertNotNull(generateAccessorsCommand);
Assert.assertEquals(SourceAssistProcessor.COMMAND_ID_ACTION_GENERATEACCESSORSPROMPT, generateAccessorsCommand.getCommand());
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateAccessorsActionTest method testAdvancedGenerateAccessorsEnabled.
@Test
public void testAdvancedGenerateAccessorsEnabled() throws JavaModelException {
// @formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "public class A {\r\n" + " static String name;\r\n" + " String address;\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(SourceAssistProcessor.COMMAND_ID_ACTION_GENERATEACCESSORSPROMPT, generateAccessorsCommand.getCommand());
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateConstructorsActionTest method testGenerateConstructorsQuickAssist.
@Test
public void testGenerateConstructorsQuickAssist() 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
// test for field declaration
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "String name");
List<Either<Command, CodeAction>> codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
Either<Command, CodeAction> constructorAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.QUICK_ASSIST);
Assert.assertNotNull(constructorAction);
Command constructorCommand = CodeActionHandlerTest.getCommand(constructorAction);
Assert.assertNotNull(constructorCommand);
Assert.assertEquals(SourceAssistProcessor.COMMAND_ID_ACTION_GENERATECONSTRUCTORSPROMPT, constructorCommand.getCommand());
// test for type declaration
params = CodeActionUtil.constructCodeActionParams(unit, "A");
codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
List<Either<Command, CodeAction>> quickAssistActions = CodeActionHandlerTest.findActions(codeActions, JavaCodeActionKind.QUICK_ASSIST);
Assert.assertTrue(CodeActionHandlerTest.commandExists(quickAssistActions, SourceAssistProcessor.COMMAND_ID_ACTION_GENERATECONSTRUCTORSPROMPT));
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateConstructorsActionTest method testGenerateConstructorsEnabled.
@Test
public void testGenerateConstructorsEnabled() 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> constructorAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.SOURCE_GENERATE_CONSTRUCTORS);
Assert.assertNotNull(constructorAction);
Command constructorCommand = CodeActionHandlerTest.getCommand(constructorAction);
Assert.assertNotNull(constructorCommand);
Assert.assertEquals(SourceAssistProcessor.COMMAND_ID_ACTION_GENERATECONSTRUCTORSPROMPT, constructorCommand.getCommand());
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class GenerateToStringActionTest method testGenerateToStringEnabled_emptyFields.
@Test
public void testGenerateToStringEnabled_emptyFields() throws JavaModelException {
// @formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "public class A {\r\n" + " private static 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> toStringAction = CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.SOURCE_GENERATE_TO_STRING);
Assert.assertNotNull(toStringAction);
Command toStringCommand = CodeActionHandlerTest.getCommand(toStringAction);
Assert.assertNotNull(toStringCommand);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, toStringCommand.getCommand());
}
Aggregations