Skip to content

Commit

Permalink
bug: relax @channel conditions for completion/validation
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jun 24, 2024
1 parent 7641f57 commit 4dfd086
Showing 1 changed file with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<double> pricesEmitter;
if (isAnnotatingEmitterObject(psiElement)) {
if (isChannelField(psiElement)) {
processIncomingChannel(psiElement, mprmAnnotation, context);
processOutgoingChannel(psiElement, mprmAnnotation, context);
}
break;
Expand All @@ -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 :
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4dfd086

Please sign in to comment.