From 39df73d95d8875ae4e318ecc9df83eb6a479a44d Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Fri, 8 Sep 2023 16:41:22 +0530 Subject: [PATCH 01/18] Fixes #196 Fixes #196 --- .../lsp/LibertyConfigLanguageServer.java | 13 +------ .../liberty/lsp/LibertyXmlServer.java | 12 +----- .../lsp/JakartaLanguageServer.java | 12 +----- .../lsp4mp/lsp/MicroProfileServer.java | 13 +------ .../ProcessStreamConnectionProvider.java | 37 ++++++++++++++++++- .../messages/LibertyBundles.properties | 5 +++ 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index 8f1fc9304..3bd4efa72 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -18,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.swing.*; import java.io.File; import java.net.URI; import java.util.ArrayList; @@ -33,20 +34,10 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider private static final Logger LOGGER = LoggerFactory.getLogger(LibertyConfigLanguageServer.class); public LibertyConfigLanguageServer() { + super("LibertyConfigLanguageServer"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); String javaHome = System.getProperty("java.home"); - if (javaHome == null) { - LOGGER.error("Unable to launch the Liberty language server. Could not resolve the java home system property"); - return; - } - if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - LOGGER.error("Unable to launch the Liberty language server." + - " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + - " Change the boot Java runtime of the IDE as documented here:" + - " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); - return; - } if (libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index eb0b10fea..9a4dac8bf 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -32,21 +32,11 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(LibertyXmlServer.class); public LibertyXmlServer() { + super("Liberty Server"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); String javaHome = System.getProperty("java.home"); - if (javaHome == null) { - LOGGER.error("Unable to launch the LemMinX language server. Could not resolve the java home system property"); - return; - } - if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - LOGGER.error("Unable to launch the LemMinX language server." + - " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + - " Change the boot Java runtime of the IDE as documented here:" + - " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); - return; - } if (lemminxServerPath.exists() && libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index 6c5b6ec70..0c8484c8d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -31,20 +31,10 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(JakartaLanguageServer.class); public JakartaLanguageServer() { + super("Jakarta Language Server"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); String javaHome = System.getProperty("java.home"); - if (javaHome == null) { - LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server. Could not resolve the java home system property"); - return; - } - if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server." + - " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + - " Change the boot Java runtime of the IDE as documented here:" + - " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); - return; - } if (lsp4JakartaServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", lsp4JakartaServerPath.getAbsolutePath(), "-DrunAsync=true")); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 1989276b3..8ffe5a700 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -34,20 +34,11 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileServer.class); public MicroProfileServer() { + super("Microprofile Server"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); String javaHome = System.getProperty("java.home"); - if (javaHome == null) { - LOGGER.error("Unable to launch the Eclipse LSP4MP language server. Could not resolve the java home system property"); - return; - } - if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - LOGGER.error("Unable to launch the Eclipse LSP4MP language server." + - " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + - " Change the boot Java runtime of the IDE as documented here:" + - " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); - return; - } + if (lsp4mpServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", lsp4mpServerPath.getAbsolutePath(), "-DrunAsync=true")); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 741d548bf..ff1b26889 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -2,8 +2,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.openliberty.tools.intellij.util.Constants; +import io.openliberty.tools.intellij.util.LocalizedResourceUtil; import javax.annotation.Nullable; +import javax.swing.*; import java.io.*; import java.util.List; import java.util.Objects; @@ -17,7 +20,9 @@ public abstract class ProcessStreamConnectionProvider implements StreamConnectio private List commands; private @Nullable String workingDir; - public ProcessStreamConnectionProvider() { + public ProcessStreamConnectionProvider(String serverType) { + String javaHome = System.getProperty("java.home"); + checkJavaHome(javaHome, serverType); } public ProcessStreamConnectionProvider(List commands) { @@ -160,5 +165,35 @@ public String toString() { return "ProcessStreamConnectionProvider [commands=" + this.getCommands() + ", workingDir=" //$NON-NLS-1$//$NON-NLS-2$ + this.getWorkingDirectory() + "]"; //$NON-NLS-1$ } + public void checkJavaHome(String javaHome, String serverType) { + + if (javaHome == null) { + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-home.null"); + LOGGER.error(errorMessage); + showErrorPopup(errorMessage); + return; + } + + File javaHomeDir = new File(javaHome); + if (!javaHomeDir.exists()) { + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.javaHomeDir.exist") + javaHome; + LOGGER.error(errorMessage); + showErrorPopup(errorMessage); + return; + } + + if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { + String errorMessage =LocalizedResourceUtil.getMessage( "liberty.action.selection.dialog.java-version",Constants.REQUIRED_JAVA_VERSION,serverType); + LOGGER.error(errorMessage); + showErrorPopup(errorMessage); + } + } + + private void showErrorPopup(String errorMessage) { + // Wrap the errorMessage in HTML tags to create a two-line popup + String htmlErrorMessage = "" + errorMessage + ""; + + JOptionPane.showMessageDialog(null, htmlErrorMessage, "Error", JOptionPane.ERROR_MESSAGE); + } } diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 09318b61a..3efaea31b 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -50,6 +50,11 @@ liberty.project.file.selection.dialog.title=Liberty project liberty.project.file.selection.dialog.message=Select Liberty project for {0} liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run +liberty.action.selection.dialog.java-home.null=Unable to launch the LemMinX language server. Could not resolve the java home system property +liberty.action.selection.dialog.javaHomeDir.exist=Unable to launch the LemMinX language server. The java.home directory does not exist +liberty.action.selection.dialog.java-version=Unable to launch the {1} . Java {0} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here Switching Boot JDK + + # Messages for Liberty add and remove project actions liberty.project.add=add Liberty project From a395d29b6b9cfe7efe83a09aa10a7e1451838d9b Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Fri, 8 Sep 2023 19:46:05 +0530 Subject: [PATCH 02/18] FIXES #196 --- .../intellij/liberty/lsp/LibertyConfigLanguageServer.java | 2 +- .../tools/intellij/liberty/lsp/LibertyXmlServer.java | 2 +- .../intellij/lsp4jakarta/lsp/JakartaLanguageServer.java | 2 +- .../tools/intellij/lsp4mp/lsp/MicroProfileServer.java | 2 +- .../java/io/openliberty/tools/intellij/util/Constants.java | 6 ++++++ src/main/resources/messages/LibertyBundles.properties | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index 3bd4efa72..01c77d1da 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -34,7 +34,7 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider private static final Logger LOGGER = LoggerFactory.getLogger(LibertyConfigLanguageServer.class); public LibertyConfigLanguageServer() { - super("LibertyConfigLanguageServer"); + super(Constants.LIBERTY_CONFIG_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); String javaHome = System.getProperty("java.home"); diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index 9a4dac8bf..07159a782 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -32,7 +32,7 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(LibertyXmlServer.class); public LibertyXmlServer() { - super("Liberty Server"); + super(Constants.LIBERTY_XML_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index 0c8484c8d..c2250c801 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -31,7 +31,7 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(JakartaLanguageServer.class); public JakartaLanguageServer() { - super("Jakarta Language Server"); + super(Constants.JAKARTA_LANG_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); String javaHome = System.getProperty("java.home"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 8ffe5a700..34f6334f6 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -34,7 +34,7 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileServer.class); public MicroProfileServer() { - super("Microprofile Server"); + super(Constants.MICROPROFILE_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); String javaHome = System.getProperty("java.home"); diff --git a/src/main/java/io/openliberty/tools/intellij/util/Constants.java b/src/main/java/io/openliberty/tools/intellij/util/Constants.java index b0a57e2f8..6788fe328 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/Constants.java +++ b/src/main/java/io/openliberty/tools/intellij/util/Constants.java @@ -86,4 +86,10 @@ public final class Constants { * Constants for langauge servers */ public static final String SERVER_ENV_GLOB_PATTERN = "**/{src/main/liberty/config,usr/servers/**}/server.env"; + + public static final String LIBERTY_XML_SERVER = "LibertyConfigLanguageServer"; + public static final String LIBERTY_CONFIG_SERVER="LibertyConfigLanguageServer"; + public static final String JAKARTA_LANG_SERVER="Jakarta Language Server"; + public static final String MICROPROFILE_SERVER="Microprofile Server"; + } diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 3efaea31b..923f033cf 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -52,7 +52,7 @@ liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run liberty.action.selection.dialog.java-home.null=Unable to launch the LemMinX language server. Could not resolve the java home system property liberty.action.selection.dialog.javaHomeDir.exist=Unable to launch the LemMinX language server. The java.home directory does not exist -liberty.action.selection.dialog.java-version=Unable to launch the {1} . Java {0} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here Switching Boot JDK +liberty.action.selection.dialog.java-version=Unable to launch the {1} . Java {0} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html From 34f94aa28c81f1973a8aa1417754d7228b032384 Mon Sep 17 00:00:00 2001 From: Anusree Lakshmi <141303561+anusreelakshmi934@users.noreply.github.com> Date: Sat, 9 Sep 2023 09:59:22 +0530 Subject: [PATCH 03/18] Update src/main/java/io/openliberty/tools/intellij/util/Constants.java Co-authored-by: Trevor Crawford --- .../io/openliberty/tools/intellij/util/Constants.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/util/Constants.java b/src/main/java/io/openliberty/tools/intellij/util/Constants.java index 6788fe328..9f1ab01b3 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/Constants.java +++ b/src/main/java/io/openliberty/tools/intellij/util/Constants.java @@ -87,9 +87,9 @@ public final class Constants { */ public static final String SERVER_ENV_GLOB_PATTERN = "**/{src/main/liberty/config,usr/servers/**}/server.env"; - public static final String LIBERTY_XML_SERVER = "LibertyConfigLanguageServer"; - public static final String LIBERTY_CONFIG_SERVER="LibertyConfigLanguageServer"; - public static final String JAKARTA_LANG_SERVER="Jakarta Language Server"; - public static final String MICROPROFILE_SERVER="Microprofile Server"; + public static final String LIBERTY_XML_SERVER = "LemMinX"; + public static final String LIBERTY_CONFIG_SERVER="Liberty Config"; + public static final String JAKARTA_LANG_SERVER="Eclipse LSP4Jakarta"; + public static final String MICROPROFILE_SERVER="Eclipse LSP4MP"; } From 0c37098e7e75489d25213aef50ca4dd92f197871 Mon Sep 17 00:00:00 2001 From: Anusree Lakshmi <141303561+anusreelakshmi934@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:29:36 +0530 Subject: [PATCH 04/18] Update src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java Co-authored-by: Trevor Crawford --- .../lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index ff1b26889..177946c34 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -183,7 +183,7 @@ public void checkJavaHome(String javaHome, String serverType) { } if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - String errorMessage =LocalizedResourceUtil.getMessage( "liberty.action.selection.dialog.java-version",Constants.REQUIRED_JAVA_VERSION,serverType); + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-version", Constants.REQUIRED_JAVA_VERSION, serverType); LOGGER.error(errorMessage); showErrorPopup(errorMessage); } From a7e87baa65bc8978f52b5809e911bd84edead515 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Tue, 12 Sep 2023 12:54:44 +0530 Subject: [PATCH 05/18] Changes mentioned #196 The server files were modified. changed to built in IntelliJ APIs to show pop up errors. --- .../lsp/LibertyConfigLanguageServer.java | 6 ++-- .../liberty/lsp/LibertyXmlServer.java | 4 +-- .../lsp/JakartaLanguageServer.java | 4 +-- .../lsp4mp/lsp/MicroProfileServer.java | 4 +-- .../ProcessStreamConnectionProvider.java | 30 +++++++++++++------ .../messages/LibertyBundles.properties | 7 ++--- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index 01c77d1da..a07bb176c 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -17,8 +17,6 @@ import io.openliberty.tools.intellij.util.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import javax.swing.*; import java.io.File; import java.net.URI; import java.util.ArrayList; @@ -34,10 +32,10 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider private static final Logger LOGGER = LoggerFactory.getLogger(LibertyConfigLanguageServer.class); public LibertyConfigLanguageServer() { - super(Constants.LIBERTY_CONFIG_SERVER); + String javaHome = System.getProperty("java.home"); + checkJavaHome(javaHome, Constants.LIBERTY_CONFIG_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); - String javaHome = System.getProperty("java.home"); if (libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index 07159a782..526f79495 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -32,11 +32,11 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(LibertyXmlServer.class); public LibertyXmlServer() { - super(Constants.LIBERTY_XML_SERVER); + String javaHome = System.getProperty("java.home"); + checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); - String javaHome = System.getProperty("java.home"); if (lemminxServerPath.exists() && libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index c2250c801..0e68547d2 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -31,10 +31,10 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(JakartaLanguageServer.class); public JakartaLanguageServer() { - super(Constants.JAKARTA_LANG_SERVER); + String javaHome = System.getProperty("java.home"); + checkJavaHome(javaHome, Constants.JAKARTA_LANG_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); - String javaHome = System.getProperty("java.home"); if (lsp4JakartaServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", lsp4JakartaServerPath.getAbsolutePath(), "-DrunAsync=true")); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 34f6334f6..d6133465b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -34,10 +34,10 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileServer.class); public MicroProfileServer() { - super(Constants.MICROPROFILE_SERVER); + String javaHome = System.getProperty("java.home"); + checkJavaHome(javaHome, Constants.MICROPROFILE_SERVER); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); - String javaHome = System.getProperty("java.home"); if (lsp4mpServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 177946c34..87682bd5a 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -1,5 +1,12 @@ package io.openliberty.tools.intellij.lsp4mp.lsp4ij.server; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import io.openliberty.tools.intellij.LibertyPluginIcons; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import io.openliberty.tools.intellij.util.Constants; @@ -20,9 +27,7 @@ public abstract class ProcessStreamConnectionProvider implements StreamConnectio private List commands; private @Nullable String workingDir; - public ProcessStreamConnectionProvider(String serverType) { - String javaHome = System.getProperty("java.home"); - checkJavaHome(javaHome, serverType); + public ProcessStreamConnectionProvider() { } public ProcessStreamConnectionProvider(List commands) { @@ -168,7 +173,7 @@ public String toString() { public void checkJavaHome(String javaHome, String serverType) { if (javaHome == null) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-home.null"); + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-home.null",serverType); LOGGER.error(errorMessage); showErrorPopup(errorMessage); return; @@ -176,24 +181,31 @@ public void checkJavaHome(String javaHome, String serverType) { File javaHomeDir = new File(javaHome); if (!javaHomeDir.exists()) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.javaHomeDir.exist") + javaHome; + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.javaHomeDir.exist",serverType,Constants.REQUIRED_JAVA_VERSION,javaHome); LOGGER.error(errorMessage); showErrorPopup(errorMessage); return; } if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-version", Constants.REQUIRED_JAVA_VERSION, serverType); + String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-version", serverType,Constants.REQUIRED_JAVA_VERSION,javaHome); LOGGER.error(errorMessage); showErrorPopup(errorMessage); } } + private void notifyError(String errMsg, Project project) { + Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING) + .setTitle(LocalizedResourceUtil.getMessage("liberty.action.cannot.start")) + .setIcon(LibertyPluginIcons.libertyIcon) + .setSubtitle("") + .setListener(NotificationListener.URL_OPENING_LISTENER); + Notifications.Bus.notify(notif, project); + } + private void showErrorPopup(String errorMessage) { - // Wrap the errorMessage in HTML tags to create a two-line popup - String htmlErrorMessage = "" + errorMessage + ""; + notifyError(errorMessage, ProjectManager.getInstance().getDefaultProject()); - JOptionPane.showMessageDialog(null, htmlErrorMessage, "Error", JOptionPane.ERROR_MESSAGE); } } diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 923f033cf..675df9709 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -50,10 +50,9 @@ liberty.project.file.selection.dialog.title=Liberty project liberty.project.file.selection.dialog.message=Select Liberty project for {0} liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run -liberty.action.selection.dialog.java-home.null=Unable to launch the LemMinX language server. Could not resolve the java home system property -liberty.action.selection.dialog.javaHomeDir.exist=Unable to launch the LemMinX language server. The java.home directory does not exist -liberty.action.selection.dialog.java-version=Unable to launch the {1} . Java {0} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html - +liberty.action.selection.dialog.java-home.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +liberty.action.selection.dialog.javaHomeDir.exist=Unable to launch the {0} language server. The java home directory does not exist.Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +liberty.action.selection.dialog.java-version=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html # Messages for Liberty add and remove project actions From f4047595649f3f1c5d4f344eb90c3463f2884cd2 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Tue, 19 Sep 2023 14:58:56 +0530 Subject: [PATCH 06/18] changes#196 checkJavaHome() made to return a boolean value. and modified the code according to other comments --- .../lsp/LibertyConfigLanguageServer.java | 4 +++- .../liberty/lsp/LibertyXmlServer.java | 4 +++- .../lsp/JakartaLanguageServer.java | 4 +++- .../lsp4mp/lsp/MicroProfileServer.java | 4 +++- .../ProcessStreamConnectionProvider.java | 21 ++++++++++--------- .../messages/LibertyBundles.properties | 8 ++++--- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index a07bb176c..7a86d320c 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -33,7 +33,9 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider public LibertyConfigLanguageServer() { String javaHome = System.getProperty("java.home"); - checkJavaHome(javaHome, Constants.LIBERTY_CONFIG_SERVER); + if(checkJavaHome(javaHome, Constants.LIBERTY_CONFIG_SERVER)){ + return; + } IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); if (libertyServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index 526f79495..eb42e9f57 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -33,7 +33,9 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { public LibertyXmlServer() { String javaHome = System.getProperty("java.home"); - checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER); + if(checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER)){ + return; + } IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index 0e68547d2..9a5b1a0af 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -32,7 +32,9 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { public JakartaLanguageServer() { String javaHome = System.getProperty("java.home"); - checkJavaHome(javaHome, Constants.JAKARTA_LANG_SERVER); + if(checkJavaHome(javaHome, Constants.JAKARTA_LANG_SERVER)){ + return; + } IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); if (lsp4JakartaServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index d6133465b..0f3f2e10a 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -35,7 +35,9 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { public MicroProfileServer() { String javaHome = System.getProperty("java.home"); - checkJavaHome(javaHome, Constants.MICROPROFILE_SERVER); + if(checkJavaHome(javaHome, Constants.MICROPROFILE_SERVER)){ + return; + } IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 87682bd5a..7627caaec 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -1,19 +1,18 @@ package io.openliberty.tools.intellij.lsp4mp.lsp4ij.server; +import com.intellij.icons.AllIcons; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; -import io.openliberty.tools.intellij.LibertyPluginIcons; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import io.openliberty.tools.intellij.util.Constants; import io.openliberty.tools.intellij.util.LocalizedResourceUtil; import javax.annotation.Nullable; -import javax.swing.*; import java.io.*; import java.util.List; import java.util.Objects; @@ -170,34 +169,36 @@ public String toString() { return "ProcessStreamConnectionProvider [commands=" + this.getCommands() + ", workingDir=" //$NON-NLS-1$//$NON-NLS-2$ + this.getWorkingDirectory() + "]"; //$NON-NLS-1$ } - public void checkJavaHome(String javaHome, String serverType) { + public boolean checkJavaHome(String javaHome, String serverType) { if (javaHome == null) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-home.null",serverType); + String errorMessage = LocalizedResourceUtil.getMessage("javaHome.is.null",serverType,Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); - return; + return true; } File javaHomeDir = new File(javaHome); if (!javaHomeDir.exists()) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.javaHomeDir.exist",serverType,Constants.REQUIRED_JAVA_VERSION,javaHome); + String errorMessage = LocalizedResourceUtil.getMessage("javaHomeDir.does.not.exist",serverType,Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); - return; + return true; } if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - String errorMessage = LocalizedResourceUtil.getMessage("liberty.action.selection.dialog.java-version", serverType,Constants.REQUIRED_JAVA_VERSION,javaHome); + String errorMessage = LocalizedResourceUtil.getMessage("java.version.message", serverType,Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); + return true; } + return false; } private void notifyError(String errMsg, Project project) { Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING) - .setTitle(LocalizedResourceUtil.getMessage("liberty.action.cannot.start")) - .setIcon(LibertyPluginIcons.libertyIcon) + .setTitle("Java runtime error") + .setIcon(AllIcons.General.Warning) .setSubtitle("") .setListener(NotificationListener.URL_OPENING_LISTENER); Notifications.Bus.notify(notif, project); diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 675df9709..25932c7c7 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -50,9 +50,11 @@ liberty.project.file.selection.dialog.title=Liberty project liberty.project.file.selection.dialog.message=Select Liberty project for {0} liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run -liberty.action.selection.dialog.java-home.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -liberty.action.selection.dialog.javaHomeDir.exist=Unable to launch the {0} language server. The java home directory does not exist.Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -liberty.action.selection.dialog.java-version=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html + +#Messages for Checking javaHome +javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html # Messages for Liberty add and remove project actions From 498eab3d49fc4be4e2f75e5f63cb292793c519e1 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Tue, 19 Sep 2023 15:45:07 +0530 Subject: [PATCH 07/18] checkJavaHome return method #196 added the boolean return method --- .../intellij/liberty/lsp/LibertyConfigLanguageServer.java | 4 ++-- .../tools/intellij/liberty/lsp/LibertyXmlServer.java | 6 +++--- .../intellij/lsp4jakarta/lsp/JakartaLanguageServer.java | 4 ++-- .../tools/intellij/lsp4mp/lsp/MicroProfileServer.java | 5 ++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index 7a86d320c..cfe559ce3 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -33,11 +33,11 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider public LibertyConfigLanguageServer() { String javaHome = System.getProperty("java.home"); + IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); + File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); if(checkJavaHome(javaHome, Constants.LIBERTY_CONFIG_SERVER)){ return; } - IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); - File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); if (libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index eb42e9f57..70bc97740 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -33,12 +33,12 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { public LibertyXmlServer() { String javaHome = System.getProperty("java.home"); - if(checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER)){ - return; - } IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); + if(checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER)){ + return; + } if (lemminxServerPath.exists() && libertyServerPath.exists()) { ArrayList params = new ArrayList<>(); params.add(javaHome + File.separator + "bin" + File.separator + "java"); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index 9a5b1a0af..795f35ccc 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -32,11 +32,11 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { public JakartaLanguageServer() { String javaHome = System.getProperty("java.home"); + IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); + File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); if(checkJavaHome(javaHome, Constants.JAKARTA_LANG_SERVER)){ return; } - IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); - File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); if (lsp4JakartaServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", lsp4JakartaServerPath.getAbsolutePath(), "-DrunAsync=true")); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 0f3f2e10a..487744e12 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -35,12 +35,11 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { public MicroProfileServer() { String javaHome = System.getProperty("java.home"); + IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); + File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); if(checkJavaHome(javaHome, Constants.MICROPROFILE_SERVER)){ return; } - IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); - File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); - if (lsp4mpServerPath.exists()) { setCommands(Arrays.asList(javaHome + File.separator + "bin" + File.separator + "java", "-jar", lsp4mpServerPath.getAbsolutePath(), "-DrunAsync=true")); From 2b452f1cab632a0e5975509538ab5f13d03225d9 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Fri, 22 Sep 2023 11:11:00 +0530 Subject: [PATCH 08/18] message exported to LibertyBundles.properties #196 Formatting done. Changed method name to isJavaHomeValid. --- .../lsp/LibertyConfigLanguageServer.java | 3 +-- .../intellij/liberty/lsp/LibertyXmlServer.java | 2 +- .../lsp4jakarta/lsp/JakartaLanguageServer.java | 2 +- .../lsp4mp/lsp/MicroProfileServer.java | 3 +-- .../ProcessStreamConnectionProvider.java | 18 +++++++++--------- .../messages/LibertyBundles.properties | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index cfe559ce3..cad6fc832 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -20,7 +20,6 @@ import java.io.File; import java.net.URI; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -35,7 +34,7 @@ public LibertyConfigLanguageServer() { String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-2.0-jar-with-dependencies.jar"); - if(checkJavaHome(javaHome, Constants.LIBERTY_CONFIG_SERVER)){ + if(!isJavaHomeValid(javaHome, Constants.LIBERTY_CONFIG_SERVER)){ return; } if (libertyServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index 70bc97740..18d90ed6f 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -36,7 +36,7 @@ public LibertyXmlServer() { IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-2.0-jar-with-dependencies.jar"); - if(checkJavaHome(javaHome, Constants.LIBERTY_XML_SERVER)){ + if(!isJavaHomeValid(javaHome, Constants.LIBERTY_XML_SERVER)){ return; } if (lemminxServerPath.exists() && libertyServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index 795f35ccc..f34f87747 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -34,7 +34,7 @@ public JakartaLanguageServer() { String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); - if(checkJavaHome(javaHome, Constants.JAKARTA_LANG_SERVER)){ + if(!isJavaHomeValid(javaHome, Constants.JAKARTA_LANG_SERVER)){ return; } if (lsp4JakartaServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 487744e12..59ba1b9ac 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -13,7 +13,6 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.extensions.PluginId; -import io.openliberty.tools.intellij.liberty.lsp.LibertyXmlServer; import io.openliberty.tools.intellij.lsp4mp.lsp4ij.server.ProcessStreamConnectionProvider; import io.openliberty.tools.intellij.util.Constants; import org.slf4j.Logger; @@ -37,7 +36,7 @@ public MicroProfileServer() { String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); - if(checkJavaHome(javaHome, Constants.MICROPROFILE_SERVER)){ + if(!isJavaHomeValid(javaHome, Constants.MICROPROFILE_SERVER)){ return; } if (lsp4mpServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 7627caaec..0adca14fb 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -169,35 +169,35 @@ public String toString() { return "ProcessStreamConnectionProvider [commands=" + this.getCommands() + ", workingDir=" //$NON-NLS-1$//$NON-NLS-2$ + this.getWorkingDirectory() + "]"; //$NON-NLS-1$ } - public boolean checkJavaHome(String javaHome, String serverType) { + public boolean isJavaHomeValid(String javaHome, String serverType) { if (javaHome == null) { - String errorMessage = LocalizedResourceUtil.getMessage("javaHome.is.null",serverType,Constants.REQUIRED_JAVA_VERSION); + String errorMessage = LocalizedResourceUtil.getMessage("javaHome.is.null", serverType, Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); - return true; + return false; } File javaHomeDir = new File(javaHome); if (!javaHomeDir.exists()) { - String errorMessage = LocalizedResourceUtil.getMessage("javaHomeDir.does.not.exist",serverType,Constants.REQUIRED_JAVA_VERSION); + String errorMessage = LocalizedResourceUtil.getMessage("javaHomeDir.does.not.exist", serverType, Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); - return true; + return false; } if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - String errorMessage = LocalizedResourceUtil.getMessage("java.version.message", serverType,Constants.REQUIRED_JAVA_VERSION); + String errorMessage = LocalizedResourceUtil.getMessage("java.version.message", serverType, Constants.REQUIRED_JAVA_VERSION); LOGGER.error(errorMessage); showErrorPopup(errorMessage); - return true; + return false; } - return false; + return true; } private void notifyError(String errMsg, Project project) { Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING) - .setTitle("Java runtime error") + .setTitle(LocalizedResourceUtil.getMessage("java.runtime.error.message")) .setIcon(AllIcons.General.Warning) .setSubtitle("") .setListener(NotificationListener.URL_OPENING_LISTENER); diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 25932c7c7..6c8aa960e 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -55,7 +55,7 @@ liberty.action.selection.dialog.message=Select Liberty action to run javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html - +java.runtime.error.message=Java runtime error # Messages for Liberty add and remove project actions liberty.project.add=add Liberty project From 92b2826ff196e9d7622e9fe29bd732f7c19d23a7 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Tue, 26 Sep 2023 09:37:13 +0530 Subject: [PATCH 09/18] Changed the error popup icon to Liberty icon #196 --- .../lsp4ij/server/ProcessStreamConnectionProvider.java | 9 +++++---- src/main/resources/messages/LibertyBundles.properties | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 0adca14fb..50c571e5d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -1,16 +1,17 @@ package io.openliberty.tools.intellij.lsp4mp.lsp4ij.server; -import com.intellij.icons.AllIcons; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.openliberty.tools.intellij.LibertyPluginIcons; import io.openliberty.tools.intellij.util.Constants; import io.openliberty.tools.intellij.util.LocalizedResourceUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.annotation.Nullable; import java.io.*; @@ -198,7 +199,7 @@ public boolean isJavaHomeValid(String javaHome, String serverType) { private void notifyError(String errMsg, Project project) { Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING) .setTitle(LocalizedResourceUtil.getMessage("java.runtime.error.message")) - .setIcon(AllIcons.General.Warning) + .setIcon(LibertyPluginIcons.libertyIcon) .setSubtitle("") .setListener(NotificationListener.URL_OPENING_LISTENER); Notifications.Bus.notify(notif, project); diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 6c8aa960e..e5342cccc 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -52,8 +52,8 @@ liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run #Messages for Checking javaHome -javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.htmljavaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html java.runtime.error.message=Java runtime error From 956f00856477b3cd56ee44c895703b4e8580bef6 Mon Sep 17 00:00:00 2001 From: anusreelakshmi934 Date: Wed, 27 Sep 2023 12:36:17 +0530 Subject: [PATCH 10/18] Fixed editing error #196 --- src/main/resources/messages/LibertyBundles.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index e5342cccc..7defa2fe7 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -52,8 +52,8 @@ liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run #Messages for Checking javaHome -javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.htmljavaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is pointing to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html +javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html java.runtime.error.message=Java runtime error From d348a999cd508047f7f04501f49ef163c71435d3 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Fri, 29 Sep 2023 20:06:03 +0530 Subject: [PATCH 11/18] Refactored the InsertAnnotationQuickfix class 1. Implemented IJavaCodeActionParticipant 2. Made the class abstract --- .../InsertAnnotationAttributesQuickFix.java | 5 ++ .../quickfix/InsertAnnotationQuickFix.java | 72 ++++++++++++++----- .../websocket/AddPathParamQuickFix.java | 5 ++ 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java index 95aebd14d..f02628348 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java @@ -32,4 +32,9 @@ public InsertAnnotationAttributesQuickFix(String annotation, boolean generateOnl //@Override protected String getLabel(String annotation, String... attributes) { return Messages.getMessage("AddAtoB", attributes[0], annotation); } + + @Override + public String getParticipantId() { + return InsertAnnotationAttributesQuickFix.class.getName(); + } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index e2383fe94..d1a950922 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -17,14 +17,23 @@ import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.Messages; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.ModifyAnnotationProposal; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.ExtendedCodeAction; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; 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.CodeActionResolveData; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Quickfix for adding new annotations with or without attributes @@ -33,7 +42,7 @@ * @author Lidia Ataupillco Ramos * */ -public class InsertAnnotationQuickFix { +public abstract class InsertAnnotationQuickFix implements IJavaCodeActionParticipant { private final String[] attributes; @@ -41,6 +50,8 @@ public class InsertAnnotationQuickFix { protected final boolean generateOnlyOneCodeAction; + private static final Logger LOGGER = Logger.getLogger(InsertAnnotationQuickFix.class.getName()); + public InsertAnnotationQuickFix(String annotation, String... attributes) { this(annotation, false, attributes); } @@ -62,23 +73,41 @@ public InsertAnnotationQuickFix(String annotation, boolean generateOnlyOneCodeAc public List getCodeActions(JavaCodeActionContext context, Diagnostic diagnostic) { PsiElement node = context.getCoveredNode(); + List codeActions = new ArrayList<>(); + addAttributes(diagnostic, context, codeActions, this.annotation); + + return codeActions; + } + + @Override + public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { + + final CodeAction toResolve = context.getUnresolved(); + final PsiElement node = context.getCoveredNode(); + final PsiMethod parentMethod = PsiTreeUtil.getParentOfType(node, PsiMethod.class); PsiModifierListOwner binding = getBinding(node); - // annotationNode is null when adding an annotation and non-null when adding attributes. PsiAnnotation annotationNode = PsiTreeUtil.getParentOfType(node, PsiAnnotation.class); - List codeActions = new ArrayList<>(); - addAttributes(diagnostic, context, binding, annotationNode, codeActions, this.annotation); + assert parentMethod != null; + String label = getLabel(this.annotation, attributes); - return codeActions; + ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getSource().getCompilationUnit(), + context.getASTRoot(), binding, annotationNode, 0, this.annotation, Arrays.asList(attributes)); + try { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e); + } + return toResolve; } - protected void addAttributes(Diagnostic diagnostic, JavaCodeActionContext context, PsiModifierListOwner binding, - PsiAnnotation annotation, List codeActions, String name) { + protected void addAttributes(Diagnostic diagnostic, JavaCodeActionContext context, List codeActions, String name) { if (generateOnlyOneCodeAction) { - addAttribute(diagnostic, context, binding, annotation, codeActions, name, attributes); + addAttribute(diagnostic, context, codeActions, name, attributes); } else { for (String attribute : attributes) { - addAttribute(diagnostic, context, binding, annotation, codeActions, name, attribute); + addAttribute(diagnostic, context, codeActions, name, attribute); } } } @@ -88,16 +117,9 @@ protected void addAttributes(Diagnostic diagnostic, JavaCodeActionContext contex * collector class. * */ - private void addAttribute(Diagnostic diagnostic, JavaCodeActionContext context, PsiModifierListOwner binding, - PsiAnnotation annotation, List codeActions, String name, String... attributes) { + private void addAttribute(Diagnostic diagnostic, JavaCodeActionContext context, List codeActions, String name, String... attributes) { String label = getLabel(name, attributes); - ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getSource().getCompilationUnit(), - context.getASTRoot(), binding, annotation, 0, name, Arrays.asList(attributes)); - CodeAction codeAction = context.convertToCodeAction(proposal, diagnostic); - - if (codeAction != null) { - codeActions.add(codeAction); - } + codeActions.add(createCodeAction(context, diagnostic, label)); } protected PsiModifierListOwner getBinding(PsiElement node) { @@ -112,4 +134,18 @@ protected PsiModifierListOwner getBinding(PsiElement node) { protected String getLabel(String annotationName, String... attributes) { return Messages.getMessage("InsertItem", "@" + annotation); // uses Java syntax } + + private CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic, String label) { + LOGGER.log(Level.WARNING, "#####&&&&&&&&& print label --" + label + "####", label); + + ExtendedCodeAction codeAction = new ExtendedCodeAction(label); + codeAction.setRelevance(0); + codeAction.setDiagnostics(Collections.singletonList(diagnostic)); + codeAction.setKind(CodeActionKind.QuickFix); + codeAction.setData(new CodeActionResolveData(context.getUri(), getParticipantId(), + context.getParams().getRange(), Collections.emptyMap(), + context.getParams().isResourceOperationSupported(), + context.getParams().isCommandConfigurationUpdateSupported())); + return codeAction; + } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/websocket/AddPathParamQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/websocket/AddPathParamQuickFix.java index 34b24295f..bb5be1464 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/websocket/AddPathParamQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/websocket/AddPathParamQuickFix.java @@ -25,4 +25,9 @@ public class AddPathParamQuickFix extends InsertAnnotationQuickFix { public AddPathParamQuickFix() { super("jakarta.websocket.server.PathParam", false, "value"); } + + @Override + public String getParticipantId() { + return AddPathParamQuickFix.class.getName(); + } } From f0f88ab9eb188e90cb9cee231a8d57f5d3553254 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Fri, 29 Sep 2023 20:12:29 +0530 Subject: [PATCH 12/18] Added extension point in plugin.xml for AddPathParamsAnnotation --- src/main/resources/META-INF/plugin.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 46307861d..5aab8e4fa 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -167,6 +167,11 @@ targetDiagnostic="jakarta-jax_rs#NonPublicResourceMethod" implementationClass="io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs.NonPublicResourceMethodQuickFix"/> + + From 75b84f120e9219fae80e543a5674042411fc0a3b Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Fri, 29 Sep 2023 21:05:00 +0530 Subject: [PATCH 13/18] enabled the code action test case and updated test case --- .../quickfix/InsertAnnotationQuickFix.java | 2 -- .../it/websocket/JakartaWebSocketTest.java | 16 ++++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index d1a950922..e78810636 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -136,8 +136,6 @@ protected String getLabel(String annotationName, String... attributes) { } private CodeAction createCodeAction(JavaCodeActionContext context, Diagnostic diagnostic, String label) { - LOGGER.log(Level.WARNING, "#####&&&&&&&&& print label --" + label + "####", label); - ExtendedCodeAction codeAction = new ExtendedCodeAction(label); codeAction.setRelevance(0); codeAction.setDiagnostics(Collections.singletonList(diagnostic)); diff --git a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java index 56b410a0e..99bbe7d82 100644 --- a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java +++ b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java @@ -70,16 +70,12 @@ public void addPathParamsAnnotation() throws Exception { JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3); - if (CHECK_CODE_ACTIONS) { - // Expected code actions - JakartaJavaCodeActionParams codeActionsParams = JakartaForJavaAssert.createCodeActionParams(uri, d1); - String newText = "\nimport jakarta.websocket.server.PathParam;\nimport jakarta.websocket.server.ServerEndpoint;\nimport jakarta.websocket.Session;\n\n" - + "/**\n * Expected Diagnostics are related to validating that the parameters have the \n * valid annotation @PathParam (code: AddPathParamsAnnotation)\n * See issue #247 (onOpen) and #248 (onClose)\n */\n" - + "@ServerEndpoint(value = \"/infos\")\npublic class AnnotationTest {\n // @PathParam missing annotation for \"String missingAnnotation\"\n @OnOpen\n public void OnOpen(Session session, @PathParam(value = \"\") "; - TextEdit te = JakartaForJavaAssert.te(5, 32, 18, 40, newText); - CodeAction ca = JakartaForJavaAssert.ca(uri, "Insert @jakarta.websocket.server.PathParam", d1, te); - JakartaForJavaAssert.assertJavaCodeAction(codeActionsParams, utils, ca); - } + // Expected code actions + JakartaJavaCodeActionParams codeActionsParams = JakartaForJavaAssert.createCodeActionParams(uri, d1); + String newText = "package io.openliberty.sample.jakarta.websocket;\\n\\nimport java.io.IOException;\\n\\nimport jakarta.websocket.OnClose;\\nimport jakarta.websocket.OnOpen;\\nimport jakarta.websocket.server.PathParam;import jakarta.websocket.server.ServerEndpoint;\\nimport jakarta.websocket.Session;\\n\\n/**\\n * Expected Diagnostics are related to validating that the parameters have the \\n * valid annotation @PathParam (code: AddPathParamsAnnotation)\\n * See issue #247 (onOpen) and #248 (onClose)\\n */\\n@ServerEndpoint(value = \"/infos\")\\npublic class AnnotationTest {\\n // @PathParam missing annotation for \"String missingAnnotation\"\\n @OnOpen\\n public void OnOpen(Session session, @PathParam(\"\") String missingAnnotation) throws IOException {\\n System.out.println(\"Websocket opened: \" + session.getId().toString());\\n }\\n \\n // Used to check that the expected diagnostic handle more than one case\\n @OnClose\\n public void OnClose(Session session, Integer missingAnnotation1, String missingAnnotation2) {\\n System.out.println(\"Websocket opened: \" + session.getId().toString());\\n }\\n}\\n"; + TextEdit te = JakartaForJavaAssert.te(0, 0, 28, 0, newText); + CodeAction ca = JakartaForJavaAssert.ca(uri, "Insert @jakarta.websocket.server.PathParam", d1, te); + JakartaForJavaAssert.assertJavaCodeAction(codeActionsParams, utils, ca); } @Test From 0f203605d3577c89a7dd069dc811ff84e9aede63 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Wed, 4 Oct 2023 20:16:34 +0530 Subject: [PATCH 14/18] Enabled quick fix testcase and updated the expected value --- .../it/websocket/JakartaWebSocketTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java index 99bbe7d82..813605436 100644 --- a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java +++ b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java @@ -36,6 +36,8 @@ import java.io.File; import java.util.Arrays; +import static io.openliberty.tools.intellij.lsp4jakarta.it.core.JakartaForJavaAssert.*; + @RunWith(JUnit4.class) public class JakartaWebSocketTest extends BaseJakartaTest { @@ -56,26 +58,29 @@ public void addPathParamsAnnotation() throws Exception { "Parameters of type String, any Java primitive type, or boxed version thereof must be annotated with @PathParams.", DiagnosticSeverity.Error, "jakarta-websocket", "AddPathParamsAnnotation" ); - + // OnClose PathParams Annotation check Diagnostic d2 = JakartaForJavaAssert.d(24, 49, 67, "Parameters of type String, any Java primitive type, or boxed version thereof must be annotated with @PathParams.", DiagnosticSeverity.Error, "jakarta-websocket", "AddPathParamsAnnotation" ); - + Diagnostic d3 = JakartaForJavaAssert.d(24, 76, 94, "Parameters of type String, any Java primitive type, or boxed version thereof must be annotated with @PathParams.", DiagnosticSeverity.Error, "jakarta-websocket", "AddPathParamsAnnotation" ); - JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3); + //TODO: uncomment this if condition, once refactoring is done for all the quick fixes. +// if (CHECK_CODE_ACTIONS) { // Expected code actions - JakartaJavaCodeActionParams codeActionsParams = JakartaForJavaAssert.createCodeActionParams(uri, d1); - String newText = "package io.openliberty.sample.jakarta.websocket;\\n\\nimport java.io.IOException;\\n\\nimport jakarta.websocket.OnClose;\\nimport jakarta.websocket.OnOpen;\\nimport jakarta.websocket.server.PathParam;import jakarta.websocket.server.ServerEndpoint;\\nimport jakarta.websocket.Session;\\n\\n/**\\n * Expected Diagnostics are related to validating that the parameters have the \\n * valid annotation @PathParam (code: AddPathParamsAnnotation)\\n * See issue #247 (onOpen) and #248 (onClose)\\n */\\n@ServerEndpoint(value = \"/infos\")\\npublic class AnnotationTest {\\n // @PathParam missing annotation for \"String missingAnnotation\"\\n @OnOpen\\n public void OnOpen(Session session, @PathParam(\"\") String missingAnnotation) throws IOException {\\n System.out.println(\"Websocket opened: \" + session.getId().toString());\\n }\\n \\n // Used to check that the expected diagnostic handle more than one case\\n @OnClose\\n public void OnClose(Session session, Integer missingAnnotation1, String missingAnnotation2) {\\n System.out.println(\"Websocket opened: \" + session.getId().toString());\\n }\\n}\\n"; - TextEdit te = JakartaForJavaAssert.te(0, 0, 28, 0, newText); - CodeAction ca = JakartaForJavaAssert.ca(uri, "Insert @jakarta.websocket.server.PathParam", d1, te); + JakartaJavaCodeActionParams codeActionsParams = createCodeActionParams(uri, d1); + String newText = "package io.openliberty.sample.jakarta.websocket;\n\nimport java.io.IOException;\n\nimport jakarta.websocket.OnClose;\nimport jakarta.websocket.OnOpen;\nimport jakarta.websocket.server.PathParam;import jakarta.websocket.server.ServerEndpoint;\nimport jakarta.websocket.Session;\n\n/**\n * Expected Diagnostics are related to validating that the parameters have the \n * valid annotation @PathParam (code: AddPathParamsAnnotation)\n * See issue #247 (onOpen) and #248 (onClose)\n */\n@ServerEndpoint(value = \"/infos\")\npublic class AnnotationTest {\n // @PathParam missing annotation for \"String missingAnnotation\"\n @OnOpen\n public void OnOpen(Session session, @PathParam(\"\") String missingAnnotation) throws IOException {\n System.out.println(\"Websocket opened: \" + session.getId().toString());\n }\n \n // Used to check that the expected diagnostic handle more than one case\n @OnClose\n public void OnClose(Session session, Integer missingAnnotation1, String missingAnnotation2) {\n System.out.println(\"Websocket opened: \" + session.getId().toString());\n }\n}\n"; + TextEdit te = te(0, 0, 28, 0, newText); + CodeAction ca = ca(uri, "Insert @jakarta.websocket.server.PathParam", d1, te); + JakartaForJavaAssert.assertJavaCodeAction(codeActionsParams, utils, ca); +// } } @Test From a1c53af9c38130d92bafd15a2c521c3e53e5da9c Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Mon, 9 Oct 2023 16:17:25 +0530 Subject: [PATCH 15/18] Added extension point for AddResourceMissingName and AddResourceMissingType quick fix Added extension point and enabled the tests --- .../AddResourceMissingNameQuickFix.java | 5 +++ .../AddResourceMissingTypeQuickFix.java | 5 +++ .../InsertAnnotationAttributesQuickFix.java | 8 +--- .../quickfix/InsertAnnotationQuickFix.java | 5 +-- src/main/resources/META-INF/plugin.xml | 10 +++++ .../annotations/ResourceAnnotationTest.java | 44 ++++++++++++++----- .../it/websocket/JakartaWebSocketTest.java | 15 ++++++- 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingNameQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingNameQuickFix.java index 82480dc58..59ef91d0d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingNameQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingNameQuickFix.java @@ -25,4 +25,9 @@ public class AddResourceMissingNameQuickFix extends InsertAnnotationAttributesQu public AddResourceMissingNameQuickFix() { super("jakarta.annotation.Resource", false, "name"); } + + @Override + public String getParticipantId() { + return AddResourceMissingNameQuickFix.class.getName(); + } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingTypeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingTypeQuickFix.java index 3a5beb446..a439ffa7d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingTypeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/annotations/AddResourceMissingTypeQuickFix.java @@ -26,4 +26,9 @@ public class AddResourceMissingTypeQuickFix extends InsertAnnotationAttributesQu public AddResourceMissingTypeQuickFix() { super("jakarta.annotation.Resource", false, "type"); } + + @Override + public String getParticipantId() { + return AddResourceMissingTypeQuickFix.class.getName(); + } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java index f02628348..d65a08d91 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationAttributesQuickFix.java @@ -20,7 +20,7 @@ * @author Lidia Ataupillco Ramos * */ -public class InsertAnnotationAttributesQuickFix extends InsertAnnotationQuickFix { +public abstract class InsertAnnotationAttributesQuickFix extends InsertAnnotationQuickFix { public InsertAnnotationAttributesQuickFix(String annotation, String... attributes) { this(annotation, false, attributes); } @@ -29,12 +29,8 @@ public InsertAnnotationAttributesQuickFix(String annotation, boolean generateOnl super(annotation, generateOnlyOneCodeAction, attributes); } - //@Override + @Override protected String getLabel(String annotation, String... attributes) { return Messages.getMessage("AddAtoB", attributes[0], annotation); } - @Override - public String getParticipantId() { - return InsertAnnotationAttributesQuickFix.class.getName(); - } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index e78810636..686e494fa 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -75,7 +75,6 @@ public List getCodeActions(JavaCodeActionContext context, PsiElement node = context.getCoveredNode(); List codeActions = new ArrayList<>(); addAttributes(diagnostic, context, codeActions, this.annotation); - return codeActions; } @@ -84,13 +83,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { final CodeAction toResolve = context.getUnresolved(); final PsiElement node = context.getCoveredNode(); - final PsiMethod parentMethod = PsiTreeUtil.getParentOfType(node, PsiMethod.class); PsiModifierListOwner binding = getBinding(node); PsiAnnotation annotationNode = PsiTreeUtil.getParentOfType(node, PsiAnnotation.class); - assert parentMethod != null; + assert binding != null; String label = getLabel(this.annotation, attributes); - ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), binding, annotationNode, 0, this.annotation, Arrays.asList(attributes)); try { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 5aab8e4fa..02b393cd1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -172,6 +172,16 @@ targetDiagnostic="jakarta-websocket#AddPathParamsAnnotation" implementationClass="io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.websocket.AddPathParamQuickFix"/> + + + + diff --git a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java index 118318a9b..eb079dd54 100644 --- a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java +++ b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java @@ -52,24 +52,44 @@ public void ResourceAnnotation() throws Exception { diagnosticsParams.setUris(Arrays.asList(uri)); // expected annotations - Diagnostic d1 = d(22, 0, 22, "The @Resource annotation must define the attribute 'type'.", + Diagnostic d1 = d(24, 0, 22, "The @Resource annotation must define the attribute 'type'.", DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceTypeAttribute"); - Diagnostic d2 = d(39, 0, 30, "The @Resource annotation must define the attribute 'name'.", + Diagnostic d2 = d(41, 0, 30, "The @Resource annotation must define the attribute 'name'.", DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceNameAttribute"); assertJavaDiagnostics(diagnosticsParams, utils, d1, d2); - if (CHECK_CODE_ACTIONS) { - JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); - TextEdit te = te(22, 0, 22, 22, "@Resource(name = \"aa\", type = \"\")"); - CodeAction ca = ca(uri, "Add type to jakarta.annotation.Resource", d1, te); - assertJavaCodeAction(codeActionParams, utils, ca); + //TODO: uncomment this if condition, once refactoring is done for all the quick fixes. +// if (CHECK_CODE_ACTIONS) { + JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); + String newText = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.Resource;" + + "\n\n@Resource(type = Object.class, name = \"aa\")\npublic class ResourceAnnotation {\n\n " + + "private Integer studentId;\n\n\n @Resource(shareable = true)\n " + + "private boolean isHappy;\n\n @Resource(name = \"test\")\n private boolean isSad;\n\n\n " + + "private String emailAddress;\n\n\n public ResourceAnnotation() {\n " + + "}\n}\n\n@Resource(name = \"aa\",type=\"\")\nclass PostDoctoralStudent {\n\n " + + "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + + "@Resource\n private boolean isSad;\n\n\n " + + "private String emailAddress;\n\n}\n\n@Resource(type = Object.class)\nclass MasterStudent {\n\n " + + "private Integer studentId;\n\n} \n"; + TextEdit te = te(0, 0, 47, 0, newText); + CodeAction ca = ca(uri, "Add type to jakarta.annotation.Resource", d1, te); + assertJavaCodeAction(codeActionParams, utils, ca); - JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); - TextEdit te1 = te(39, 0, 39, 30, "@Resource(type = \"\", name = \"\")"); - CodeAction ca1 = ca(uri, "Add name to jakarta.annotation.Resource", d2, te1); - assertJavaCodeAction(codeActionParams1, utils, ca1); - } + JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); + newText = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.Resource;" + + "\n\n@Resource(type = Object.class, name = \"aa\")\npublic class ResourceAnnotation {\n\n " + + "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + + "@Resource(name = \"test\")\n private boolean isSad;\n\n\n private String emailAddress;\n\n\n " + + "public ResourceAnnotation() {\n }\n}\n\n@Resource(name = \"aa\")\nclass PostDoctoralStudent {\n\n " + + "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + + "@Resource\n private boolean isSad;\n\n\n private String emailAddress;\n\n}\n\n" + + "@Resource(type = Object.class, name=\"\")\nclass MasterStudent {\n\n " + + "private Integer studentId;\n\n} \n"; + TextEdit te1 = te(0, 0, 47, 0, newText); + CodeAction ca1 = ca(uri, "Add name to jakarta.annotation.Resource", d2, te1); + assertJavaCodeAction(codeActionParams1, utils, ca1); +// } } } diff --git a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java index 813605436..c82baf304 100644 --- a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java +++ b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/websocket/JakartaWebSocketTest.java @@ -75,10 +75,21 @@ public void addPathParamsAnnotation() throws Exception { // if (CHECK_CODE_ACTIONS) { // Expected code actions JakartaJavaCodeActionParams codeActionsParams = createCodeActionParams(uri, d1); - String newText = "package io.openliberty.sample.jakarta.websocket;\n\nimport java.io.IOException;\n\nimport jakarta.websocket.OnClose;\nimport jakarta.websocket.OnOpen;\nimport jakarta.websocket.server.PathParam;import jakarta.websocket.server.ServerEndpoint;\nimport jakarta.websocket.Session;\n\n/**\n * Expected Diagnostics are related to validating that the parameters have the \n * valid annotation @PathParam (code: AddPathParamsAnnotation)\n * See issue #247 (onOpen) and #248 (onClose)\n */\n@ServerEndpoint(value = \"/infos\")\npublic class AnnotationTest {\n // @PathParam missing annotation for \"String missingAnnotation\"\n @OnOpen\n public void OnOpen(Session session, @PathParam(\"\") String missingAnnotation) throws IOException {\n System.out.println(\"Websocket opened: \" + session.getId().toString());\n }\n \n // Used to check that the expected diagnostic handle more than one case\n @OnClose\n public void OnClose(Session session, Integer missingAnnotation1, String missingAnnotation2) {\n System.out.println(\"Websocket opened: \" + session.getId().toString());\n }\n}\n"; + String newText = "package io.openliberty.sample.jakarta.websocket;\n\nimport java.io.IOException;" + + "\n\nimport jakarta.websocket.OnClose;\nimport jakarta.websocket.OnOpen;\n" + + "import jakarta.websocket.server.PathParam;import jakarta.websocket.server.ServerEndpoint;\n" + + "import jakarta.websocket.Session;\n\n/**\n * Expected Diagnostics are related to validating that the " + + "parameters have the \n * valid annotation @PathParam (code: AddPathParamsAnnotation)\n * " + + "See issue #247 (onOpen) and #248 (onClose)\n */\n@ServerEndpoint(value = \"/infos\")\n" + + "public class AnnotationTest {\n // @PathParam missing annotation for \"String missingAnnotation\"\n" + + " @OnOpen\n public void OnOpen(Session session, @PathParam(\"\") String missingAnnotation) " + + "throws IOException {\n System.out.println(\"Websocket opened: \" + session.getId().toString());" + + "\n }\n \n // Used to check that the expected diagnostic handle more than one case\n " + + "@OnClose\n public void OnClose(Session session, Integer missingAnnotation1, " + + "String missingAnnotation2) {\n System.out.println(\"Websocket opened: \" + " + + "session.getId().toString());\n }\n}\n"; TextEdit te = te(0, 0, 28, 0, newText); CodeAction ca = ca(uri, "Insert @jakarta.websocket.server.PathParam", d1, te); - JakartaForJavaAssert.assertJavaCodeAction(codeActionsParams, utils, ca); // } } From 0a1e86222bea383baad7f4685471e79d25b851e0 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Mon, 9 Oct 2023 16:23:07 +0530 Subject: [PATCH 16/18] Formatted the newly added code and added back the removed comment --- .../codeAction/proposal/quickfix/InsertAnnotationQuickFix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index 686e494fa..5646d3fa5 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -80,10 +80,10 @@ public List getCodeActions(JavaCodeActionContext context, @Override public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { - final CodeAction toResolve = context.getUnresolved(); final PsiElement node = context.getCoveredNode(); PsiModifierListOwner binding = getBinding(node); + // annotationNode is null when adding an annotation and non-null when adding attributes. PsiAnnotation annotationNode = PsiTreeUtil.getParentOfType(node, PsiAnnotation.class); assert binding != null; From b27b3c8f437fefe20f86d0ea80bff22af2cdcd68 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Thu, 12 Oct 2023 18:08:48 +0530 Subject: [PATCH 17/18] Revert "Merge remote-tracking branch 'upstream/main' into issue25_refactor_-InsertAnnotationQuickFix" This reverts commit a96dae401aa8d7d2ea4b8a2a0aef878804ca0919, reversing changes made to 0a1e86222bea383baad7f4685471e79d25b851e0. --- .../lsp/LibertyConfigLanguageServer.java | 14 +++++- .../liberty/lsp/LibertyXmlServer.java | 12 ++++- .../lsp/JakartaLanguageServer.java | 12 ++++- .../lsp4mp/lsp/MicroProfileServer.java | 13 ++++- .../ProcessStreamConnectionProvider.java | 49 ------------------- .../tools/intellij/util/Constants.java | 6 --- .../messages/LibertyBundles.properties | 6 --- 7 files changed, 43 insertions(+), 69 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java index f71485add..2d24bff00 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyConfigLanguageServer.java @@ -17,9 +17,11 @@ import io.openliberty.tools.intellij.util.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.io.File; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -31,10 +33,18 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider private static final Logger LOGGER = LoggerFactory.getLogger(LibertyConfigLanguageServer.class); public LibertyConfigLanguageServer() { - String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-jar-with-dependencies.jar"); - if(!isJavaHomeValid(javaHome, Constants.LIBERTY_CONFIG_SERVER)){ + String javaHome = System.getProperty("java.home"); + if (javaHome == null) { + LOGGER.error("Unable to launch the Liberty language server. Could not resolve the java home system property"); + return; + } + if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { + LOGGER.error("Unable to launch the Liberty language server." + + " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + + " Change the boot Java runtime of the IDE as documented here:" + + " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); return; } if (libertyServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java index d38e429b5..9015d752d 100644 --- a/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java +++ b/src/main/java/io/openliberty/tools/intellij/liberty/lsp/LibertyXmlServer.java @@ -32,11 +32,19 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(LibertyXmlServer.class); public LibertyXmlServer() { - String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar"); File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-jar-with-dependencies.jar"); - if(!isJavaHomeValid(javaHome, Constants.LIBERTY_XML_SERVER)){ + String javaHome = System.getProperty("java.home"); + if (javaHome == null) { + LOGGER.error("Unable to launch the LemMinX language server. Could not resolve the java home system property"); + return; + } + if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { + LOGGER.error("Unable to launch the LemMinX language server." + + " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + + " Change the boot Java runtime of the IDE as documented here:" + + " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); return; } if (lemminxServerPath.exists() && libertyServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java index f34f87747..6c5b6ec70 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp/JakartaLanguageServer.java @@ -31,10 +31,18 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(JakartaLanguageServer.class); public JakartaLanguageServer() { - String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR); - if(!isJavaHomeValid(javaHome, Constants.JAKARTA_LANG_SERVER)){ + String javaHome = System.getProperty("java.home"); + if (javaHome == null) { + LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server. Could not resolve the java home system property"); + return; + } + if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { + LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server." + + " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + + " Change the boot Java runtime of the IDE as documented here:" + + " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); return; } if (lsp4JakartaServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java index 59ba1b9ac..1989276b3 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp/MicroProfileServer.java @@ -13,6 +13,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.extensions.PluginId; +import io.openliberty.tools.intellij.liberty.lsp.LibertyXmlServer; import io.openliberty.tools.intellij.lsp4mp.lsp4ij.server.ProcessStreamConnectionProvider; import io.openliberty.tools.intellij.util.Constants; import org.slf4j.Logger; @@ -33,10 +34,18 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileServer.class); public MicroProfileServer() { - String javaHome = System.getProperty("java.home"); IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij")); File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); - if(!isJavaHomeValid(javaHome, Constants.MICROPROFILE_SERVER)){ + String javaHome = System.getProperty("java.home"); + if (javaHome == null) { + LOGGER.error("Unable to launch the Eclipse LSP4MP language server. Could not resolve the java home system property"); + return; + } + if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { + LOGGER.error("Unable to launch the Eclipse LSP4MP language server." + + " Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." + + " Change the boot Java runtime of the IDE as documented here:" + + " https://www.jetbrains.com/help/idea/switching-boot-jdk.html"); return; } if (lsp4mpServerPath.exists()) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java index 50c571e5d..741d548bf 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -1,18 +1,8 @@ package io.openliberty.tools.intellij.lsp4mp.lsp4ij.server; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationListener; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import io.openliberty.tools.intellij.LibertyPluginIcons; -import io.openliberty.tools.intellij.util.Constants; -import io.openliberty.tools.intellij.util.LocalizedResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import javax.annotation.Nullable; import java.io.*; import java.util.List; @@ -170,44 +160,5 @@ public String toString() { return "ProcessStreamConnectionProvider [commands=" + this.getCommands() + ", workingDir=" //$NON-NLS-1$//$NON-NLS-2$ + this.getWorkingDirectory() + "]"; //$NON-NLS-1$ } - public boolean isJavaHomeValid(String javaHome, String serverType) { - - if (javaHome == null) { - String errorMessage = LocalizedResourceUtil.getMessage("javaHome.is.null", serverType, Constants.REQUIRED_JAVA_VERSION); - LOGGER.error(errorMessage); - showErrorPopup(errorMessage); - return false; - } - - File javaHomeDir = new File(javaHome); - if (!javaHomeDir.exists()) { - String errorMessage = LocalizedResourceUtil.getMessage("javaHomeDir.does.not.exist", serverType, Constants.REQUIRED_JAVA_VERSION); - LOGGER.error(errorMessage); - showErrorPopup(errorMessage); - return false; - } - - if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) { - String errorMessage = LocalizedResourceUtil.getMessage("java.version.message", serverType, Constants.REQUIRED_JAVA_VERSION); - LOGGER.error(errorMessage); - showErrorPopup(errorMessage); - return false; - } - return true; - } - - private void notifyError(String errMsg, Project project) { - Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING) - .setTitle(LocalizedResourceUtil.getMessage("java.runtime.error.message")) - .setIcon(LibertyPluginIcons.libertyIcon) - .setSubtitle("") - .setListener(NotificationListener.URL_OPENING_LISTENER); - Notifications.Bus.notify(notif, project); - } - - private void showErrorPopup(String errorMessage) { - notifyError(errorMessage, ProjectManager.getInstance().getDefaultProject()); - - } } diff --git a/src/main/java/io/openliberty/tools/intellij/util/Constants.java b/src/main/java/io/openliberty/tools/intellij/util/Constants.java index 9f1ab01b3..b0a57e2f8 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/Constants.java +++ b/src/main/java/io/openliberty/tools/intellij/util/Constants.java @@ -86,10 +86,4 @@ public final class Constants { * Constants for langauge servers */ public static final String SERVER_ENV_GLOB_PATTERN = "**/{src/main/liberty/config,usr/servers/**}/server.env"; - - public static final String LIBERTY_XML_SERVER = "LemMinX"; - public static final String LIBERTY_CONFIG_SERVER="Liberty Config"; - public static final String JAKARTA_LANG_SERVER="Eclipse LSP4Jakarta"; - public static final String MICROPROFILE_SERVER="Eclipse LSP4MP"; - } diff --git a/src/main/resources/messages/LibertyBundles.properties b/src/main/resources/messages/LibertyBundles.properties index 7defa2fe7..09318b61a 100644 --- a/src/main/resources/messages/LibertyBundles.properties +++ b/src/main/resources/messages/LibertyBundles.properties @@ -51,12 +51,6 @@ liberty.project.file.selection.dialog.message=Select Liberty project for {0} liberty.action.selection.dialog.title=Liberty action liberty.action.selection.dialog.message=Select Liberty action to run -#Messages for Checking javaHome -javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here https://www.jetbrains.com/help/idea/switching-boot-jdk.html -java.runtime.error.message=Java runtime error - # Messages for Liberty add and remove project actions liberty.project.add=add Liberty project liberty.project.add.dialog.title=Add Liberty project From 1b5f461b6da599bd80644680cbb3ca4318c8d368 Mon Sep 17 00:00:00 2001 From: Aparna Michael Date: Tue, 17 Oct 2023 12:29:01 +0530 Subject: [PATCH 18/18] updated the resource annotation test --- .../annotations/ResourceAnnotationTest.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java index eb079dd54..de5e5fd9f 100644 --- a/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java +++ b/src/test/java/io/openliberty/tools/intellij/lsp4jakarta/it/annotations/ResourceAnnotationTest.java @@ -52,10 +52,10 @@ public void ResourceAnnotation() throws Exception { diagnosticsParams.setUris(Arrays.asList(uri)); // expected annotations - Diagnostic d1 = d(24, 0, 22, "The @Resource annotation must define the attribute 'type'.", + Diagnostic d1 = d(22, 0, 22, "The @Resource annotation must define the attribute 'type'.", DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceTypeAttribute"); - Diagnostic d2 = d(41, 0, 30, "The @Resource annotation must define the attribute 'name'.", + Diagnostic d2 = d(39, 0, 30, "The @Resource annotation must define the attribute 'name'.", DiagnosticSeverity.Error, "jakarta-annotations", "MissingResourceNameAttribute"); assertJavaDiagnostics(diagnosticsParams, utils, d1, d2); @@ -64,30 +64,32 @@ public void ResourceAnnotation() throws Exception { // if (CHECK_CODE_ACTIONS) { JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1); String newText = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.Resource;" + - "\n\n@Resource(type = Object.class, name = \"aa\")\npublic class ResourceAnnotation {\n\n " + + "\n\n@Resource(type = Object.class, name = \"aa\")\npublic class ResourceAnnotation " + + "{\n\n private Integer studentId;\n\n\n @Resource(shareable = true)\n " + + "private boolean isHappy;\n\n @Resource(name = \"test\")\n " + + " private boolean isSad;\n\n\n private String emailAddress;\n\n\n}\n\n" + + "@Resource(name = \"aa\",type=\"\")\nclass PostDoctoralStudent {\n\n " + "private Integer studentId;\n\n\n @Resource(shareable = true)\n " + - "private boolean isHappy;\n\n @Resource(name = \"test\")\n private boolean isSad;\n\n\n " + - "private String emailAddress;\n\n\n public ResourceAnnotation() {\n " + - "}\n}\n\n@Resource(name = \"aa\",type=\"\")\nclass PostDoctoralStudent {\n\n " + - "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + - "@Resource\n private boolean isSad;\n\n\n " + - "private String emailAddress;\n\n}\n\n@Resource(type = Object.class)\nclass MasterStudent {\n\n " + - "private Integer studentId;\n\n} \n"; - TextEdit te = te(0, 0, 47, 0, newText); + "private boolean isHappy;\n\n @Resource\n private boolean isSad;\n\n\n " + + "private String emailAddress;\n\n}\n\n@Resource(type = Object.class)\nclass " + + "MasterStudent {\n\n private Integer studentId;\n\n} \n"; + TextEdit te = te(0, 0, 45, 0, newText); CodeAction ca = ca(uri, "Add type to jakarta.annotation.Resource", d1, te); assertJavaCodeAction(codeActionParams, utils, ca); JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); - newText = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.Resource;" + - "\n\n@Resource(type = Object.class, name = \"aa\")\npublic class ResourceAnnotation {\n\n " + - "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + - "@Resource(name = \"test\")\n private boolean isSad;\n\n\n private String emailAddress;\n\n\n " + - "public ResourceAnnotation() {\n }\n}\n\n@Resource(name = \"aa\")\nclass PostDoctoralStudent {\n\n " + - "private Integer studentId;\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + - "@Resource\n private boolean isSad;\n\n\n private String emailAddress;\n\n}\n\n" + + newText = "package io.openliberty.sample.jakarta.annotations;\n\n" + + "import jakarta.annotation.Resource;\n\n@Resource(type = Object.class, " + + "name = \"aa\")\npublic class ResourceAnnotation {\n\n private Integer studentId;" + + "\n\n\n @Resource(shareable = true)\n private boolean isHappy;\n\n " + + "@Resource(name = \"test\")\n private boolean isSad;\n\n\n " + + "private String emailAddress;\n\n\n}\n\n@Resource(name = \"aa\")\n" + + "class PostDoctoralStudent {\n\n private Integer studentId;\n\n\n " + + "@Resource(shareable = true)\n private boolean isHappy;\n\n @Resource\n " + + "private boolean isSad;\n\n\n private String emailAddress;\n\n}\n\n" + "@Resource(type = Object.class, name=\"\")\nclass MasterStudent {\n\n " + "private Integer studentId;\n\n} \n"; - TextEdit te1 = te(0, 0, 47, 0, newText); + TextEdit te1 = te(0, 0, 45, 0, newText); CodeAction ca1 = ca(uri, "Add name to jakarta.annotation.Resource", d2, te1); assertJavaCodeAction(codeActionParams1, utils, ca1); // }