JvmAnnotationAttributeValue.getSourceElement is removed between 192.5728.98 -> 192.5728.98

已回答

Hello,

In the Apache Camel plug-in we have a feature that can look up a logical bean name reference between a camel route and a bean, this is done by searching for all classes annotated with the specific annotation and checking the value parameter match the logical bean name. Since the value can be a PsiReferenceExpressionImpl to a PSIField with the static name we use the JvmAnnotationAttributeValue.getSourceElement, but it is removed with 2019.2

https://github.com/JetBrains/intellij-community/commit/5af0561e6b2cd673fedffea423afef71d836b1eb#diff-f6378aa9ac9a4ce1a89b0d4561e935a1

@Repository(value = CompleteJavaSpringRepositoryBeanTestData.JAVA_REPOSITORY_TEST_BEAN)
public class CompleteJavaSpringRepositoryBeanTestData {

static public String JAVA_REPOSITORY_TEST_BEAN = "myRepositoryBean";
...
}

This is how we do it today :

final PsiAnnotation classAnnotation = psiClass.getAnnotation(annotation);
final JvmAnnotationAttribute attribute = classAnnotation.findAttribute("value");
if (attribute != null) {
final PsiElement sourceElement = attribute.getAttributeValue().getSourceElement();
if (sourceElement instanceof PsiReferenceExpressionImpl) {
final PsiField psiField = (PsiField) sourceElement.getReference().resolve();

Since the "JvmAnnotationAttributeValue.getSourceElement" is removed, I am looking for another way to achieve this. 

Thanks,

Flemming 

0
正式评论

Hi, sorry for removal of these methods, this API is incomplete (experimental) and this particular method was incorrect.

Please use

PsiAnnotationMemberValue value = classAnnotation.findAttributeValue("value");
if (value instanceof PsiReferenceExpressionImpl) { ... }

Thanks, it works perfectly

0

请先登录再写评论。