JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/body/EnumConstantDeclaration.java
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 */
21package com.github.javaparser.ast.body;
22
23import com.github.javaparser.ast.AllFieldsConstructor;
24import com.github.javaparser.ast.NodeList;
25import com.github.javaparser.ast.expr.AnnotationExpr;
26import com.github.javaparser.ast.expr.Expression;
27import com.github.javaparser.ast.expr.SimpleName;
28import com.github.javaparser.ast.nodeTypes.NodeWithArguments;
29import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
30import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
31import com.github.javaparser.ast.observer.ObservableProperty;
32import com.github.javaparser.ast.visitor.GenericVisitor;
33import com.github.javaparser.ast.visitor.VoidVisitor;
34import static com.github.javaparser.utils.Utils.assertNotNull;
35import com.github.javaparser.ast.Node;
36import com.github.javaparser.ast.visitor.CloneVisitor;
37import com.github.javaparser.metamodel.EnumConstantDeclarationMetaModel;
38import com.github.javaparser.metamodel.JavaParserMetaModel;
39import com.github.javaparser.TokenRange;
40import com.github.javaparser.resolution.Resolvable;
41import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration;
42import java.util.function.Consumer;
43import java.util.Optional;
44import com.github.javaparser.ast.Generated;
45
46/**
47 * One of the values an enum can take. A(1) and B(2) in this example: {@code enum X { A(1), B(2) }}
48 *
49 * @author Julio Vilmar Gesser
50 */
51public class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> implements NodeWithJavadoc<EnumConstantDeclaration>, NodeWithSimpleName<EnumConstantDeclaration>, NodeWithArguments<EnumConstantDeclaration>, Resolvable<ResolvedEnumConstantDeclaration> {
52
53    private SimpleName name;
54
55    private NodeList<Expressionarguments;
56
57    private NodeList<BodyDeclaration<?>> classBody;
58
59    public EnumConstantDeclaration() {
60        this(null, new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>());
61    }
62
63    public EnumConstantDeclaration(String name) {
64        this(null, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>());
65    }
66
67    @AllFieldsConstructor
68    public EnumConstantDeclaration(NodeList<AnnotationExprannotationsSimpleName nameNodeList<ExpressionargumentsNodeList<BodyDeclaration<?>> classBody) {
69        this(nullannotationsnameargumentsclassBody);
70    }
71
72    /**
73     * This constructor is used by the parser and is considered private.
74     */
75    @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
76    public EnumConstantDeclaration(TokenRange tokenRangeNodeList<AnnotationExprannotationsSimpleName nameNodeList<ExpressionargumentsNodeList<BodyDeclaration<?>> classBody) {
77        super(tokenRangeannotations);
78        setName(name);
79        setArguments(arguments);
80        setClassBody(classBody);
81        customInitialization();
82    }
83
84    @Override
85    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
86    public <RAR accept(final GenericVisitor<RAvfinal A arg) {
87        return v.visit(this, arg);
88    }
89
90    @Override
91    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
92    public <Avoid accept(final VoidVisitor<Avfinal A arg) {
93        v.visit(this, arg);
94    }
95
96    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
97    public NodeList<ExpressiongetArguments() {
98        return arguments;
99    }
100
101    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
102    public NodeList<BodyDeclaration<?>> getClassBody() {
103        return classBody;
104    }
105
106    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
107    public SimpleName getName() {
108        return name;
109    }
110
111    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
112    public EnumConstantDeclaration setArguments(final NodeList<Expressionarguments) {
113        assertNotNull(arguments);
114        if (arguments == this.arguments) {
115            return (EnumConstantDeclaration) this;
116        }
117        notifyPropertyChange(ObservableProperty.ARGUMENTS, this.argumentsarguments);
118        if (this.arguments != null)
119            this.arguments.setParentNode(null);
120        this.arguments = arguments;
121        setAsParentNodeOf(arguments);
122        return this;
123    }
124
125    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
126    public EnumConstantDeclaration setClassBody(final NodeList<BodyDeclaration<?>> classBody) {
127        assertNotNull(classBody);
128        if (classBody == this.classBody) {
129            return (EnumConstantDeclaration) this;
130        }
131        notifyPropertyChange(ObservableProperty.CLASS_BODY, this.classBodyclassBody);
132        if (this.classBody != null)
133            this.classBody.setParentNode(null);
134        this.classBody = classBody;
135        setAsParentNodeOf(classBody);
136        return this;
137    }
138
139    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
140    public EnumConstantDeclaration setName(final SimpleName name) {
141        assertNotNull(name);
142        if (name == this.name) {
143            return (EnumConstantDeclaration) this;
144        }
145        notifyPropertyChange(ObservableProperty.NAME, this.namename);
146        if (this.name != null)
147            this.name.setParentNode(null);
148        this.name = name;
149        setAsParentNodeOf(name);
150        return this;
151    }
152
153    @Override
154    @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
155    public boolean remove(Node node) {
156        if (node == null)
157            return false;
158        for (int i = 0i < arguments.size(); i++) {
159            if (arguments.get(i) == node) {
160                arguments.remove(i);
161                return true;
162            }
163        }
164        for (int i = 0i < classBody.size(); i++) {
165            if (classBody.get(i) == node) {
166                classBody.remove(i);
167                return true;
168            }
169        }
170        return super.remove(node);
171    }
172
173    @Override
174    @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
175    public EnumConstantDeclaration clone() {
176        return (EnumConstantDeclarationaccept(new CloneVisitor(), null);
177    }
178
179    @Override
180    @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
181    public EnumConstantDeclarationMetaModel getMetaModel() {
182        return JavaParserMetaModel.enumConstantDeclarationMetaModel;
183    }
184
185    @Override
186    @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
187    public boolean replace(Node nodeNode replacementNode) {
188        if (node == null)
189            return false;
190        for (int i = 0i < arguments.size(); i++) {
191            if (arguments.get(i) == node) {
192                arguments.set(i, (ExpressionreplacementNode);
193                return true;
194            }
195        }
196        for (int i = 0i < classBody.size(); i++) {
197            if (classBody.get(i) == node) {
198                classBody.set(i, (BodyDeclarationreplacementNode);
199                return true;
200            }
201        }
202        if (node == name) {
203            setName((SimpleNamereplacementNode);
204            return true;
205        }
206        return super.replace(nodereplacementNode);
207    }
208
209    @Override
210    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
211    public boolean isEnumConstantDeclaration() {
212        return true;
213    }
214
215    @Override
216    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
217    public EnumConstantDeclaration asEnumConstantDeclaration() {
218        return this;
219    }
220
221    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
222    public void ifEnumConstantDeclaration(Consumer<EnumConstantDeclarationaction) {
223        action.accept(this);
224    }
225
226    @Override
227    public ResolvedEnumConstantDeclaration resolve() {
228        return getSymbolResolver().resolveDeclaration(this, ResolvedEnumConstantDeclaration.class);
229    }
230
231    @Override
232    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
233    public Optional<EnumConstantDeclarationtoEnumConstantDeclaration() {
234        return Optional.of(this);
235    }
236}
237
MembersX
EnumConstantDeclaration:setArguments
EnumConstantDeclaration:ifEnumConstantDeclaration
EnumConstantDeclaration:toEnumConstantDeclaration
EnumConstantDeclaration:asEnumConstantDeclaration
EnumConstantDeclaration:setName
EnumConstantDeclaration:name
EnumConstantDeclaration:getClassBody
EnumConstantDeclaration:setClassBody
EnumConstantDeclaration:clone
EnumConstantDeclaration:EnumConstantDeclaration
EnumConstantDeclaration:getName
EnumConstantDeclaration:resolve
EnumConstantDeclaration:classBody
EnumConstantDeclaration:isEnumConstantDeclaration
EnumConstantDeclaration:getMetaModel
EnumConstantDeclaration:replace
EnumConstantDeclaration:arguments
EnumConstantDeclaration:getArguments
EnumConstantDeclaration:accept
EnumConstantDeclaration:remove
Members
X