how to add javadoc to PsiMethod programatically
Hi, i'm creating a javadoc comment for a method like this:
PsiMethod theMethod= psiClass.findMethodBySignature(factoriedTestMethod, false);
String commentText = "/**\n" +
"* @see FooBar#zas()\n" +
"* @verifies do nothing\n" +
"*/";
PsiDocComment psiDocComment = elementFactory.createDocCommentFromText(commentText, null);
psiClass.addBefore(psiDocComment, theMethod);
but it unit testing code, this theMethod.getDocComment() is returning null...
So which is the right way to add javadoc comment to PsiMethod?
Please sign in to leave a comment.
Hello Jaime,
You're adding the doc comment to the class between the methods, which is
an invalid PSI structure. You need to add the doc comment to the method itself.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
I got it in this way, the thing I wasn't aware about was the method.getFirstChild().
String commentText = "/**\n" +
"* @see " + methodQualifiedName + "\n" +
"* @verifies " + description + "\n" +
"*/";
PsiComment psiComment = elementFactory.createCommentFromText(commentText, null);
method.addBefore(psiComment, method.getFirstChild());