From 87eb9cf7eab72918962ee26f56ac379c5d9b8f6d Mon Sep 17 00:00:00 2001 From: azerr Date: Wed, 10 Jul 2024 23:01:32 +0200 Subject: [PATCH] Unrecognized property mp.messaging.* when Channel annotation is used along with Multi Fixes https://github.com/redhat-developer/vscode-quarkus/issues/750 Signed-off-by: azerr --- ...MicroProfileReactiveMessagingProvider.java | 63 ++++++++----------- .../src/main/java/org/acme/kafka/Quote.java | 5 ++ .../java/org/acme/kafka/QuoteResource.java | 11 ++++ .../src/main/resources/application.properties | 4 +- .../MicroProfileReactiveMessagingTest.java | 9 ++- 5 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/Quote.java create mode 100644 microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/QuoteResource.java diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java index 6628a1559..c5556f286 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java @@ -21,7 +21,6 @@ import static org.eclipse.lsp4mp.jdt.core.utils.JDTTypeUtils.isBinary; import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CHANNEL_ANNOTATION; import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ANNOTATION; -import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.EMITTER_CLASS; import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTES_ANNOTATION; import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTE_ANNOTATION; import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.INCOMING_ANNOTATION; @@ -40,7 +39,6 @@ import org.eclipse.lsp4mp.commons.metadata.ValueHint; import org.eclipse.lsp4mp.jdt.core.AbstractAnnotationTypeReferencePropertiesProvider; import org.eclipse.lsp4mp.jdt.core.SearchContext; -import org.eclipse.lsp4mp.jdt.core.utils.JDTTypeUtils; /** * Properties provider to collect MicroProfile properties from the MicroProfile @@ -104,13 +102,14 @@ */ public class MicroProfileReactiveMessagingProvider extends AbstractAnnotationTypeReferencePropertiesProvider { - private static final String[] ANNOTATION_NAMES = { CONNECTOR_ANNOTATION, INCOMING_ANNOTATION, OUTGOING_ANNOTATION, CHANNEL_ANNOTATION }; + private static final String[] ANNOTATION_NAMES = { CONNECTOR_ANNOTATION, INCOMING_ANNOTATION, OUTGOING_ANNOTATION, + CHANNEL_ANNOTATION }; - private static enum Direction { + private enum Direction { INCOMING, OUTGOING, INCOMING_AND_OUTGOING; } - private static enum MessageType { + private enum MessageType { INCOMING, OUTGOING, CONNECTOR; } @@ -145,11 +144,11 @@ protected void processAnnotation(IJavaElement javaElement, IAnnotation mprmAnnot // public double process(int priceInUsd) { processIncomingChannel(javaElement, mprmAnnotation, context); break; - case CHANNEL_ANNOTATION: + case CHANNEL_ANNOTATION: // Used for both incoming and outgoing channels // @Inject // @Channel("prices") // Emitter pricesEmitter; - if (isAnnotatingEmitterObject(javaElement)) { + if (isChannelField(javaElement)) { processOutgoingChannel(javaElement, mprmAnnotation, context); } break; @@ -164,16 +163,8 @@ protected void processAnnotation(IJavaElement javaElement, IAnnotation mprmAnnot } } - private static boolean isAnnotatingEmitterObject(IJavaElement element) { - if (element.getElementType() != IJavaElement.FIELD) { - return false; - } - IField field = (IField) element; - String typeSignature = JDTTypeUtils.getResolvedTypeName(field); - if (typeSignature == null) { - return false; - } - return typeSignature.startsWith(EMITTER_CLASS); + private static boolean isChannelField(IJavaElement element) { + return element.getElementType() == IJavaElement.FIELD; } /** @@ -238,8 +229,8 @@ private void processChannelConnector(IJavaElement javaElement, IAnnotation incom boolean binary = isBinary(javaElement); String description = null; String type = "org.eclipse.microprofile.reactive.messaging.spi.Connector"; - addMpMessagingItem(channelName, false, "connector", messageType, sourceType, sourceField, sourceMethod, binary, type, - description, null, context); + addMpMessagingItem(channelName, false, "connector", messageType, sourceType, sourceField, sourceMethod, binary, + type, description, null, context); } /** @@ -310,34 +301,34 @@ private void processConnectorAttribute(String connectorName, IAnnotation connect case INCOMING: // Generate mp.messaging.incoming.${connector-name}.[attribute] // ex : mp.messaging.incoming.${smallrye-kafka}.topic - addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, type, - description, defaultValue, context); + addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, + type, description, defaultValue, context); break; case OUTGOING: // Generate mp.messaging.outgoing.${connector-name}.[attribute] - addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, type, - description, defaultValue, context); + addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, + type, description, defaultValue, context); break; case INCOMING_AND_OUTGOING: // Generate mp.messaging.incoming.${connector-name}.[attribute] - addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, type, - description, defaultValue, context); + addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, + type, description, defaultValue, context); // Generate mp.messaging.outgoing.${connector-name}.[attribute] - addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, type, - description, defaultValue, context); + addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, + type, description, defaultValue, context); break; } // Generate mp.messaging.connector.[connector-name].[attribute] - addMpMessagingItem(connectorName, false, attributeName, MessageType.CONNECTOR, sourceType, null, null, binary, type, - description, defaultValue, context); + addMpMessagingItem(connectorName, false, attributeName, MessageType.CONNECTOR, sourceType, null, null, binary, + type, description, defaultValue, context); } private void addMpMessagingItem(String connectorOrChannelName, boolean dynamic, String attributeName, - MessageType messageType, String sourceType, String sourceField, String sourceMethod, boolean binary, String type, - String description, String defaultValue, SearchContext context) { + MessageType messageType, String sourceType, String sourceField, String sourceMethod, boolean binary, + String type, String description, String defaultValue, SearchContext context) { String propertyName = getMPMessagingName(messageType, dynamic, connectorOrChannelName, attributeName); - super.addItemMetadata(context.getCollector(), propertyName, type, description, sourceType, sourceField, sourceMethod, - defaultValue, null, binary); + super.addItemMetadata(context.getCollector(), propertyName, type, description, sourceType, sourceField, + sourceMethod, defaultValue, null, binary); } /** @@ -373,12 +364,10 @@ private String getType(String connectorAttributeType) { if (StringUtils.isEmpty(connectorAttributeType)) { return null; } - switch (connectorAttributeType) { - case "string": + if (connectorAttributeType.equals("string")) { return "java.lang.String"; - default: - return connectorAttributeType; } + return connectorAttributeType; } private static String getMPMessagingName(MessageType messageType, boolean dynamic, String connectorOrChannelName, diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/Quote.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/Quote.java new file mode 100644 index 000000000..9d4f77ef5 --- /dev/null +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/Quote.java @@ -0,0 +1,5 @@ +package org.acme.kafka; + +public class Quote { + +} diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/QuoteResource.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/QuoteResource.java new file mode 100644 index 000000000..3c9aed42b --- /dev/null +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/java/org/acme/kafka/QuoteResource.java @@ -0,0 +1,11 @@ +package org.acme.kafka; + +import io.smallrye.mutiny.Multi; +import org.eclipse.microprofile.reactive.messaging.Channel; + +public class QuoteResource { + + @Channel("quotes") + Multi quotes; + +} diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/resources/application.properties b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/resources/application.properties index 41812d429..a19a5c229 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/resources/application.properties +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/microprofile-reactive-messaging/src/main/resources/application.properties @@ -5,4 +5,6 @@ mp.messaging.outgoing.generated-price.value.serializer=org.apache.kafka.common.s # Configure the Kafka source (we read from it) mp.messaging.incoming.prices.connector=smallrye-kafka -mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer \ No newline at end of file +mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer + +mp.messaging.outgoing.quotes.connector=smallrye-kafka diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/reactivemessaging/properties/MicroProfileReactiveMessagingTest.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/reactivemessaging/properties/MicroProfileReactiveMessagingTest.java index 22765f38d..dd3938de9 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/reactivemessaging/properties/MicroProfileReactiveMessagingTest.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/reactivemessaging/properties/MicroProfileReactiveMessagingTest.java @@ -85,9 +85,14 @@ public void microprofileReactiveMessagingPropertiesTest() throws Exception { // mp.messaging.incoming.${connector-name} p(null, "mp.messaging.incoming.${smallrye-kafka}.bootstrap.servers", "java.lang.String", "A comma-separated list of host:port to use for establishing the initial connection to the Kafka cluster.", - true, "io.smallrye.reactive.messaging.kafka.KafkaConnector", null, null, 0, "localhost:9092") // + true, "io.smallrye.reactive.messaging.kafka.KafkaConnector", null, null, 0, "localhost:9092"), + + // mp.messaging.outgoing.quotes.connector + p(null, "mp.messaging.outgoing.quotes.connector", + "org.eclipse.microprofile.reactive.messaging.spi.Connector", null, false, + "org.acme.kafka.QuoteResource", "quotes", null, 0, null) // ); - + assertPropertiesDuplicate(infoFromClasspath); assertHints(infoFromClasspath, h("${mp.messaging.connector.binary}", null, true, null, //