Skip to content

Commit

Permalink
fix: REST endpoint code vision hint is not resolving a public static
Browse files Browse the repository at this point in the history
final and quarkus.rest.path parameter

Fixes #1393

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 9, 2024
1 parent f3946a0 commit 97a09bf
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +31,8 @@
*/
public class AnnotationUtils {

private static final Logger log = LoggerFactory.getLogger(AnnotationUtils.class);

/**
* Returns checks if the <code>annotatable</code> parameter is annotated with the given annotation.
*
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 97a09bf

Please sign in to comment.