From 0790343a64fb3fb9931ae949436da6626e64de1f Mon Sep 17 00:00:00 2001 From: Michael Glavassevich Date: Tue, 15 Aug 2023 13:40:30 -0400 Subject: [PATCH 1/2] Proof-of-concept for unifying the design for MicroProfile and Jakarta EE diagnostics. Signed-off-by: Michael Glavassevich --- .../lsp4ij/AbstractDiagnosticsCollector.java | 26 ++++- .../lsp4ij/PropertiesManagerForJakarta.java | 88 ++++----------- .../psi/core/PropertiesManagerForJava.java | 59 +--------- .../java/diagnostics/DiagnosticsHandler.java | 102 ++++++++++++++++++ .../IJavaDiagnosticsParticipant.java | 2 - .../JavaDiagnosticsDefinition.java | 95 ++++++++++++++++ src/main/resources/META-INF/plugin.xml | 59 +++++++++- 7 files changed, 299 insertions(+), 132 deletions(-) create mode 100644 src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/DiagnosticsHandler.java create mode 100644 src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java index 13b8f35c7..f5527c09b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java @@ -13,12 +13,16 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaDiagnosticsParticipant; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.Range; @@ -28,7 +32,7 @@ * Abstract class for collecting Java diagnostics. * */ -public class AbstractDiagnosticsCollector implements DiagnosticsCollector { +public abstract class AbstractDiagnosticsCollector implements DiagnosticsCollector, IJavaDiagnosticsParticipant { /** * Constructor @@ -84,6 +88,25 @@ protected Diagnostic createDiagnostic(PsiElement el, PsiJavaFile unit, String ms return diagnostic; } + /** + * Collect diagnostics according to the context. + * + * @param context the java diagnostics context + * + * @return diagnostics list and null otherwise. + * + */ + @Override + public final List collectDiagnostics(JavaDiagnosticsContext context) { + PsiFile typeRoot = context.getTypeRoot(); + if (typeRoot instanceof PsiJavaFile) { + List diagnostics = new ArrayList<>(); + collectDiagnostics((PsiJavaFile) typeRoot, diagnostics); + return diagnostics; + } + return Collections.emptyList(); + } + /** * Returns diagnostics for the given compilation unit. * @@ -301,4 +324,5 @@ protected static String getSimpleName(String fqName) { protected static boolean isConstructorMethod(PsiMethod m) { return m.isConstructor(); } + } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java index dd3fa994e..ab2cd428d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020,2022 Red Hat, Inc. + * Copyright (c) 2020,2023 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, @@ -12,44 +12,30 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij; -import com.intellij.lang.jvm.JvmTypeDeclaration; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.module.Module; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.annotations.AnnotationDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.beanvalidation.BeanValidationDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.cdi.ManagedBeanDiagnosticsCollector; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.JakartaCodeActionHandler; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.di.DependencyInjectionDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs.Jax_RSClassDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs.ResourceMethodDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jsonb.JsonbDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jsonp.JsonpDiagnosticCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.persistence.PersistenceEntityDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.persistence.PersistenceMapKeyDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.FilterDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.ListenerDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet.ServletDiagnosticsCollector; -import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.websocket.WebSocketDiagnosticsCollector; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.DiagnosticsHandler; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; -import org.eclipse.lsp4j.*; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.PublishDiagnosticsParams; import org.eclipse.lsp4jakarta.commons.*; -import org.eclipse.lsp4mp.commons.*; +import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; +import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -65,25 +51,13 @@ public static PropertiesManagerForJakarta getInstance() { return INSTANCE; } - private List diagnosticsCollectors = new ArrayList<>(); private JakartaCodeActionHandler codeActionHandler = new JakartaCodeActionHandler(); + private final DiagnosticsHandler diagnosticsHandler; + private PropertiesManagerForJakarta() { - diagnosticsCollectors.add(new ServletDiagnosticsCollector()); - diagnosticsCollectors.add(new AnnotationDiagnosticsCollector()); - diagnosticsCollectors.add(new FilterDiagnosticsCollector()); - diagnosticsCollectors.add(new ListenerDiagnosticsCollector()); - diagnosticsCollectors.add(new BeanValidationDiagnosticsCollector()); - diagnosticsCollectors.add(new PersistenceEntityDiagnosticsCollector()); - diagnosticsCollectors.add(new PersistenceMapKeyDiagnosticsCollector()); - diagnosticsCollectors.add(new ResourceMethodDiagnosticsCollector()); - diagnosticsCollectors.add(new Jax_RSClassDiagnosticsCollector()); - diagnosticsCollectors.add(new JsonbDiagnosticsCollector()); - diagnosticsCollectors.add(new ManagedBeanDiagnosticsCollector()); - diagnosticsCollectors.add(new DependencyInjectionDiagnosticsCollector()); - diagnosticsCollectors.add(new JsonpDiagnosticCollector()); - diagnosticsCollectors.add(new WebSocketDiagnosticsCollector()); codeActionHandler = new JakartaCodeActionHandler(); + diagnosticsHandler = new DiagnosticsHandler("jakarta"); } /** @@ -94,40 +68,7 @@ private PropertiesManagerForJakarta() { * @return diagnostics for the given uris list. */ public List diagnostics(JakartaDiagnosticsParams params, IPsiUtils utils) { - List uris = params.getUris(); - if (uris == null) { - return Collections.emptyList(); - } - DocumentFormat documentFormat = params.getDocumentFormat(); - List publishDiagnostics = new ArrayList(); - for (String uri : uris) { - List diagnostics = new ArrayList<>(); - PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics); - publishDiagnostics.add(publishDiagnostic); - collectDiagnostics(uri, utils, documentFormat, diagnostics); - } - return publishDiagnostics; - } - - private void collectDiagnostics(String uri, IPsiUtils utils, DocumentFormat documentFormat, List diagnostics) { - PsiFile typeRoot = ApplicationManager.getApplication().runReadAction((Computable) () -> resolveTypeRoot(uri, utils)); - if (typeRoot == null) { - return; - } - - try { - if (typeRoot instanceof PsiJavaFile) { - Module module = ApplicationManager.getApplication().runReadAction((ThrowableComputable) () -> utils.getModule(uri)); - DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> { - PsiJavaFile unit = (PsiJavaFile) typeRoot; - for (DiagnosticsCollector collector : diagnosticsCollectors) { - collector.collectDiagnostics(unit, diagnostics); - } - }); - } - } catch (IOException e) { - LOGGER.warn(e.getLocalizedMessage(), e); - } + return diagnosticsHandler.collectDiagnostics(adapt(params), utils); } /** @@ -408,4 +349,11 @@ public List getCodeAction(JakartaJavaCodeActionParams params, IPsiUt return codeActionHandler.codeAction(params, utils); }); } + + private MicroProfileJavaDiagnosticsParams adapt(JakartaDiagnosticsParams params) { + MicroProfileJavaDiagnosticsParams mpParams = new MicroProfileJavaDiagnosticsParams(params.getUris(), + new MicroProfileJavaDiagnosticsSettings(Collections.emptyList())); + mpParams.setDocumentFormat(params.getDocumentFormat()); + return mpParams; + } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java index 25592fe70..aca74db75 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java @@ -14,10 +14,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.module.Module; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.project.DumbService; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; @@ -27,6 +24,7 @@ import com.intellij.psi.PsiModifierListOwner; import com.intellij.psi.PsiParameter; import com.intellij.psi.util.PsiTreeUtil; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.DiagnosticsHandler; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codelens.IJavaCodeLensParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codelens.JavaCodeLensContext; @@ -34,8 +32,6 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.completion.JavaCompletionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.definition.IJavaDefinitionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.definition.JavaDefinitionContext; -import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaDiagnosticsParticipant; -import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.hover.IJavaHoverParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.hover.JavaHoverContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.codeaction.CodeActionHandler; @@ -51,10 +47,8 @@ import org.eclipse.lsp4mp.commons.MicroProfileJavaCompletionParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDefinitionParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; -import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings; import org.eclipse.lsp4mp.commons.MicroProfileJavaFileInfoParams; import org.eclipse.lsp4mp.commons.MicroProfileJavaHoverParams; -import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.PublishDiagnosticsParams; @@ -86,8 +80,11 @@ public static PropertiesManagerForJava getInstance() { private final CodeActionHandler codeActionHandler; + private final DiagnosticsHandler diagnosticsHandler; + private PropertiesManagerForJava() { this.codeActionHandler = new CodeActionHandler(); + this.diagnosticsHandler = new DiagnosticsHandler("mp"); } /** @@ -285,53 +282,7 @@ private void collectDefinition(String uri, PsiFile typeRoot, PsiElement hyperlin * @return diagnostics for the given uris list. */ public List diagnostics(MicroProfileJavaDiagnosticsParams params, IPsiUtils utils) { - List uris = params.getUris(); - if (uris == null) { - return Collections.emptyList(); - } - DocumentFormat documentFormat = params.getDocumentFormat(); - List publishDiagnostics = new ArrayList(); - for (String uri : uris) { - List diagnostics = new ArrayList<>(); - PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics); - publishDiagnostics.add(publishDiagnostic); - collectDiagnostics(uri, utils, documentFormat, params.getSettings(), diagnostics); - } - return publishDiagnostics; - } - - private void collectDiagnostics(String uri, IPsiUtils utils, DocumentFormat documentFormat, - MicroProfileJavaDiagnosticsSettings settings, List diagnostics) { - PsiFile typeRoot = ApplicationManager.getApplication().runReadAction((Computable) () -> resolveTypeRoot(uri, utils)); - if (typeRoot == null) { - return; - } - - try { - Module module = ApplicationManager.getApplication().runReadAction((ThrowableComputable) () -> utils.getModule(uri)); - DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> { - // Collect all adapted diagnostics participant - JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, module, documentFormat, settings); - List definitions = IJavaDiagnosticsParticipant.EP_NAME.extensions() - .filter(definition -> definition.isAdaptedForDiagnostics(context)) - .collect(Collectors.toList()); - if (definitions.isEmpty()) { - return; - } - - // Begin, collect, end participants - definitions.forEach(definition -> definition.beginDiagnostics(context)); - definitions.forEach(definition -> { - List collectedDiagnostics = definition.collectDiagnostics(context); - if (collectedDiagnostics != null && !collectedDiagnostics.isEmpty()) { - diagnostics.addAll(collectedDiagnostics); - } - }); - definitions.forEach(definition -> definition.endDiagnostics(context)); - }); - } catch (IOException e) { - LOGGER.warn(e.getLocalizedMessage(), e); - } + return diagnosticsHandler.collectDiagnostics(params, utils); } /** diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/DiagnosticsHandler.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/DiagnosticsHandler.java new file mode 100644 index 000000000..66736fa23 --- /dev/null +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/DiagnosticsHandler.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2020, 2023 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ + +package io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.DumbService; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.psi.PsiFile; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.corrections.JavaDiagnosticsDefinition; +import org.eclipse.lsp4j.Diagnostic; +import org.eclipse.lsp4j.PublishDiagnosticsParams; +import org.eclipse.lsp4mp.commons.DocumentFormat; +import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; +import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class DiagnosticsHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(DiagnosticsHandler.class); + + private final String group; + + public DiagnosticsHandler(String group) { + this.group = group; + } + + public List collectDiagnostics(MicroProfileJavaDiagnosticsParams params, IPsiUtils utils) { + List uris = params.getUris(); + if (uris == null) { + return Collections.emptyList(); + } + DocumentFormat documentFormat = params.getDocumentFormat(); + List publishDiagnostics = new ArrayList<>(); + for (String uri : uris) { + List diagnostics = new ArrayList<>(); + PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics); + publishDiagnostics.add(publishDiagnostic); + collectDiagnostics(uri, utils, documentFormat, params.getSettings(), diagnostics); + } + return publishDiagnostics; + } + + private void collectDiagnostics(String uri, IPsiUtils utils, DocumentFormat documentFormat, + MicroProfileJavaDiagnosticsSettings settings, List diagnostics) { + PsiFile typeRoot = ApplicationManager.getApplication().runReadAction((Computable) () -> resolveTypeRoot(uri, utils)); + if (typeRoot == null) { + return; + } + + try { + Module module = ApplicationManager.getApplication().runReadAction((ThrowableComputable) () -> utils.getModule(uri)); + DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> { + // Collect all adapted diagnostic definitions + JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, module, documentFormat, settings); + List definitions = JavaDiagnosticsDefinition.EP_NAME.extensions() + .filter(definition -> definition.isAdaptedForDiagnostics(context)) + .filter(definition -> group.equals(definition.getGroup())) + .collect(Collectors.toList()); + if (definitions.isEmpty()) { + return; + } + + // Begin, collect, end participants + definitions.forEach(definition -> definition.beginDiagnostics(context)); + definitions.forEach(definition -> { + List collectedDiagnostics = definition.collectDiagnostics(context); + if (collectedDiagnostics != null && !collectedDiagnostics.isEmpty()) { + diagnostics.addAll(collectedDiagnostics); + } + }); + definitions.forEach(definition -> definition.endDiagnostics(context)); + }); + } catch (IOException e) { + LOGGER.warn(e.getLocalizedMessage(), e); + } + } + + // REVISIT: Make this a public method on a common utility class? + private static PsiFile resolveTypeRoot(String uri, IPsiUtils utils) { + return utils.resolveCompilationUnit(uri); + } +} diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java index e0a088802..dafdd5627 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java @@ -25,8 +25,6 @@ */ public interface IJavaDiagnosticsParticipant { - public static final ExtensionPointName EP_NAME = ExtensionPointName.create("open-liberty.intellij.javaDiagnosticsParticipant"); - /** * Returns true if diagnostics must be collected for the given context and false * otherwise. diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java new file mode 100644 index 000000000..2707be06e --- /dev/null +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2020, 2023 Red Hat Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ + +package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.corrections; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.serviceContainer.BaseKeyedLazyInstance; +import com.intellij.util.xmlb.annotations.Attribute; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaDiagnosticsParticipant; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; +import org.eclipse.lsp4j.Diagnostic; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Wrapper class around {@link IJavaDiagnosticsParticipant} participants. + */ +public final class JavaDiagnosticsDefinition extends BaseKeyedLazyInstance + implements IJavaDiagnosticsParticipant { + + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("open-liberty.intellij.javaDiagnosticsParticipant"); + + private static final Logger LOGGER = Logger.getLogger(JavaDiagnosticsDefinition.class.getName()); + private static final String GROUP_ATTR = "group"; + private static final String IMPLEMENTATION_CLASS_ATTR = "implementationClass"; + + @Attribute(GROUP_ATTR) + private String group; + + @Attribute(IMPLEMENTATION_CLASS_ATTR) + public String implementationClass; + + @Override + public boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context) { + try { + return getInstance().isAdaptedForDiagnostics(context); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Error while calling isAdaptedForDiagnostics", e); + return false; + } + } + + @Override + public void beginDiagnostics(JavaDiagnosticsContext context) { + try { + getInstance().beginDiagnostics(context); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e); + } + } + + @Override + public List collectDiagnostics(JavaDiagnosticsContext context) { + try { + List diagnostics = getInstance().collectDiagnostics(context); + return diagnostics != null ? diagnostics : Collections.emptyList(); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e); + return Collections.emptyList(); + } + } + + @Override + public void endDiagnostics(JavaDiagnosticsContext context) { + try { + getInstance().endDiagnostics(context); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e); + } + } + + public @Nullable String getGroup() { + return group; + } + + @Override + protected @Nullable String getImplementationClassName() { + return implementationClass; + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 03ae52655..c9b7c6a46 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -35,7 +35,7 @@ + beanClass="io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.corrections.JavaDiagnosticsDefinition"/> + + group="mp" + implementationClass="io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.validators.JavaASTDiagnosticsParticipant"/> + group="mp" + implementationClass="io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.health.java.MicroProfileHealthDiagnosticsParticipant"/> + group="mp" + implementationClass="io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.restclient.java.MicroProfileRestClientDiagnosticsParticipant"/> + group="mp" + implementationClass="io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.metrics.java.MicroProfileMetricsDiagnosticsParticipant"/> + + + + + + + + + + + + + + + + From c680d1f88ca68b8d5d18e7ff0654be239f690ad0 Mon Sep 17 00:00:00 2001 From: Michael Glavassevich Date: Thu, 21 Sep 2023 14:29:00 -0400 Subject: [PATCH 2/2] Updating copyrights and cleaning up imports. Signed-off-by: Michael Glavassevich --- .../lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java | 2 +- .../lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java | 2 +- .../lsp4mp4ij/psi/core/PropertiesManagerForJava.java | 2 +- .../core/java/diagnostics/IJavaDiagnosticsParticipant.java | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java index f5527c09b..638278b24 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AbstractDiagnosticsCollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2022 IBM Corporation and others. + * Copyright (c) 2022, 2023 IBM Corporation and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java index ab2cd428d..8e5887edf 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/PropertiesManagerForJakarta.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020,2023 Red Hat, Inc. + * Copyright (c) 2020, 2023 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java index aca74db75..18f3f5e0d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 Red Hat, Inc. + * Copyright (c) 2020, 2023 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java index dafdd5627..52d0976f7 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/diagnostics/IJavaDiagnosticsParticipant.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020 Red Hat Inc. and others. +* Copyright (c) 2020, 2023 Red Hat Inc. and others. * All rights reserved. This program and the accompanying materials * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html @@ -11,11 +11,10 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics; -import java.util.List; - -import com.intellij.openapi.extensions.ExtensionPointName; import org.eclipse.lsp4j.Diagnostic; +import java.util.List; + /** * Java diagnostics participants API. *