JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/stmt/ContinueStmt.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.stmt;
22
23import com.github.javaparser.ast.AllFieldsConstructor;
24import com.github.javaparser.ast.expr.SimpleName;
25import com.github.javaparser.ast.nodeTypes.NodeWithOptionalLabel;
26import com.github.javaparser.ast.observer.ObservableProperty;
27import com.github.javaparser.ast.visitor.GenericVisitor;
28import com.github.javaparser.ast.visitor.VoidVisitor;
29import java.util.Optional;
30import com.github.javaparser.ast.Node;
31import com.github.javaparser.ast.visitor.CloneVisitor;
32import com.github.javaparser.metamodel.ContinueStmtMetaModel;
33import com.github.javaparser.metamodel.JavaParserMetaModel;
34import com.github.javaparser.TokenRange;
35import com.github.javaparser.metamodel.OptionalProperty;
36import java.util.function.Consumer;
37import com.github.javaparser.ast.Generated;
38
39/**
40 * A continue statement with an optional label;
41 * <br>{@code continue brains;}
42 * <br>{@code continue;}
43 *
44 * @author Julio Vilmar Gesser
45 */
46public class ContinueStmt extends Statement implements NodeWithOptionalLabel<ContinueStmt> {
47
48    @OptionalProperty
49    private SimpleName label;
50
51    public ContinueStmt() {
52        this(nullnull);
53    }
54
55    public ContinueStmt(final String label) {
56        this(null, new SimpleName(label));
57    }
58
59    @AllFieldsConstructor
60    public ContinueStmt(final SimpleName label) {
61        this(nulllabel);
62    }
63
64    /**
65     * This constructor is used by the parser and is considered private.
66     */
67    @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
68    public ContinueStmt(TokenRange tokenRangeSimpleName label) {
69        super(tokenRange);
70        setLabel(label);
71        customInitialization();
72    }
73
74    @Override
75    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
76    public <RAR accept(final GenericVisitor<RAvfinal A arg) {
77        return v.visit(this, arg);
78    }
79
80    @Override
81    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
82    public <Avoid accept(final VoidVisitor<Avfinal A arg) {
83        v.visit(this, arg);
84    }
85
86    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
87    public Optional<SimpleNamegetLabel() {
88        return Optional.ofNullable(label);
89    }
90
91    /**
92     * Sets the label
93     *
94     * @param label the label, can be null
95     * @return this, the ContinueStmt
96     */
97    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
98    public ContinueStmt setLabel(final SimpleName label) {
99        if (label == this.label) {
100            return (ContinueStmt) this;
101        }
102        notifyPropertyChange(ObservableProperty.LABEL, this.labellabel);
103        if (this.label != null)
104            this.label.setParentNode(null);
105        this.label = label;
106        setAsParentNodeOf(label);
107        return this;
108    }
109
110    @Override
111    @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
112    public boolean remove(Node node) {
113        if (node == null)
114            return false;
115        if (label != null) {
116            if (node == label) {
117                removeLabel();
118                return true;
119            }
120        }
121        return super.remove(node);
122    }
123
124    @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
125    public ContinueStmt removeLabel() {
126        return setLabel((SimpleNamenull);
127    }
128
129    @Override
130    @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
131    public ContinueStmt clone() {
132        return (ContinueStmtaccept(new CloneVisitor(), null);
133    }
134
135    @Override
136    @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
137    public ContinueStmtMetaModel getMetaModel() {
138        return JavaParserMetaModel.continueStmtMetaModel;
139    }
140
141    @Override
142    @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
143    public boolean replace(Node nodeNode replacementNode) {
144        if (node == null)
145            return false;
146        if (label != null) {
147            if (node == label) {
148                setLabel((SimpleNamereplacementNode);
149                return true;
150            }
151        }
152        return super.replace(nodereplacementNode);
153    }
154
155    @Override
156    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
157    public boolean isContinueStmt() {
158        return true;
159    }
160
161    @Override
162    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
163    public ContinueStmt asContinueStmt() {
164        return this;
165    }
166
167    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
168    public void ifContinueStmt(Consumer<ContinueStmtaction) {
169        action.accept(this);
170    }
171
172    @Override
173    @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
174    public Optional<ContinueStmttoContinueStmt() {
175        return Optional.of(this);
176    }
177}
178
MembersX
ContinueStmt:getMetaModel
ContinueStmt:toContinueStmt
ContinueStmt:asContinueStmt
ContinueStmt:removeLabel
ContinueStmt:setLabel
ContinueStmt:isContinueStmt
ContinueStmt:label
ContinueStmt:clone
ContinueStmt:accept
ContinueStmt:getLabel
ContinueStmt:replace
ContinueStmt:ContinueStmt
ContinueStmt:remove
ContinueStmt:ifContinueStmt
Members
X