Getting an anchorElement for the FileTemplate when using createClass

I have a plugin that in some point creates a new class (using the JavaPsiFacade for this)

The new class created would have a custom annotation inserted to it, and I'm using the Class PsiElement to add
the new annotation after its created, I'm using the addBefore method, with no anchor element.

The Problem is that the annotation appear before the FileTemplate documentations and it's kinda ugly and naturally
not resides with regular coding...it kinda ends up looking like so:

import com.idi.anno.AnnoRef; @AnnoRef(refId = "CustomValue1") /** * Created with IntelliJ IDEA. * User: Eldad-Dor * Date: 9/23/13 * Time: 8:46 PM * To change this template use File | Settings | File Templates. */ public class CommonQuery2T { }



Is there any way to get the JavaDoc or Text created by the FileTemplate as a PsiElement to be used as an anchor
so I can add my custom annotation after it?

3 comments

This is not a correct way to add annotations; you'll end up with a broken PSI structure. The correct way is to use PsiClass.getModifierList().addAnnotation(). The fact that the class was created by a file template is irrelevant here; the PSI structure does not depend on this.

0

Thanks for the quick reply...simple and stright answer as always, works great!

0

Similiar question asked here http://devnet.jetbrains.com/thread/449462?tstart=0
Two questions down from yours :)

0

Please sign in to leave a comment.