| 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.stmt; |
| 22 | |
| 23 | import com.github.javaparser.ast.AllFieldsConstructor; |
| 24 | import com.github.javaparser.ast.expr.SimpleName; |
| 25 | import com.github.javaparser.ast.nodeTypes.NodeWithOptionalLabel; |
| 26 | import com.github.javaparser.ast.observer.ObservableProperty; |
| 27 | import com.github.javaparser.ast.visitor.GenericVisitor; |
| 28 | import com.github.javaparser.ast.visitor.VoidVisitor; |
| 29 | import java.util.Optional; |
| 30 | import com.github.javaparser.ast.Node; |
| 31 | import com.github.javaparser.ast.visitor.CloneVisitor; |
| 32 | import com.github.javaparser.metamodel.ContinueStmtMetaModel; |
| 33 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
| 34 | import com.github.javaparser.TokenRange; |
| 35 | import com.github.javaparser.metamodel.OptionalProperty; |
| 36 | import java.util.function.Consumer; |
| 37 | import 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 | */ |
| 46 | public class ContinueStmt extends Statement implements NodeWithOptionalLabel<ContinueStmt> { |
| 47 | |
| 48 | @OptionalProperty |
| 49 | private SimpleName label; |
| 50 | |
| 51 | public ContinueStmt() { |
| 52 | this(null, null); |
| 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(null, label); |
| 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 tokenRange, SimpleName label) { |
| 69 | super(tokenRange); |
| 70 | setLabel(label); |
| 71 | customInitialization(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
| 76 | public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
| 77 | return v.visit(this, arg); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
| 82 | public <A> void accept(final VoidVisitor<A> v, final A arg) { |
| 83 | v.visit(this, arg); |
| 84 | } |
| 85 | |
| 86 | @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
| 87 | public Optional<SimpleName> getLabel() { |
| 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.label, label); |
| 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((SimpleName) null); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
| 131 | public ContinueStmt clone() { |
| 132 | return (ContinueStmt) accept(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 node, Node replacementNode) { |
| 144 | if (node == null) |
| 145 | return false; |
| 146 | if (label != null) { |
| 147 | if (node == label) { |
| 148 | setLabel((SimpleName) replacementNode); |
| 149 | return true; |
| 150 | } |
| 151 | } |
| 152 | return super.replace(node, replacementNode); |
| 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<ContinueStmt> action) { |
| 169 | action.accept(this); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 174 | public Optional<ContinueStmt> toContinueStmt() { |
| 175 | return Optional.of(this); |
| 176 | } |
| 177 | } |
| 178 |
Members