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.

5 comments
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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

0
Comment actions Permalink

Like this?


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

0

Please sign in to leave a comment.