Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relax @Channel conditions for completion/validation #1344

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,16 +159,8 @@ 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;
}

/**
Expand Down Expand Up @@ -219,11 +210,9 @@ private void processChannelConnector(PsiModifierListOwner javaElement, PsiAnnota
String sourceType = getSourceType(javaElement);
String sourceMethod = null;
String sourceField = null;
if (javaElement instanceof PsiMethod) {
PsiMethod method = (PsiMethod) javaElement;
if (javaElement instanceof PsiMethod method) {
sourceMethod = getSourceMethod(method);
} else if (javaElement instanceof PsiField) {
PsiField field = (PsiField) javaElement;
} else if (javaElement instanceof PsiField field) {
sourceField = getSourceField(field);
}
boolean binary = isBinary(javaElement);
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();
if (pair.getValue() instanceof PsiArrayInitializerMemberValue connectorAttributeAnnotations) {
for (Object annotation : connectorAttributeAnnotations.getInitializers()) {
if (annotation instanceof PsiAnnotation) {
processConnectorAttribute(connectorName, (PsiAnnotation) annotation, sourceType, binary,
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
Loading