Generating a DocComment on a method
I've written a new inspection that detects when a field's javadoc is present and the corresponding getter and setter javadoc are not present.
The quickfix copies javadoc from field's own javadoc to the accessors.
I have this basic functionality working but i would like to go a little further and have param and return tags generated as well.
Is there a way to call the IDEA function that generates javadoc skeleton when typing /** and pressing the Enter key before the method declaration ?
Gilles Philippart
请先登录再写评论。
Hello Gilles,
GP> Is there a way to call the IDEA function that generates javadoc
GP> skeleton when typing /** and pressing the Enter key before the
GP> method declaration ?
There is no such way, but the IDEA logic for this is very simple and easy
to reproduce in your plugin.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Okay then, is there a way to create instances of PsiDocToken then ? i only found methods to create PsiComment, PsiDocElement, and PsiDocTag in PsiElementFactory.
Until now, i've used factory.createCommentFromText("/** " + (getter ? "Returns " : "Sets ") + "some javadoc" + "*/", method) but the resulting javadoc isn't automatically formatted.
Gilles Philippart
Hello Gilles,
GP> Okay then, is there a way to create instances of PsiDocToken then ?
GP> i only found methods to create PsiComment, PsiDocElement, and
GP> PsiDocTag in PsiElementFactory.
GP>
GP> Until now, i've used factory.createCommentFromText("/** " + (getter
GP> ? "Returns " : "Sets ") + "some javadoc" + "*/", method) but the
GP> resulting javadoc isn't automatically formatted.
IDEA builds the JavaDoc comment as simple text.
To get the comment to format correctly, you need to call CodeStyleManager.reformat()
explicitly, with a text range that includes the method to which the comment
is attached.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
I?m writing a plugin for generating javadoc comments for every uncommented
element (field, method, inner class, etc) in a java source file.
Everything is fine and working but when I try to add the comment in the file
it takes a long of time, so commenting every element in the file takes a
couple minutes.
The code I use to add the comment is:
psiDocCommentOwner.addBefore(docComment,
psiDocCommentOwner.getFirstChild());
where
. psiDocCommentOwner is the element for which I?m adding the comment
. docComment is the javadoc comment generated with
PsiElementFactory.createDocCommentFromText()
Is there another way to do this ?
"Dmitry Jemerov (JetBrains)" <yole@jetbrains.com> escribio en el mensaje
news:83ca25fd25ab818c7e8d4e5faae50@news.intellij.net...
>
>
>
>
>