how to change content for PsiDocTag

Hi I have a method like this one, and I want to modify the content for the @should tag.


/**
     * @should zas
     */
    void b() {

    }

It becomes

/**
      * @should new content
      */
     void b() {

    }


How could I get this? I'm trying something like but it isn't very user pleasnt because it disorders tags.

        PsiDocTag newVerifiesDocTag = JavaPsiFacade.getElementFactory(tag.getProject()).createDocTagFromText("@" + tag.getName() + " " + newContents);
        PsiDocComment containingComment = tag.getContainingComment();
        containingComment.deleteChildRange(tag, tag);
        containingComment.add(newVerifiesDocTag);

1 comment
Comment actions Permalink

Hello Jaime,

Try the replace() method instead of deleteChildRange() and add()?

Hi I have a method like this one, and I want to modify the content for
the @should tag.

/**

  • @should zas

*/
void b() {
}

It becomes

/**

  • @should new content

*/
void b() {
}

How could I get this? I'm trying something like but it isn't very user
pleasnt because it disorders tags.

PsiDocTag newVerifiesDocTag =
JavaPsiFacade.getElementFactory(tag.getProject()).createDocTagFromText
("@" + tag.getName() + " " + newContents);
PsiDocComment containingComment = tag.getContainingComment();
containingComment.deleteChildRange(tag, tag);
containingComment.add(newVerifiesDocTag);


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


0

Please sign in to leave a comment.