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?

2 comments

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.

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?

---
Original message URL:
http://devnet.jetbrains.net/message/5277012#5277012


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

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());

0

Please sign in to leave a comment.