Having trouble using PSI to insert javadoc comment
The company I work for has a very special javadoc comment style. So, I was trying to write a plugin to generate the shell of these comments. Basically, I find the PSIElement that I want to put the comment on, and then call element.addBefore(element.getFirstChild(), newComment) (if no comment previously existed). But I keep getting IllegalArgumentExceptions from addBefore(). I was putting the comment here because if I manually add the comment, and use PSIViewer to look at the structure, the comment is the first child of the method. Any thoughts?
Please sign in to leave a comment.
I found my problem, the order of arguments to addBefore() was incorrect. I thought I had seen this order work previously, but I guess not.
Would you be willing to share your plugin? My company also has a special format for javadoc comments.
When I get it working I will consider it. Shouldn't be a problem.
Kathryn,
If you still want my code (I've released it to my team without any complaints...yet!), let me know. I can attach the source here in this message thread (I don't want to put it on the Twiki because it's definitely not generally useful stuff).
John,
Yes, I'd still like the code. Many thanks!
Kathryn
Kathryn,
Here you go (I hope I do the attachment correctly). Included is a build.xml and a plugin.xml. I made a quick pass through to remove all references to my company name (I did this in my off time and therefore don't want this not-so-great and not-so-commented code to reflect on my company). Please note that the method comment code in particular is quite complex, but is mostly needed to handle the really strange formatting of comments that we use.
Lastly, I've got a small code-folding thing to fold the first comment in a file (were our license comment goes). The CodeFolder plugin is really a better solution, and I will probably have my team switch to it at a later date.
Hope this is useful to you,
John Murph
Attachment(s):
GreenTools.zip