Skip to content

Commit

Permalink
Support for MicroProfile RestClient/Health Diagnostics
Browse files Browse the repository at this point in the history
Fixes redhat-developer#217

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Feb 28, 2020
1 parent 1e0c715 commit a7ac0e1
Show file tree
Hide file tree
Showing 63 changed files with 2,846 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
pluginName=JDT MicroProfile Extension
providerName=Red Hat
propertiesProviders.name=MicroProfile properties providers extension
javaFeatureParticipants.name=Java features participants for MicroProfile
projectLabelProviders.name=Project label providers extension
19 changes: 16 additions & 3 deletions microprofile.jdt/com.redhat.microprofile.jdt.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<extension-point id="propertiesProviders"
name="%propertiesProviders.name"
schema="schema/propertiesProviders.exsd" />
<extension-point id="projectLabelProviders" name="%projectLabelProviders.name" schema="schema/projectLabelProviders.exsd"/>
<extension-point id="javaFeatureParticipants"
name="%javaFeatureParticipants.name"
schema="schema/javaFeatureParticipants.exsd" />
<extension-point id="projectLabelProviders"
name="%projectLabelProviders.name"
schema="schema/projectLabelProviders.exsd"/>

<!-- Delegate command handler for application.properties file -->
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
Expand All @@ -20,6 +25,7 @@
<delegateCommandHandler class="com.redhat.microprofile.jdt.internal.core.ls.MicroProfileDelegateCommandHandlerForJava">
<command id="microprofile/java/codeLens"/>
<command id="microprofile/java/hover"/>
<command id="microprofile/java/diagnostics"/>
</delegateCommandHandler>
</extension>

Expand All @@ -34,9 +40,16 @@
<!-- Properties provider from the MicroProfile @ConfigProperty annotation -->
<provider class="com.redhat.microprofile.jdt.internal.core.providers.MicroProfileConfigPropertyProvider" />
<!-- Properties provider from the MicroProfile Fault Tolerance annotations -->
<provider class="com.redhat.microprofile.jdt.internal.core.providers.MicroProfileFaultToleranceProvider" />
<provider class="com.redhat.microprofile.jdt.internal.faulttolerance.properties.MicroProfileFaultToleranceProvider" />
<!-- Properties provider from the MicroProfile @RegisterRestClient annotation -->
<provider class="com.redhat.microprofile.jdt.internal.core.providers.MicroProfileRegisterRestClientProvider" />
<provider class="com.redhat.microprofile.jdt.internal.restclient.properties.MicroProfileRegisterRestClientProvider" />
</extension>

<extension point="com.redhat.microprofile.jdt.core.javaFeatureParticipants">
<!-- Java diagnostics for the MicroProfile Health -->
<diagnostics class="com.redhat.microprofile.jdt.internal.health.java.MicroProfileHealthDiagnosticsParticipant" />
<!-- Java diagnostics for the MicroProfile RestClient -->
<diagnostics class="com.redhat.microprofile.jdt.internal.restclient.java.MicroProfileRestClientDiagnosticsParticipant" />
</extension>

<extension point="com.redhat.microprofile.jdt.core.projectLabelProviders">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="com.redhat.microprofile.jdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="com.redhat.microprofile.jdt.core" id="javaFeatureParticipants" name="Java features participants"/>
</appinfo>
<documentation>
This extension point allows adding a Java feature (codelens, hover, diagnostics) to consume it in the Java editor.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<choice>
<element ref="diagnostics"/>
</choice>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="diagnostics">
<annotation>
<documentation>
Java diagnostics participant.
</documentation>
</annotation>
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Name of a class that implements IJavaDiagnosticsParticipant.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":com.redhat.microprofile.jdt.core.java.IJavaDiagnosticsParticipant"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
2.0
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
The following is an example of a java feature participant extension:

&lt;pre&gt;
&lt;extension point=&quot;com.redhat.quarkus.jdt.core.javaFeatureParticipants&quot;&gt;
&lt;diagnostics
class=&quot;com.example.MyJavaDiagnosticsParticipant&quot;&gt;
&lt;/diagnostics&gt;
&lt;/extension&gt;
&lt;/pre&gt;
</documentation>
</annotation>




</schema>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="com.redhat.quarkus.jdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<schema targetNamespace="com.redhat.microprofile.jdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="com.redhat.quarkus.jdt.core" id="propertiesProviders" name="Properties providers"/>
<meta.schema plugin="com.redhat.microprofile.jdt.core" id="propertiesProviders" name="Properties providers"/>
</appinfo>
<documentation>
This extension point allows adding a properties provider to provide capability to collect MicroProfile/Quarkus properties from Java libraries and sources.
Expand Down Expand Up @@ -84,7 +84,7 @@
The following is an example of a properties provider extension:

&lt;pre&gt;
&lt;extension point=&quot;com.redhat.quarkus.jdt.core.propertiesProvider&quot;&gt;
&lt;extension point=&quot;com.redhat.microprofile.jdt.core.propertiesProvider&quot;&gt;
&lt;provider
class=&quot;com.example.MyPropertyProvider&quot;&gt;
&lt;/provider&gt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package com.redhat.microprofile.commons;

/**
* Quarkus Java codelens parameters.
* MicroProfile Java codelens parameters.
*
* @author Angelo ZERR
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.microprofile.commons;

import java.util.List;

/**
* MicroProfile Java diagnostics parameters.
*
* @author Angelo ZERR
*
*/
public class MicroProfileJavaDiagnosticsParams {

private List<String> uris;

private DocumentFormat documentFormat;

public MicroProfileJavaDiagnosticsParams() {
this(null);
}

public MicroProfileJavaDiagnosticsParams(List<String> uris) {
setUris(uris);
}

/**
* Returns the java file uris list.
*
* @return the java file uris list.
*/
public List<String> getUris() {
return uris;
}

/**
* Set the java file uris list.
*
* @param uris the java file uris list.
*/
public void setUris(List<String> uris) {
this.uris = uris;
}

public DocumentFormat getDocumentFormat() {
return documentFormat;
}

public void setDocumentFormat(DocumentFormat documentFormat) {
this.documentFormat = documentFormat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import org.eclipse.lsp4j.Range;

/**
* Quarkus Hover Information
* MicroProfile Hover Information
*
* This class represents the return object for the
* <code>quarkus.java.hover</code> command
* <code>microprofile/java/hover</code> command
*/
public class MicroProfileJavaHoverInfo {

Expand All @@ -25,6 +25,7 @@ public class MicroProfileJavaHoverInfo {

/**
* Creates a new <code>QuarkusJavaHoverInfo</code> object
*
* @param propertyKey the property key being hovered
* @param propertyValue the property value of the property key being hovered
* @param range the range of the property key being hovered
Expand All @@ -34,7 +35,7 @@ public MicroProfileJavaHoverInfo(String propertyKey, String propertyValue, Range
this.propertyValue = propertyValue;
this.range = range;
}

/**
* Returns the property key
*
Expand All @@ -43,9 +44,10 @@ public MicroProfileJavaHoverInfo(String propertyKey, String propertyValue, Range
public String getPropertyKey() {
return propertyKey;
}

/**
* Returns the property value for the property key
*
* @return the property value for the property key
*/
public String getPropertyValue() {
Expand All @@ -54,6 +56,7 @@ public String getPropertyValue() {

/**
* Returns the range of the property key
*
* @return the range of the property key
*/
public Range getRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.eclipse.lsp4j.Position;

/**
* Quarkus Java codelens parameters.
* MicroProfile Java codelens parameters.
*
* @author Angelo ZERR
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class MicroProfileConstants {
private MicroProfileConstants() {
}

public static final String INJECT_ANNOTATION = "javax.inject.Inject";

// MicroProfile Core annotations

public static final String CONFIG_PROPERTY_ANNOTATION = "org.eclipse.microprofile.config.inject.ConfigProperty";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static com.redhat.microprofile.jdt.core.utils.AnnotationUtils.getAnnotation;
import static com.redhat.microprofile.jdt.core.utils.AnnotationUtils.getAnnotationMemberValue;
import static com.redhat.microprofile.jdt.core.utils.AnnotationUtils.hasAnnotation;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -39,15 +40,21 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.util.Ranges;

import com.redhat.microprofile.commons.DocumentFormat;
import com.redhat.microprofile.commons.MicroProfileJavaCodeLensParams;
import com.redhat.microprofile.commons.MicroProfileJavaDiagnosticsParams;
import com.redhat.microprofile.commons.MicroProfileJavaHoverInfo;
import com.redhat.microprofile.commons.MicroProfileJavaHoverParams;
import com.redhat.microprofile.jdt.core.java.JavaDiagnosticsContext;
import com.redhat.microprofile.jdt.core.project.JDTMicroProfileProjectManager;
import com.redhat.microprofile.jdt.core.utils.IJDTUtils;
import com.redhat.microprofile.jdt.internal.core.java.JavaFeaturesRegistry;

/**
* JDT quarkus manager for Java files.
Expand Down Expand Up @@ -210,7 +217,7 @@ private static String getJaxRsPathValue(IAnnotatable annotatable) throws JavaMod
}

private static boolean isJaxRsRequestMethod(IAnnotatable annotatable) throws JavaModelException {
return getAnnotation(annotatable, JAVAX_WS_RS_GET_ANNOTATION) != null;
return hasAnnotation(annotatable, JAVAX_WS_RS_GET_ANNOTATION);
}

private boolean overlaps(ISourceRange typeRange, ISourceRange methodRange) {
Expand Down Expand Up @@ -315,4 +322,40 @@ public MicroProfileJavaHoverInfo hover(MicroProfileJavaHoverParams params, IJDTU
return null;
}

/**
* Returns diagnostics for the given uris list.
*
* @param params the diagnostics parameters
* @param utils the utilities class
* @return diagnostics for the given uris list.
* @throws JavaModelException
*/
public List<PublishDiagnosticsParams> diagnostics(MicroProfileJavaDiagnosticsParams params, IJDTUtils utils,
IProgressMonitor monitor) throws JavaModelException {
List<String> uris = params.getUris();
if (uris == null) {
return Collections.emptyList();
}
DocumentFormat documentFormat = params.getDocumentFormat();
List<PublishDiagnosticsParams> publishDiagnostics = new ArrayList<PublishDiagnosticsParams>();
for (String uri : uris) {
List<Diagnostic> diagnostics = new ArrayList<>();
PublishDiagnosticsParams publishDiagnostic = new PublishDiagnosticsParams(uri, diagnostics);
publishDiagnostics.add(publishDiagnostic);
collectDiagnostics(uri, utils, documentFormat, diagnostics, monitor);
}
return publishDiagnostics;
}

private void collectDiagnostics(String uri, IJDTUtils utils, DocumentFormat documentFormat,
List<Diagnostic> diagnostics, IProgressMonitor monitor) {
ITypeRoot typeRoot = resolveTypeRoot(uri, utils, monitor);
if (typeRoot == null) {
return;
}
JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, documentFormat, diagnostics);
JavaFeaturesRegistry.getInstance().getJavaFeatureDefinitions()
.forEach(definition -> definition.collectDiagnostics(context, monitor));
}

}
Loading

0 comments on commit a7ac0e1

Please sign in to comment.