Search in sources :

Example 21 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GrDocCommentUtil method setDocComment.

public static GrDocComment setDocComment(@NotNull GrDocCommentOwner owner, @Nullable GrDocComment comment) {
    GrDocComment docComment = owner.getDocComment();
    if (docComment != null) {
        if (comment == null) {
            docComment.delete();
            return null;
        } else {
            PsiElement added = docComment.replace(comment);
            assert added instanceof GrDocComment;
            return (GrDocComment) added;
        }
    } else {
        if (comment == null)
            return null;
        PsiElement parent = owner.getParent();
        ASTNode node = owner.getNode();
        parent.getNode().addLeaf(GroovyTokenTypes.mNLS, "\n ", node);
        PsiElement added = parent.addBefore(comment, owner);
        assert added instanceof GrDocComment;
        return (GrDocComment) added;
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Example 22 with GrDocComment

use of org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment in project intellij-community by JetBrains.

the class GrDocTagImpl method setName.

@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
    final PsiElement nameElement = getNameElement();
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
    final GrDocComment comment = factory.createDocCommentFromText("/** @" + name + "*/");
    nameElement.replace(comment.getTags()[0].getNameElement());
    return this;
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) PsiElement(com.intellij.psi.PsiElement) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)

Aggregations

GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)22 PsiElement (com.intellij.psi.PsiElement)9 GrDocCommentOwner (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner)8 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 Nullable (org.jetbrains.annotations.Nullable)4 GrDocTag (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag)4 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)3 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)3 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)3 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)3 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)3 ASTNode (com.intellij.lang.ASTNode)2 Document (com.intellij.openapi.editor.Document)2 PsiComment (com.intellij.psi.PsiComment)2 PsiFile (com.intellij.psi.PsiFile)2 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2