| 1 | /* |
|---|---|
| 2 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
| 3 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
| 4 | * |
| 5 | * This file is part of JavaParser. |
| 6 | * |
| 7 | * JavaParser can be used either under the terms of |
| 8 | * a) the GNU Lesser General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * b) the terms of the Apache License |
| 12 | * |
| 13 | * You should have received a copy of both licenses in LICENCE.LGPL and |
| 14 | * LICENCE.APACHE. Please refer to those files for details. |
| 15 | * |
| 16 | * JavaParser is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU Lesser General Public License for more details. |
| 20 | */ |
| 21 | package com.github.javaparser.ast.comments; |
| 22 | |
| 23 | import com.github.javaparser.ast.AllFieldsConstructor; |
| 24 | import com.github.javaparser.ast.visitor.GenericVisitor; |
| 25 | import com.github.javaparser.ast.visitor.VoidVisitor; |
| 26 | import com.github.javaparser.javadoc.Javadoc; |
| 27 | import com.github.javaparser.ast.Node; |
| 28 | import com.github.javaparser.ast.visitor.CloneVisitor; |
| 29 | import com.github.javaparser.metamodel.JavadocCommentMetaModel; |
| 30 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
| 31 | import com.github.javaparser.TokenRange; |
| 32 | import java.util.function.Consumer; |
| 33 | import java.util.Optional; |
| 34 | import com.github.javaparser.ast.Generated; |
| 35 | import static com.github.javaparser.StaticJavaParser.parseJavadoc; |
| 36 | |
| 37 | /** |
| 38 | * A Javadoc comment. {@code /** a comment */} |
| 39 | * |
| 40 | * @author Julio Vilmar Gesser |
| 41 | */ |
| 42 | public class JavadocComment extends Comment { |
| 43 | |
| 44 | public JavadocComment() { |
| 45 | this(null, "empty"); |
| 46 | } |
| 47 | |
| 48 | @AllFieldsConstructor |
| 49 | public JavadocComment(String content) { |
| 50 | this(null, content); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * This constructor is used by the parser and is considered private. |
| 55 | */ |
| 56 | @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
| 57 | public JavadocComment(TokenRange tokenRange, String content) { |
| 58 | super(tokenRange, content); |
| 59 | customInitialization(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
| 64 | public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
| 65 | return v.visit(this, arg); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
| 70 | public <A> void accept(final VoidVisitor<A> v, final A arg) { |
| 71 | v.visit(this, arg); |
| 72 | } |
| 73 | |
| 74 | public Javadoc parse() { |
| 75 | return parseJavadoc(getContent()); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
| 80 | public boolean remove(Node node) { |
| 81 | if (node == null) |
| 82 | return false; |
| 83 | return super.remove(node); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
| 88 | public JavadocComment clone() { |
| 89 | return (JavadocComment) accept(new CloneVisitor(), null); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
| 94 | public JavadocCommentMetaModel getMetaModel() { |
| 95 | return JavaParserMetaModel.javadocCommentMetaModel; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
| 100 | public boolean replace(Node node, Node replacementNode) { |
| 101 | if (node == null) |
| 102 | return false; |
| 103 | return super.replace(node, replacementNode); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 108 | public boolean isJavadocComment() { |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 114 | public JavadocComment asJavadocComment() { |
| 115 | return this; |
| 116 | } |
| 117 | |
| 118 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 119 | public void ifJavadocComment(Consumer<JavadocComment> action) { |
| 120 | action.accept(this); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 125 | public Optional<JavadocComment> toJavadocComment() { |
| 126 | return Optional.of(this); |
| 127 | } |
| 128 | } |
| 129 |
Members