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.ast.Node; |
27 | import com.github.javaparser.ast.visitor.CloneVisitor; |
28 | import com.github.javaparser.metamodel.LineCommentMetaModel; |
29 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
30 | import com.github.javaparser.TokenRange; |
31 | import java.util.function.Consumer; |
32 | import java.util.Optional; |
33 | import com.github.javaparser.ast.Generated; |
34 | |
35 | /** |
36 | * <p> |
37 | * AST node that represent line comments. |
38 | * </p> |
39 | * Line comments start with "//" and finish at the end of the line ("\n"). |
40 | * |
41 | * @author Julio Vilmar Gesser |
42 | */ |
43 | public class LineComment extends Comment { |
44 | |
45 | public LineComment() { |
46 | this(null, "empty"); |
47 | } |
48 | |
49 | @AllFieldsConstructor |
50 | public LineComment(String content) { |
51 | this(null, content); |
52 | } |
53 | |
54 | /** |
55 | * This constructor is used by the parser and is considered private. |
56 | */ |
57 | @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
58 | public LineComment(TokenRange tokenRange, String content) { |
59 | super(tokenRange, content); |
60 | customInitialization(); |
61 | } |
62 | |
63 | @Override |
64 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
65 | public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
66 | return v.visit(this, arg); |
67 | } |
68 | |
69 | @Override |
70 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
71 | public <A> void accept(final VoidVisitor<A> v, final A arg) { |
72 | v.visit(this, arg); |
73 | } |
74 | |
75 | @Override |
76 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
77 | public boolean isLineComment() { |
78 | return true; |
79 | } |
80 | |
81 | @Override |
82 | @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
83 | public boolean remove(Node node) { |
84 | if (node == null) |
85 | return false; |
86 | return super.remove(node); |
87 | } |
88 | |
89 | @Override |
90 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
91 | public LineComment clone() { |
92 | return (LineComment) accept(new CloneVisitor(), null); |
93 | } |
94 | |
95 | @Override |
96 | @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
97 | public LineCommentMetaModel getMetaModel() { |
98 | return JavaParserMetaModel.lineCommentMetaModel; |
99 | } |
100 | |
101 | @Override |
102 | @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
103 | public boolean replace(Node node, Node replacementNode) { |
104 | if (node == null) |
105 | return false; |
106 | return super.replace(node, replacementNode); |
107 | } |
108 | |
109 | @Override |
110 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
111 | public LineComment asLineComment() { |
112 | return this; |
113 | } |
114 | |
115 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
116 | public void ifLineComment(Consumer<LineComment> action) { |
117 | action.accept(this); |
118 | } |
119 | |
120 | @Override |
121 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
122 | public Optional<LineComment> toLineComment() { |
123 | return Optional.of(this); |
124 | } |
125 | } |
126 |
Members