Looking up annotations

How do I look up annotations on a class or method? I can figure out if a given PsiClass is an annotation, but I also need to be able to look up the annotations specified on a given field/method/class.

0
Avatar
Permanently deleted user

Hani Suleiman wrote:

How do I look up annotations on a class or method? I can figure out if a given PsiClass is an annotation, but I also need to be able to look up the annotations specified on a given field/method/class.


Annotations are part of an element's ModifierList. Take a look at
com.intellij.codeInsight.AnnotationUtil for more info.

HTH,
Sascha

0
Avatar
Permanently deleted user

Once I have a PsiAnnotationMemberValue, how go I get the value itself?

Say I have an annotation with a boolean value... how do I query the value as a boolean?  My hack way currently is toString it and check endsWith "false" :-(

0

Check if the PsiAnnotationMemberValue is a PsiLiteral, and if it is, call the getValue() method on it.

0
Avatar
Permanently deleted user

Like this?


PsiAnnotationMemberValue miniCheck = psiAnno.findAttributeValue("minifyName");
 if (miniCheck instanceof PsiLiteral)
 { PsiLiteral miniCheckLiteral = (PsiLiteral) miniCheck;
  mini = (Boolean)miniCheckLiteral.getValue();
 }

0

Yes.

0

请先登录再写评论。