How to create a PsiAnnotation?

I'm writing an intention action which annotates elements with appropriate classes, depending on the context. However, I can't figure, how I can, out of a given PsiClass, create a PsiAnnotation and apply it to a class field or method parameter. How can I do this? I'm fine with just inserting a String into the document, it would be nice to have a PsiAnnotation added to ModifierList though.


On the class' ModifierList call com.intellij.psi.PsiModifierList#addAnnotation


You can use JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("com.example.AnnoName")


Please sign in to leave a comment.