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.body; |
22 | |
23 | import com.github.javaparser.ast.AllFieldsConstructor; |
24 | import com.github.javaparser.ast.Modifier; |
25 | import com.github.javaparser.ast.Node; |
26 | import com.github.javaparser.ast.NodeList; |
27 | import com.github.javaparser.ast.expr.AnnotationExpr; |
28 | import com.github.javaparser.ast.expr.SimpleName; |
29 | import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; |
30 | import com.github.javaparser.ast.type.Type; |
31 | import com.github.javaparser.ast.visitor.CloneVisitor; |
32 | import com.github.javaparser.ast.visitor.GenericVisitor; |
33 | import com.github.javaparser.ast.visitor.VoidVisitor; |
34 | import com.github.javaparser.metamodel.AnnotationDeclarationMetaModel; |
35 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
36 | import com.github.javaparser.TokenRange; |
37 | import com.github.javaparser.resolution.Resolvable; |
38 | import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration; |
39 | import java.util.function.Consumer; |
40 | import java.util.Optional; |
41 | import com.github.javaparser.ast.Generated; |
42 | |
43 | /** |
44 | * An annotation type declaration.<br>{@code @interface X { ... }} |
45 | * |
46 | * @author Julio Vilmar Gesser |
47 | */ |
48 | public class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> implements NodeWithAbstractModifier<AnnotationDeclaration>, Resolvable<ResolvedAnnotationDeclaration> { |
49 | |
50 | public AnnotationDeclaration() { |
51 | this(null, new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>()); |
52 | } |
53 | |
54 | public AnnotationDeclaration(NodeList<Modifier> modifiers, String name) { |
55 | this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>()); |
56 | } |
57 | |
58 | @AllFieldsConstructor |
59 | public AnnotationDeclaration(NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) { |
60 | this(null, modifiers, annotations, name, members); |
61 | } |
62 | |
63 | /** |
64 | * This constructor is used by the parser and is considered private. |
65 | */ |
66 | @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
67 | public AnnotationDeclaration(TokenRange tokenRange, NodeList<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) { |
68 | super(tokenRange, modifiers, annotations, name, members); |
69 | customInitialization(); |
70 | } |
71 | |
72 | @Override |
73 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
74 | public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
75 | return v.visit(this, arg); |
76 | } |
77 | |
78 | @Override |
79 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
80 | public <A> void accept(final VoidVisitor<A> v, final A arg) { |
81 | v.visit(this, arg); |
82 | } |
83 | |
84 | @Override |
85 | @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
86 | public boolean remove(Node node) { |
87 | if (node == null) |
88 | return false; |
89 | return super.remove(node); |
90 | } |
91 | |
92 | @Override |
93 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
94 | public AnnotationDeclaration clone() { |
95 | return (AnnotationDeclaration) accept(new CloneVisitor(), null); |
96 | } |
97 | |
98 | @Override |
99 | @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
100 | public AnnotationDeclarationMetaModel getMetaModel() { |
101 | return JavaParserMetaModel.annotationDeclarationMetaModel; |
102 | } |
103 | |
104 | @Override |
105 | @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
106 | public boolean replace(Node node, Node replacementNode) { |
107 | if (node == null) |
108 | return false; |
109 | return super.replace(node, replacementNode); |
110 | } |
111 | |
112 | @Override |
113 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
114 | public boolean isAnnotationDeclaration() { |
115 | return true; |
116 | } |
117 | |
118 | @Override |
119 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
120 | public AnnotationDeclaration asAnnotationDeclaration() { |
121 | return this; |
122 | } |
123 | |
124 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
125 | public void ifAnnotationDeclaration(Consumer<AnnotationDeclaration> action) { |
126 | action.accept(this); |
127 | } |
128 | |
129 | @Override |
130 | public ResolvedAnnotationDeclaration resolve() { |
131 | return getSymbolResolver().resolveDeclaration(this, ResolvedAnnotationDeclaration.class); |
132 | } |
133 | |
134 | @Override |
135 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
136 | public Optional<AnnotationDeclaration> toAnnotationDeclaration() { |
137 | return Optional.of(this); |
138 | } |
139 | |
140 | @Override |
141 | public FieldDeclaration addField(Type type, String name, Modifier.Keyword... modifiers) { |
142 | throw new IllegalStateException("Cannot add a field to an annotation declaration."); |
143 | } |
144 | } |
145 |
Members