From 97a09bfa87dfdae446ab30929a564e88b807a11f Mon Sep 17 00:00:00 2001 From: azerr Date: Wed, 9 Oct 2024 17:00:40 +0200 Subject: [PATCH] fix: REST endpoint code vision hint is not resolving a public static final and quarkus.rest.path parameter Fixes #1393 Signed-off-by: azerr --- .../psi/core/utils/AnnotationUtils.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/utils/AnnotationUtils.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/utils/AnnotationUtils.java index 1093b2c90..2b7de07af 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/utils/AnnotationUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/utils/AnnotationUtils.java @@ -10,16 +10,13 @@ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils; import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.PsiAnnotationMemberValue; -import com.intellij.psi.PsiAnnotationOwner; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiModifierListOwner; +import com.intellij.psi.*; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.util.Ranges; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -34,6 +31,8 @@ */ public class AnnotationUtils { + private static final Logger log = LoggerFactory.getLogger(AnnotationUtils.class); + /** * Returns checks if the annotatable parameter is annotated with the given annotation. * @@ -173,12 +172,27 @@ public static boolean isMatchAnnotation(PsiAnnotation annotation, String annotat * @return the value of the given member name of the given annotation. */ public static String getAnnotationMemberValue(PsiAnnotation annotation, String memberName) { - PsiAnnotationMemberValue member = getAnnotationMemberValueExpression(annotation, memberName); - String value = member != null && member.getText() != null ? member.getText() : null; - if (value != null && value.length() > 1 && value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') { - value = value.substring(1, value.length() - 1); + PsiElement member = getAnnotationMemberValueExpression(annotation, memberName); + if (member == null) { + return null; + } + if (member instanceof PsiReference reference) { + // ex: @Path(MY_CONSTANTS) where MY_CONSTANTS is a Java field. + member = reference.resolve(); + } + if (member instanceof PsiField field) { + // ex: private static final String MY_CONSTANTS = "foo"; + member = field.getInitializer(); + } + if (member == null) { + return null; + } + if (member instanceof PsiLiteralExpression literalExpression) { + // ex : @Path("foo") --> foo + return literalExpression.getText(); } - return value; + // Other cases? + return member.getText(); } public static PsiAnnotationMemberValue getAnnotationMemberValueExpression(PsiAnnotation annotation, String memberName) {