Looking up annotations Follow
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.
Please sign in to leave a comment.
Hani Suleiman wrote:
Annotations are part of an element's ModifierList. Take a look at
com.intellij.codeInsight.AnnotationUtil for more info.
HTH,
Sascha
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" :-(
Check if the PsiAnnotationMemberValue is a PsiLiteral, and if it is, call the getValue() method on it.
Like this?
PsiAnnotationMemberValue miniCheck = psiAnno.findAttributeValue("minifyName");
if (miniCheck instanceof PsiLiteral)
{ PsiLiteral miniCheckLiteral = (PsiLiteral) miniCheck;
mini = (Boolean)miniCheckLiteral.getValue();
}
Yes.