From ad44287acc85b7a305e338c23c5a0656d615126d Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Wed, 5 Jul 2023 16:27:05 +0200 Subject: [PATCH] chore: complete port of 'Add an id to track the type of each CodeAction' Signed-off-by: Fred Bricon --- .../java/codeaction/CodeActionFactory.java | 116 ------------------ .../NoValueAssignedToPropertyQuickFix.java | 8 +- .../java/ImplementHealthCheckQuickFix.java | 5 +- ...cationScopedAnnotationMissingQuickFix.java | 4 +- .../MicroProfileGenerateOpenAPIOperation.java | 11 +- .../psi/core/MicroProfileForJavaAssert.java | 15 ++- ...MicroProfileConfigJavaDiagnosticsTest.java | 17 +-- ...MicroProfileHealthJavaDiagnosticsTest.java | 15 +-- ...icroProfileMetricsJavaDiagnosticsTest.java | 13 +- .../java/GenerateOpenAPIAnnotationsTest.java | 3 +- ...oProfileRestClientJavaDiagnosticsTest.java | 21 ++-- .../psi/quarkus/renarde/RenardeJaxRsTest.java | 8 +- 12 files changed, 54 insertions(+), 182 deletions(-) delete mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/CodeActionFactory.java diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/CodeActionFactory.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/CodeActionFactory.java deleted file mode 100644 index 44c9f6798..000000000 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/java/codeaction/CodeActionFactory.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2018 Red Hat Inc. and others. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v. 2.0 which is available at -* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -* which is available at https://www.apache.org/licenses/LICENSE-2.0. -* -* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -* -* Contributors: -* Red Hat Inc. - initial API and implementation -*******************************************************************************/ -package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.eclipse.lsp4j.CodeAction; -import org.eclipse.lsp4j.CodeActionKind; -import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.Position; -import org.eclipse.lsp4j.Range; -import org.eclipse.lsp4j.TextDocumentEdit; -import org.eclipse.lsp4j.TextDocumentItem; -import org.eclipse.lsp4j.TextEdit; -import org.eclipse.lsp4j.VersionedTextDocumentIdentifier; -import org.eclipse.lsp4j.WorkspaceEdit; -import org.eclipse.lsp4j.jsonrpc.messages.Either; - -/** - * Factory for simple {@link CodeAction} - * - */ -public class CodeActionFactory { - - /** - * Create a CodeAction to remove the content from the given range. - * - * @param title - * @param range - * @param document - * @param diagnostic - * @return - */ - public static CodeAction remove(String title, Range range, TextDocumentItem document, Diagnostic diagnostic) { - return replace(title, range, "", document, diagnostic); - } - - /** - * Create a CodeAction to insert a new content at the end of the given range. - * - * @param title - * @param range - * @param insertText - * @param document - * @param diagnostic - * @return - */ - public static CodeAction insert(String title, Position position, String insertText, TextDocumentItem document, - Diagnostic diagnostic) { - return insert(title, position, insertText, document, Arrays.asList(diagnostic)); - } - - /** - * Create a CodeAction to insert a new content at the end of the given range. - * - * @param title - * @param range - * @param insertText - * @param document - * @param diagnostics - * @return - */ - public static CodeAction insert(String title, Position position, String insertText, TextDocumentItem document, - List diagnostics) { - CodeAction insertContentAction = new CodeAction(title); - insertContentAction.setKind(CodeActionKind.QuickFix); - insertContentAction.setDiagnostics(diagnostics); - TextEdit edit = new TextEdit(new Range(position, position), insertText); - VersionedTextDocumentIdentifier versionedTextDocumentIdentifier = new VersionedTextDocumentIdentifier( - document.getUri(), document.getVersion()); - - TextDocumentEdit textDocumentEdit = new TextDocumentEdit(versionedTextDocumentIdentifier, - Collections.singletonList(edit)); - WorkspaceEdit workspaceEdit = new WorkspaceEdit(Collections.singletonList(Either.forLeft(textDocumentEdit))); - insertContentAction.setEdit(workspaceEdit); - workspaceEdit.setChanges(Collections.emptyMap()); - return insertContentAction; - } - - public static CodeAction replace(String title, Range range, String replaceText, TextDocumentItem document, - Diagnostic diagnostic) { - CodeAction replaceContentAction = new CodeAction(title); - replaceContentAction.setKind(CodeActionKind.QuickFix); - replaceContentAction.setDiagnostics(Arrays.asList(diagnostic)); - TextEdit edit = new TextEdit(range, replaceText); - VersionedTextDocumentIdentifier versionedTextDocumentIdentifier = new VersionedTextDocumentIdentifier( - document.getUri(), document.getVersion()); - - TextDocumentEdit textDocumentEdit = new TextDocumentEdit(versionedTextDocumentIdentifier, - Collections.singletonList(edit)); - WorkspaceEdit workspaceEdit = new WorkspaceEdit(Collections.singletonList(Either.forLeft(textDocumentEdit))); - replaceContentAction.setEdit(workspaceEdit); - workspaceEdit.setChanges(Collections.emptyMap()); - return replaceContentAction; - } - - public static boolean isDiagnosticCode(Either diagnosticCode, String code) { - if (diagnosticCode == null || diagnosticCode.isRight()) { - return false; - } - return code.equals(diagnosticCode.getLeft()); - } -} diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java index 4e2c14117..957ba8099 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/NoValueAssignedToPropertyQuickFix.java @@ -30,7 +30,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.CodeActionFactory; +import org.eclipse.lsp4mp.ls.commons.CodeActionFactory; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; @@ -52,6 +52,7 @@ import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; /** * QuickFix for fixing @@ -99,7 +100,7 @@ public List getCodeActions(JavaCodeActionContext context, // the properties file exists TextDocumentItem document = new TextDocumentItem(uri, "properties", 0, insertText); CodeAction codeAction = CodeActionFactory.insert( - getTitle(propertyName, configSource.getConfigFileName()), new Position(0, 0), insertText, + getTitle(propertyName, configSource.getConfigFileName()), MicroProfileCodeActionId.AssignValueToProperty, new Position(0, 0), insertText, document, diagnostic); codeActions.add(codeAction); } @@ -127,8 +128,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String insertText = propertyName + "=" + lineSeparator; TextDocumentEdit tde = insertTextEdit(new TextDocumentItem(uri, "properties", 0, insertText), insertText, new Position(0, 0)); - WorkspaceEdit workspaceEdit = new WorkspaceEdit(Collections.singletonList(Either.forLeft(tde))); - unresolved.setEdit(workspaceEdit); + unresolved.setEdit(new WorkspaceEdit(Collections.singletonList(Either.forLeft(tde)))); return unresolved; } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java index e56e650a9..1ace4f53a 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java @@ -28,7 +28,6 @@ import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; @@ -82,10 +81,8 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ImplementInterfaceProposal(context.getCompilationUnit(), parentType, context.getASTRoot(), MicroProfileHealthConstants.HEALTH_CHECK_INTERFACE, 0, context.getSource().getCompilationUnit()); - WorkspaceEdit workspaceEdit; try { - workspaceEdit = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(workspaceEdit); + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit to make the class implement @HealthCheck", e); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java index 73b409456..26bea8689 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java @@ -29,7 +29,6 @@ import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; @@ -100,8 +99,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, addAnnotation, context.getSource().getCompilationUnit(), REMOVE_ANNOTATION_NAMES); try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to create workspace edit to replace bean scope annotation", e); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java index bedb88a4b..c0745ef5f 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java @@ -28,17 +28,11 @@ import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** * Generate OpenAPI annotations by the "Source" kind code action. @@ -124,8 +118,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit()); try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); } catch (Exception e) { } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/MicroProfileForJavaAssert.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/MicroProfileForJavaAssert.java index 61dc9a804..22a48b51e 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/MicroProfileForJavaAssert.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/MicroProfileForJavaAssert.java @@ -14,12 +14,13 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManagerForJava; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaErrorCode; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import org.eclipse.lsp4j.*; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4mp.commons.*; +import org.eclipse.lsp4mp.commons.codeaction.CodeActionData; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Assert; import java.io.File; @@ -30,7 +31,7 @@ import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.assertTrue; /** * MicroProfile assert for java files for JUnit tests. * @@ -70,6 +71,11 @@ public static void assertCodeActions(List actual, CodeActi // we don't want to compare title, etc ca.setCommand(null); ca.setKind(null); + + if (ca.getEdit() != null && ca.getEdit().getChanges() != null) { + assertTrue(ca.getEdit().getChanges().isEmpty()); + ca.getEdit().setChanges(null); + } if (ca.getDiagnostics() != null) { ca.getDiagnostics().forEach(d -> { d.setSeverity(null); @@ -83,10 +89,11 @@ public static void assertCodeActions(List actual, CodeActi for (int i = 0; i < expected.length; i++) { assertEquals("Assert title [" + i + "]", expected[i].getTitle(), actual.get(i).getTitle()); assertEquals("Assert edit [" + i + "]", expected[i].getEdit(), actual.get(i).getEdit()); + assertEquals("Assert id [" + i + "]", ((CodeActionData)(expected[i].getData())).getCodeActionId(), ((CodeActionData)(actual.get(i).getData())).getCodeActionId()); } } - public static CodeAction ca(String uri, String title, Diagnostic d, TextEdit... te) { + public static CodeAction ca(String uri, String title, MicroProfileCodeActionId id, Diagnostic d, TextEdit... te) { CodeAction codeAction = new CodeAction(); codeAction.setTitle(title); codeAction.setDiagnostics(Arrays.asList(d)); @@ -95,8 +102,8 @@ public static CodeAction ca(String uri, String title, Diagnostic d, TextEdit... TextDocumentEdit textDocumentEdit = new TextDocumentEdit(versionedTextDocumentIdentifier, Arrays.asList(te)); WorkspaceEdit workspaceEdit = new WorkspaceEdit(Arrays.asList(Either.forLeft(textDocumentEdit))); - workspaceEdit.setChanges(Collections.emptyMap()); codeAction.setEdit(workspaceEdit); + codeAction.setData(new CodeActionData(id)); return codeAction; } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java index e3f0e1b1d..7522c02f9 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/java/MicroProfileConfigJavaDiagnosticsTest.java @@ -28,6 +28,7 @@ import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Test; import java.io.File; @@ -165,16 +166,16 @@ public void testCodeActionForUnassigned() throws Exception { MicroProfileJavaCodeActionParams codeActionParams1 = createCodeActionParams(javaFileUri, d1, false); assertJavaCodeAction(codeActionParams1, utils, // - ca(javaFileUri, "Insert 'defaultValue' attribute", d1, // + ca(javaFileUri, "Insert 'defaultValue' attribute", MicroProfileCodeActionId.ConfigPropertyInsertDefaultValue, d1, // te(0, 0, 18, 0, "package org.acme.config;\n\nimport org.eclipse.microprofile.config.inject.ConfigProperty;\n\nimport io.quarkus.arc.config.ConfigProperties;\n\npublic class UnassignedValue {\n\n @ConfigProperty(name = \"foo\", defaultValue = \"\")\n private String foo;\n\n @ConfigProperties(prefix = \"server\")\n private class Server {\n\n @ConfigProperty(name = \"url\")\n private String url;\n }\n}\n")), - ca(propertiesFileUri, "Insert 'foo' property in 'META-INF/microprofile-config.properties'", d1, // + ca(propertiesFileUri, "Insert 'foo' property in 'META-INF/microprofile-config.properties'", MicroProfileCodeActionId.AssignValueToProperty, d1, // te(0, 0, 0, 0, "foo=" + lineSeparator))); MicroProfileJavaCodeActionParams codeActionParams2 = createCodeActionParams(javaFileUri, d2, false); assertJavaCodeAction(codeActionParams2, utils, // - ca(javaFileUri, "Insert 'defaultValue' attribute", d2, // + ca(javaFileUri, "Insert 'defaultValue' attribute", MicroProfileCodeActionId.ConfigPropertyInsertDefaultValue, d2, // te(0, 0, 18, 0, "package org.acme.config;\n\nimport org.eclipse.microprofile.config.inject.ConfigProperty;\n\nimport io.quarkus.arc.config.ConfigProperties;\n\npublic class UnassignedValue {\n\n @ConfigProperty(name = \"foo\")\n private String foo;\n\n @ConfigProperties(prefix = \"server\")\n private class Server {\n\n @ConfigProperty(name = \"url\", defaultValue = \"\")\n private String url;\n }\n}\n")), - ca(propertiesFileUri, "Insert 'server.url' property in 'META-INF/microprofile-config.properties'", d2, // + ca(propertiesFileUri, "Insert 'server.url' property in 'META-INF/microprofile-config.properties'", MicroProfileCodeActionId.AssignValueToProperty, d2, // te(0, 0, 0, 0, "server.url=" + lineSeparator))); // Same code actions but with exclude @@ -193,18 +194,18 @@ public void testCodeActionForUnassigned() throws Exception { codeActionParams1_1.setCommandConfigurationUpdateSupported(true); assertJavaCodeAction(codeActionParams1_1, utils, // MicroProfileCodeActionFactory.createAddToUnassignedExcludedCodeAction("foo", d1_1), - ca(javaFileUri, "Insert 'defaultValue' attribute", d1_1, // + ca(javaFileUri, "Insert 'defaultValue' attribute", MicroProfileCodeActionId.ConfigPropertyInsertDefaultValue, d1_1, // te(0, 0, 18, 0, "package org.acme.config;\n\nimport org.eclipse.microprofile.config.inject.ConfigProperty;\n\nimport io.quarkus.arc.config.ConfigProperties;\n\npublic class UnassignedValue {\n\n @ConfigProperty(name = \"foo\", defaultValue = \"\")\n private String foo;\n\n @ConfigProperties(prefix = \"server\")\n private class Server {\n\n @ConfigProperty(name = \"url\")\n private String url;\n }\n}\n")), - ca(propertiesFileUri, "Insert 'foo' property in 'META-INF/microprofile-config.properties'", d1_1, // + ca(propertiesFileUri, "Insert 'foo' property in 'META-INF/microprofile-config.properties'", MicroProfileCodeActionId.AssignValueToProperty, d1_1, // te(0, 0, 0, 0, "foo=" + lineSeparator))); MicroProfileJavaCodeActionParams codeActionParams2_1 = createCodeActionParams(javaFileUri, d2_1); codeActionParams2_1.setCommandConfigurationUpdateSupported(true); assertJavaCodeAction(codeActionParams2_1, utils, // MicroProfileCodeActionFactory.createAddToUnassignedExcludedCodeAction("server.url", d2_1), - ca(javaFileUri, "Insert 'defaultValue' attribute", d2_1, // + ca(javaFileUri, "Insert 'defaultValue' attribute", MicroProfileCodeActionId.ConfigPropertyInsertDefaultValue, d2_1, // te(0, 0, 18, 0, "package org.acme.config;\n\nimport org.eclipse.microprofile.config.inject.ConfigProperty;\n\nimport io.quarkus.arc.config.ConfigProperties;\n\npublic class UnassignedValue {\n\n @ConfigProperty(name = \"foo\")\n private String foo;\n\n @ConfigProperties(prefix = \"server\")\n private class Server {\n\n @ConfigProperty(name = \"url\", defaultValue = \"\")\n private String url;\n }\n}\n")), - ca(propertiesFileUri, "Insert 'server.url' property in 'META-INF/microprofile-config.properties'", d2_1, // + ca(propertiesFileUri, "Insert 'server.url' property in 'META-INF/microprofile-config.properties'", MicroProfileCodeActionId.AssignValueToProperty, d2_1, // te(0, 0, 0, 0, "server.url=" + lineSeparator))); } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/health/java/MicroProfileHealthJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/health/java/MicroProfileHealthJavaDiagnosticsTest.java index 6661b86d7..f7bbc9c11 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/health/java/MicroProfileHealthJavaDiagnosticsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/health/java/MicroProfileHealthJavaDiagnosticsTest.java @@ -27,6 +27,7 @@ import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Test; import java.io.File; @@ -69,7 +70,7 @@ public void testImplementHealthCheck() throws Exception { codeActionParams.setResourceOperationSupported(true); codeActionParams.setCommandConfigurationUpdateSupported(true); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Let 'DontImplementHealthCheck' implement '@HealthCheck'", d, // + ca(uri, "Let 'DontImplementHealthCheck' implement '@HealthCheck'", MicroProfileCodeActionId.ImplementHealthCheck, d, // te(0, 0, 16, 0, "package org.acme.health;\n\nimport javax.enterprise.context.ApplicationScoped;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\nimport org.eclipse.microprofile.health.Liveness;\n\n@Liveness\n@ApplicationScoped\npublic class DontImplementHealthCheck implements HealthCheck {\n\n public HealthCheckResponse call() {\n return null;\n }\n\n} \n"))); } @@ -94,11 +95,11 @@ public void testHealthAnnotationMissing() throws Exception { MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Health", d, // + ca(uri, "Insert @Health", MicroProfileCodeActionId.InsertMissingHealthAnnotation, d, // te(0, 0, 13, 0, "package org.acme.health;\n\nimport org.eclipse.microprofile.health.Health;\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\n\n@Health\npublic class ImplementHealthCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return null;\n }\n\n}\n")), - ca(uri, "Insert @Liveness", d, // + ca(uri, "Insert @Liveness", MicroProfileCodeActionId.InsertMissingHealthAnnotation, d, // te(0, 0, 13, 0, "package org.acme.health;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\nimport org.eclipse.microprofile.health.Liveness;\n\n@Liveness\npublic class ImplementHealthCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return null;\n }\n\n}\n")), // - ca(uri, "Insert @Readiness", d, // + ca(uri, "Insert @Readiness", MicroProfileCodeActionId.InsertMissingHealthAnnotation, d, // te(0, 0, 13, 0, "package org.acme.health;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\nimport org.eclipse.microprofile.health.Readiness;\n\n@Readiness\npublic class ImplementHealthCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return null;\n }\n\n}\n")) // ); } @@ -135,11 +136,11 @@ public void testHealthAnnotationMissingv3() throws Exception { //String uri = javaFile.getLocation().toFile().toURI().toString(); MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Liveness", d, // + ca(uri, "Insert @Liveness", MicroProfileCodeActionId.InsertMissingHealthAnnotation, d, // te(0, 0, 13, 0, "package org.acme;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\nimport org.eclipse.microprofile.health.Liveness;\n\n@Liveness\npublic class MyLivenessCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return HealthCheckResponse.up(\"alive\");\n }\n\n}\n")), // - ca(uri, "Insert @Readiness", d, // + ca(uri, "Insert @Readiness", MicroProfileCodeActionId.InsertMissingHealthAnnotation, d, // te(0, 0, 13, 0, "package org.acme;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\nimport org.eclipse.microprofile.health.Readiness;\n\n@Readiness\npublic class MyLivenessCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return HealthCheckResponse.up(\"alive\");\n }\n\n}\n")), // - ca(uri, "Generate OpenAPI Annotations for 'MyLivenessCheck'", d, // + ca(uri, "Generate OpenAPI Annotations for 'MyLivenessCheck'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d, // te(0, 0, 13, 0, "package org.acme;\n\nimport org.eclipse.microprofile.health.HealthCheck;\nimport org.eclipse.microprofile.health.HealthCheckResponse;\n\npublic class MyLivenessCheck implements HealthCheck {\n\n @Override\n public HealthCheckResponse call() {\n return HealthCheckResponse.up(\"alive\");\n }\n\n}\n")) // ); } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/metrics/java/MicroProfileMetricsJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/metrics/java/MicroProfileMetricsJavaDiagnosticsTest.java index 06976fb06..1ca47f0c5 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/metrics/java/MicroProfileMetricsJavaDiagnosticsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/metrics/java/MicroProfileMetricsJavaDiagnosticsTest.java @@ -14,11 +14,6 @@ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.metrics.java; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtilCore; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtilCore; -import com.intellij.openapi.vfs.VirtualFile; -import com.redhat.devtools.intellij.MavenModuleImportingTestCase; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.LSP4MPMavenModuleImportingTestCase; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileMavenProjectName; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; @@ -31,9 +26,9 @@ import org.eclipse.lsp4mp.commons.DocumentFormat; import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Test; -import java.io.File; import java.util.Arrays; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileForJavaAssert.*; @@ -66,7 +61,7 @@ public void testApplicationScopedAnnotationMissing() throws Exception { MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(javaFileUri, d); // check for MicroProfile metrics quick fix code action associated with diagnostic warning assertJavaCodeAction(codeActionParams, utils, // - ca(javaFileUri, "Replace current scope with @ApplicationScoped", d, // + ca(javaFileUri, "Replace current scope with @ApplicationScoped", MicroProfileCodeActionId.InsertApplicationScopedAnnotation, d, // te(0, 0, 18, 0, "package org.acme;\n\nimport javax.enterprise.context.ApplicationScoped;\nimport javax.ws.rs.Path;\n\nimport org.eclipse.microprofile.metrics.MetricUnits;\nimport org.eclipse.microprofile.metrics.annotation.Gauge;\n\n@ApplicationScoped\n@Path(\"/\")\npublic class IncorrectScope {\n\n @Gauge(name = \"Return Int\", unit = MetricUnits.NONE, description = \"Test method for Gauge annotation\")\n public int returnInt() {\n return 2;\n }\n\n}\n"))); } @@ -97,9 +92,9 @@ public void testApplicationScopedAnnotationMissingJakarta() throws Exception { // check for MicroProfile metrics quick fix code action associated with // diagnostic warning assertJavaCodeAction(codeActionParams, utils, // - ca(javaFileUri, "Replace current scope with @ApplicationScoped", d1, // + ca(javaFileUri, "Replace current scope with @ApplicationScoped", MicroProfileCodeActionId.InsertApplicationScopedAnnotation, d1, // te(0, 0, 21, 1, "package com.demo.rest;\n\nimport jakarta.enterprise.context.ApplicationScoped;\nimport jakarta.ws.rs.Path;\nimport org.eclipse.microprofile.metrics.MetricUnits;\nimport org.eclipse.microprofile.metrics.annotation.Gauge;\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\nimport jakarta.inject.Inject;\n\n@ApplicationScoped\n@Path(\"/\")\npublic class IncorrectScopeJakarta {\n\n @Inject\n @RestClient\n public MyService service1;\n\n @Gauge(name = \"Return Int\", unit = MetricUnits.NONE, description = \"Test method for Gauge annotation\")\n public int returnInt() {\n return 2;\n }\n}")), - ca(javaFileUri, "Generate OpenAPI Annotations for 'IncorrectScopeJakarta'", d1, // No @Operation should be added + ca(javaFileUri, "Generate OpenAPI Annotations for 'IncorrectScopeJakarta'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d1, // No @Operation should be added te(0, 0, 21, 1, "package com.demo.rest;\n\nimport jakarta.ws.rs.Path;\nimport org.eclipse.microprofile.metrics.MetricUnits;\nimport org.eclipse.microprofile.metrics.annotation.Gauge;\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\nimport jakarta.inject.Inject;\nimport jakarta.enterprise.context.RequestScoped;\n\n@RequestScoped\n@Path(\"/\")\npublic class IncorrectScopeJakarta {\n\n @Inject\n @RestClient\n public MyService service1;\n\n @Gauge(name = \"Return Int\", unit = MetricUnits.NONE, description = \"Test method for Gauge annotation\")\n public int returnInt() {\n return 2;\n }\n}"))); } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/openapi/java/GenerateOpenAPIAnnotationsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/openapi/java/GenerateOpenAPIAnnotationsTest.java index 2dff40074..f9336f6bc 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/openapi/java/GenerateOpenAPIAnnotationsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/openapi/java/GenerateOpenAPIAnnotationsTest.java @@ -22,6 +22,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Test; import java.io.File; @@ -54,7 +55,7 @@ public void testGenerateOpenAPIAnnotationsAction() throws Exception { String newText = "package org.acme.openapi;\n\nimport org.eclipse.microprofile.openapi.annotations.Operation;\n\nimport java.util.Properties;\nimport javax.enterprise.context.RequestScoped;\nimport javax.ws.rs.GET;\nimport javax.ws.rs.Path;\nimport javax.ws.rs.core.Response;\n\n@RequestScoped\n@Path(\"/systems\")\npublic class NoOperationAnnotation {\n\n @Operation(summary = \"\", description = \"\")\n @GET\n public Response getMyInformation(String hostname) {\n return Response.ok(listContents()).build();\n }\n\n @Operation(summary = \"\", description = \"\")\n @GET\n public Response getPropertiesForMyHost() {\n return Response.ok().build();\n }\n\n private Properties listContents() {\n Properties info = new Properties();\n info.setProperty(\"Name\", \"APITest\");\n info.setProperty(\"Desc\", \"API Test\");\n return info;\n }\n\n}"; assertJavaCodeAction(codeActionParams, utils, - ca(uri, "Generate OpenAPI Annotations for 'NoOperationAnnotation'", d, + ca(uri, "Generate OpenAPI Annotations for 'NoOperationAnnotation'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d, te(0, 0, 29, 1, newText)) ); } diff --git a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/restclient/java/MicroProfileRestClientJavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/restclient/java/MicroProfileRestClientJavaDiagnosticsTest.java index b389d8634..21d175d89 100644 --- a/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/restclient/java/MicroProfileRestClientJavaDiagnosticsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/restclient/java/MicroProfileRestClientJavaDiagnosticsTest.java @@ -24,6 +24,7 @@ import org.eclipse.lsp4mp.commons.DocumentFormat; import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeActionParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; +import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import org.junit.Test; import java.io.File; @@ -88,17 +89,17 @@ public void testRestClientAnnotationMissingForFields() throws Exception { MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d3); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @RestClient", d3, // + ca(uri, "Insert @RestClient", MicroProfileCodeActionId.InsertRestClientAnnotation, d3, // te(0, 0, 22, 10, "package org.acme.restclient;\n\nimport javax.inject.Inject;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\npublic class Fields {\n\n public Country country;\n\n @Inject\n @RestClient\n public MyService service1, service2;\n\n @RestClient\n @Inject\n public CountriesService RestClientAnnotationMissing;\n\n @RestClient\n public CountriesService InjectAnnotationMissing;\n\n public CountriesService RestClientAndInjectAnnotationMissing;\n} \n "))); codeActionParams = createCodeActionParams(uri, d4); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Inject", d4, // + ca(uri, "Insert @Inject", MicroProfileCodeActionId.InsertInjectAnnotation, d4, // te(0, 0, 22, 10, "package org.acme.restclient;\n\nimport javax.inject.Inject;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\npublic class Fields {\n\n public Country country;\n\n @Inject\n @RestClient\n public MyService service1, service2;\n\n @Inject\n public CountriesService RestClientAnnotationMissing;\n\n @Inject\n @RestClient\n public CountriesService InjectAnnotationMissing;\n\n public CountriesService RestClientAndInjectAnnotationMissing;\n} \n "))); codeActionParams = createCodeActionParams(uri, d5); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Inject, @RestClient", d5, // + ca(uri, "Insert @Inject, @RestClient", MicroProfileCodeActionId.InsertInjectAndRestClientAnnotations, d5, // te(0, 0, 22, 10, "package org.acme.restclient;\n\nimport javax.inject.Inject;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\npublic class Fields {\n\n public Country country;\n\n @Inject\n @RestClient\n public MyService service1, service2;\n\n @Inject\n public CountriesService RestClientAnnotationMissing;\n\n @RestClient\n public CountriesService InjectAnnotationMissing;\n\n @RestClient\n @Inject\n public CountriesService RestClientAndInjectAnnotationMissing;\n} \n "))); } @@ -135,16 +136,16 @@ public void testRestClientAnnotationMissingForFieldsJakarta() throws Exception { MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d2); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Inject", d2, // + ca(uri, "Insert @Inject", MicroProfileCodeActionId.InsertInjectAnnotation, d2, // te(0, 0, 17, 1, "package com.demo.rest;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\nimport jakarta.inject.Inject;\n\npublic class injectAnnotation {\n\n @Inject\n @RestClient\n public MyService NoAnnotationMissing;\n\n @Inject\n @RestClient\n public Service InjectAnnotationMissing;\n\n public Service RestClientAndInjectAnnotationMissing;\n\n}")), - ca(uri, "Generate OpenAPI Annotations for 'injectAnnotation'", d2, // + ca(uri, "Generate OpenAPI Annotations for 'injectAnnotation'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d2, // te(0, 0, 17, 1, "package com.demo.rest;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\nimport jakarta.inject.Inject;\n\npublic class injectAnnotation {\n\n @Inject\n @RestClient\n public MyService NoAnnotationMissing;\n\n @RestClient\n public Service InjectAnnotationMissing;\n\n public Service RestClientAndInjectAnnotationMissing;\n\n}"))); codeActionParams = createCodeActionParams(uri, d3); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @Inject, @RestClient", d3, // + ca(uri, "Insert @Inject, @RestClient", MicroProfileCodeActionId.InsertInjectAndRestClientAnnotations, d3, // te(0, 0, 17, 1, "package com.demo.rest;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\nimport jakarta.inject.Inject;\n\npublic class injectAnnotation {\n\n @Inject\n @RestClient\n public MyService NoAnnotationMissing;\n\n @RestClient\n public Service InjectAnnotationMissing;\n\n @RestClient\n @Inject\n public Service RestClientAndInjectAnnotationMissing;\n\n}")), - ca(uri, "Generate OpenAPI Annotations for 'injectAnnotation'", d3, // + ca(uri, "Generate OpenAPI Annotations for 'injectAnnotation'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d3, // te(0, 0, 17, 1, "package com.demo.rest;\n\nimport org.eclipse.microprofile.rest.client.inject.RestClient;\n\nimport jakarta.inject.Inject;\n\npublic class injectAnnotation {\n\n @Inject\n @RestClient\n public MyService NoAnnotationMissing;\n\n @RestClient\n public Service InjectAnnotationMissing;\n\n public Service RestClientAndInjectAnnotationMissing;\n\n}"))); } @@ -173,7 +174,7 @@ public void testRestClientAnnotationMissingForInterface() throws Exception { /*String uri = javaFile.getLocation().toFile().toURI().toString();*/ MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @RegisterRestClient", d, // + ca(uri, "Insert @RegisterRestClient", MicroProfileCodeActionId.InsertRegisterRestClient, d, // te(0, 0, 5, 0, "package org.acme.restclient;\n\nimport org.eclipse.microprofile.rest.client.inject.RegisterRestClient;\n\n@RegisterRestClient\npublic interface MyService {\n\n}\n"))); } @@ -199,10 +200,10 @@ public void testRestClientAnnotationMissingForInterfaceJakarta() throws Exceptio MicroProfileJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d); assertJavaCodeAction(codeActionParams, utils, // - ca(uri, "Insert @RegisterRestClient", d, // + ca(uri, "Insert @RegisterRestClient", MicroProfileCodeActionId.InsertRegisterRestClient, d, // te(0, 0, 5, 0, "package com.demo.rest;\n\nimport org.eclipse.microprofile.rest.client.inject.RegisterRestClient;\n\n@RegisterRestClient\npublic interface MyService {\n\n}\n")), - ca(uri, "Generate OpenAPI Annotations for 'MyService'", d, // + ca(uri, "Generate OpenAPI Annotations for 'MyService'", MicroProfileCodeActionId.GenerateOpenApiAnnotations, d, // te(0, 0, 5, 0, "package com.demo.rest;\n\npublic interface MyService {\n\n}\n"))); } diff --git a/src/test/java/com/redhat/microprofile/psi/quarkus/renarde/RenardeJaxRsTest.java b/src/test/java/com/redhat/microprofile/psi/quarkus/renarde/RenardeJaxRsTest.java index 50530747b..447b6eb24 100644 --- a/src/test/java/com/redhat/microprofile/psi/quarkus/renarde/RenardeJaxRsTest.java +++ b/src/test/java/com/redhat/microprofile/psi/quarkus/renarde/RenardeJaxRsTest.java @@ -11,20 +11,14 @@ *******************************************************************************/ package com.redhat.microprofile.psi.quarkus.renarde; -import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileForJavaAssert.*; -import static org.junit.Assert.assertNotNull; - import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtilCore; -import com.intellij.psi.PsiClass; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; -import com.redhat.devtools.intellij.qute.psi.utils.PsiTypeUtils; import com.redhat.microprofile.psi.quarkus.QuarkusMavenModuleImportingTestCase; import com.redhat.microprofile.psi.quarkus.QuarkusMavenProjectName; import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeLensParams; import org.junit.Test; -import java.io.File; +import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileForJavaAssert.*; /** * Tests for the CodeLens features introduced by