@Nullable public static GrDocComment findDocComment(GrDocCommentOwner owner) { if (owner.getFirstChild() instanceof GrDocComment) { return ((GrDocComment) owner.getFirstChild()); } PsiElement element = owner instanceof GrVariable && owner.getParent() instanceof GrVariableDeclaration ? owner.getParent() : owner; element = skipWhiteSpacesAndStopOnDoc(element, false); if (element instanceof GrDocComment) return (GrDocComment) element; return null; }
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; } }