Need help on PsiDocComment Permanently deleted user Created June 30, 2004 12:05 Any idea as to how to create a new PsiDocComment object and replace the exsiting PsiDocComment object with the new one.Any help would be appreciatedRegardsRuchir Awadhawal
Ruchir Awadhawal wrote:
Well, I am afraid there is no direct way at the moment, however the
following should work:
1. Create bogus method with your doc comment using
PsiElementFactory.createMethodFromText():
2. Use bogusMethod.getDocComment() to obtain a PsiDocComment
3. Add it/replace with it wherever you want
Hope this helps,
Cheers,
Dmitry
--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"
I am the writer of the to-string plugin and it has a feature to add/replace javadoc on the toString method.
Here is some code from my plugin. You can download the source from http://www.intellij.org/twiki/bin/view/Main/ToStringPlugin
/Claus
not be replaced. * @throws IncorrectOperationException is thrown if error adding/replacing the javadoc comment. * @since 2.14 */ public PsiComment addOrReplaceJavadoc(PsiElementFactory factory, PsiMethod method, String javadoc, boolean replace) throws IncorrectOperationException { PsiComment comment = factory.createCommentFromText(javadoc, null); // does a method already exists? if (method.getDocComment() != null) { if (replace) { // javadoc already exists, so replace method.getDocComment().replace(comment); return comment; } else { // do not relace existing javadoc return null; } } else { // add new javadoc method.addBefore(comment, method.getFirstChild()); return comment; } } ]]>