From 4dfd0868a523f5172efe88d333dd1c5e1534f05c Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Mon, 24 Jun 2024 11:12:52 +0200 Subject: [PATCH] bug: relax @Channel conditions for completion/validation Signed-off-by: Fred Bricon --- ...MicroProfileReactiveMessagingProvider.java | 56 +++++++------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java index 92b739b1a..ddd90eb1f 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/reactivemessaging/properties/MicroProfileReactiveMessagingProvider.java @@ -18,7 +18,6 @@ import com.intellij.psi.PsiNameValuePair; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.AbstractAnnotationTypeReferencePropertiesProvider; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.SearchContext; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.lsp4mp.commons.metadata.ItemHint; import org.eclipse.lsp4mp.commons.metadata.ValueHint; @@ -33,7 +32,6 @@ import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ANNOTATION; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTES_ANNOTATION; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTE_ANNOTATION; -import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.EMITTER_CLASS; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.INCOMING_ANNOTATION; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.OUTGOING_ANNOTATION; @@ -102,11 +100,11 @@ public class MicroProfileReactiveMessagingProvider extends AbstractAnnotationTyp 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; } @@ -141,11 +139,12 @@ protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation // public double process(int priceInUsd) { processIncomingChannel(psiElement, mprmAnnotation, context); break; - case CHANNEL_ANNOTATION: + case CHANNEL_ANNOTATION: //Used for both incoming and outgoing channels // @Inject // @Channel("prices") // Emitter pricesEmitter; - if (isAnnotatingEmitterObject(psiElement)) { + if (isChannelField(psiElement)) { + processIncomingChannel(psiElement, mprmAnnotation, context); processOutgoingChannel(psiElement, mprmAnnotation, context); } break; @@ -160,17 +159,9 @@ protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation } } - private static boolean isAnnotatingEmitterObject(PsiElement element) { - if (!(element instanceof PsiField)) { - return false; - } - PsiField field = (PsiField) element; - String typeSignature = PsiTypeUtils.getResolvedTypeName(field); - if (typeSignature == null) { - return false; - } - return typeSignature.startsWith(EMITTER_CLASS); - } + private static boolean isChannelField(PsiElement element) { + return element instanceof PsiField; + } /** * Generate static property for incoming connector (ex : @@ -219,12 +210,10 @@ private void processChannelConnector(PsiModifierListOwner javaElement, PsiAnnota String sourceType = getSourceType(javaElement); String sourceMethod = null; String sourceField = null; - if (javaElement instanceof PsiMethod) { - PsiMethod method = (PsiMethod) javaElement; - sourceMethod = getSourceMethod(method); - } else if (javaElement instanceof PsiField) { - PsiField field = (PsiField) javaElement; - sourceField = getSourceField(field); + if (javaElement instanceof PsiMethod method) { + sourceMethod = getSourceMethod(method); + } else if (javaElement instanceof PsiField field) { + sourceField = getSourceField(field); } boolean binary = isBinary(javaElement); String description = null; @@ -261,11 +250,10 @@ private void processConnector(PsiModifierListOwner javaElement, PsiAnnotation co processConnectorAttribute(connectorName, connectorAttributeAnnotation, sourceType, binary, context); } else if (isMatchAnnotation(connectorAttributeAnnotation, CONNECTOR_ATTRIBUTES_ANNOTATION)) { for (PsiNameValuePair pair : connectorAttributeAnnotation.getParameterList().getAttributes()) { - if (pair.getValue() instanceof PsiArrayInitializerMemberValue) { - PsiArrayInitializerMemberValue connectorAttributeAnnotations = (PsiArrayInitializerMemberValue) pair.getValue(); - for (Object annotation : connectorAttributeAnnotations.getInitializers()) { - if (annotation instanceof PsiAnnotation) { - processConnectorAttribute(connectorName, (PsiAnnotation) annotation, sourceType, binary, + if (pair.getValue() instanceof PsiArrayInitializerMemberValue connectorAttributeAnnotations) { + for (Object annotation : connectorAttributeAnnotations.getInitializers()) { + if (annotation instanceof PsiAnnotation psiAnnotation) { + processConnectorAttribute(connectorName, psiAnnotation, sourceType, binary, context); } } @@ -363,13 +351,11 @@ private String getType(String connectorAttributeType) { if (StringUtils.isEmpty(connectorAttributeType)) { return null; } - switch (connectorAttributeType) { - case "string": - return "java.lang.String"; - default: - return connectorAttributeType; - } - } + if (connectorAttributeType.equals("string")) { + return "java.lang.String"; + } + return connectorAttributeType; + } private static String getMPMessagingName(MessageType messageType, boolean dynamic, String connectorOrChannelName, String attributeName) {