| 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.Node; |
| 25 | import com.github.javaparser.ast.visitor.CloneVisitor; |
| 26 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
| 27 | import com.github.javaparser.metamodel.StatementMetaModel; |
| 28 | import com.github.javaparser.TokenRange; |
| 29 | import com.github.javaparser.ast.Generated; |
| 30 | import java.util.function.Consumer; |
| 31 | import static com.github.javaparser.utils.CodeGenerationUtils.f; |
| 32 | import java.util.Optional; |
| 33 | |
| 34 | /** |
| 35 | * A base class for all statements. |
| 36 | * |
| 37 | * @author Julio Vilmar Gesser |
| 38 | */ |
| 39 | public abstract class Statement extends Node { |
| 40 | |
| 41 | @AllFieldsConstructor |
| 42 | public Statement() { |
| 43 | this(null); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * This constructor is used by the parser and is considered private. |
| 48 | */ |
| 49 | @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
| 50 | public Statement(TokenRange tokenRange) { |
| 51 | super(tokenRange); |
| 52 | customInitialization(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
| 57 | public boolean remove(Node node) { |
| 58 | if (node == null) |
| 59 | return false; |
| 60 | return super.remove(node); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
| 65 | public Statement clone() { |
| 66 | return (Statement) accept(new CloneVisitor(), null); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
| 71 | public StatementMetaModel getMetaModel() { |
| 72 | return JavaParserMetaModel.statementMetaModel; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
| 77 | public boolean replace(Node node, Node replacementNode) { |
| 78 | if (node == null) |
| 79 | return false; |
| 80 | return super.replace(node, replacementNode); |
| 81 | } |
| 82 | |
| 83 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 84 | public boolean isAssertStmt() { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 89 | public AssertStmt asAssertStmt() { |
| 90 | throw new IllegalStateException(f("%s is not an AssertStmt", this)); |
| 91 | } |
| 92 | |
| 93 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 94 | public boolean isBlockStmt() { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 99 | public BlockStmt asBlockStmt() { |
| 100 | throw new IllegalStateException(f("%s is not an BlockStmt", this)); |
| 101 | } |
| 102 | |
| 103 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 104 | public boolean isBreakStmt() { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 109 | public BreakStmt asBreakStmt() { |
| 110 | throw new IllegalStateException(f("%s is not an BreakStmt", this)); |
| 111 | } |
| 112 | |
| 113 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 114 | public boolean isContinueStmt() { |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 119 | public ContinueStmt asContinueStmt() { |
| 120 | throw new IllegalStateException(f("%s is not an ContinueStmt", this)); |
| 121 | } |
| 122 | |
| 123 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 124 | public boolean isDoStmt() { |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 129 | public DoStmt asDoStmt() { |
| 130 | throw new IllegalStateException(f("%s is not an DoStmt", this)); |
| 131 | } |
| 132 | |
| 133 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 134 | public boolean isEmptyStmt() { |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 139 | public EmptyStmt asEmptyStmt() { |
| 140 | throw new IllegalStateException(f("%s is not an EmptyStmt", this)); |
| 141 | } |
| 142 | |
| 143 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 144 | public boolean isExplicitConstructorInvocationStmt() { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 149 | public ExplicitConstructorInvocationStmt asExplicitConstructorInvocationStmt() { |
| 150 | throw new IllegalStateException(f("%s is not an ExplicitConstructorInvocationStmt", this)); |
| 151 | } |
| 152 | |
| 153 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 154 | public boolean isExpressionStmt() { |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 159 | public ExpressionStmt asExpressionStmt() { |
| 160 | throw new IllegalStateException(f("%s is not an ExpressionStmt", this)); |
| 161 | } |
| 162 | |
| 163 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 164 | public boolean isForStmt() { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 169 | public ForStmt asForStmt() { |
| 170 | throw new IllegalStateException(f("%s is not an ForStmt", this)); |
| 171 | } |
| 172 | |
| 173 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 174 | public boolean isIfStmt() { |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 179 | public IfStmt asIfStmt() { |
| 180 | throw new IllegalStateException(f("%s is not an IfStmt", this)); |
| 181 | } |
| 182 | |
| 183 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 184 | public boolean isLabeledStmt() { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 189 | public LabeledStmt asLabeledStmt() { |
| 190 | throw new IllegalStateException(f("%s is not an LabeledStmt", this)); |
| 191 | } |
| 192 | |
| 193 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 194 | public boolean isLocalClassDeclarationStmt() { |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 199 | public LocalClassDeclarationStmt asLocalClassDeclarationStmt() { |
| 200 | throw new IllegalStateException(f("%s is not an LocalClassDeclarationStmt", this)); |
| 201 | } |
| 202 | |
| 203 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 204 | public boolean isReturnStmt() { |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 209 | public ReturnStmt asReturnStmt() { |
| 210 | throw new IllegalStateException(f("%s is not an ReturnStmt", this)); |
| 211 | } |
| 212 | |
| 213 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 214 | public boolean isSwitchStmt() { |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 219 | public SwitchStmt asSwitchStmt() { |
| 220 | throw new IllegalStateException(f("%s is not an SwitchStmt", this)); |
| 221 | } |
| 222 | |
| 223 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 224 | public boolean isSynchronizedStmt() { |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 229 | public SynchronizedStmt asSynchronizedStmt() { |
| 230 | throw new IllegalStateException(f("%s is not an SynchronizedStmt", this)); |
| 231 | } |
| 232 | |
| 233 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 234 | public boolean isThrowStmt() { |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 239 | public ThrowStmt asThrowStmt() { |
| 240 | throw new IllegalStateException(f("%s is not an ThrowStmt", this)); |
| 241 | } |
| 242 | |
| 243 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 244 | public boolean isTryStmt() { |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 249 | public TryStmt asTryStmt() { |
| 250 | throw new IllegalStateException(f("%s is not an TryStmt", this)); |
| 251 | } |
| 252 | |
| 253 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 254 | public boolean isUnparsableStmt() { |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 259 | public UnparsableStmt asUnparsableStmt() { |
| 260 | throw new IllegalStateException(f("%s is not an UnparsableStmt", this)); |
| 261 | } |
| 262 | |
| 263 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 264 | public boolean isWhileStmt() { |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 269 | public WhileStmt asWhileStmt() { |
| 270 | throw new IllegalStateException(f("%s is not an WhileStmt", this)); |
| 271 | } |
| 272 | |
| 273 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 274 | public void ifAssertStmt(Consumer<AssertStmt> action) { |
| 275 | } |
| 276 | |
| 277 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 278 | public void ifBlockStmt(Consumer<BlockStmt> action) { |
| 279 | } |
| 280 | |
| 281 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 282 | public void ifBreakStmt(Consumer<BreakStmt> action) { |
| 283 | } |
| 284 | |
| 285 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 286 | public void ifContinueStmt(Consumer<ContinueStmt> action) { |
| 287 | } |
| 288 | |
| 289 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 290 | public void ifDoStmt(Consumer<DoStmt> action) { |
| 291 | } |
| 292 | |
| 293 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 294 | public void ifEmptyStmt(Consumer<EmptyStmt> action) { |
| 295 | } |
| 296 | |
| 297 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 298 | public void ifExplicitConstructorInvocationStmt(Consumer<ExplicitConstructorInvocationStmt> action) { |
| 299 | } |
| 300 | |
| 301 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 302 | public void ifExpressionStmt(Consumer<ExpressionStmt> action) { |
| 303 | } |
| 304 | |
| 305 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 306 | public void ifForStmt(Consumer<ForStmt> action) { |
| 307 | } |
| 308 | |
| 309 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 310 | public void ifIfStmt(Consumer<IfStmt> action) { |
| 311 | } |
| 312 | |
| 313 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 314 | public void ifLabeledStmt(Consumer<LabeledStmt> action) { |
| 315 | } |
| 316 | |
| 317 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 318 | public void ifLocalClassDeclarationStmt(Consumer<LocalClassDeclarationStmt> action) { |
| 319 | } |
| 320 | |
| 321 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 322 | public void ifReturnStmt(Consumer<ReturnStmt> action) { |
| 323 | } |
| 324 | |
| 325 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 326 | public void ifSwitchStmt(Consumer<SwitchStmt> action) { |
| 327 | } |
| 328 | |
| 329 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 330 | public void ifSynchronizedStmt(Consumer<SynchronizedStmt> action) { |
| 331 | } |
| 332 | |
| 333 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 334 | public void ifThrowStmt(Consumer<ThrowStmt> action) { |
| 335 | } |
| 336 | |
| 337 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 338 | public void ifTryStmt(Consumer<TryStmt> action) { |
| 339 | } |
| 340 | |
| 341 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 342 | public void ifUnparsableStmt(Consumer<UnparsableStmt> action) { |
| 343 | } |
| 344 | |
| 345 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 346 | public void ifWhileStmt(Consumer<WhileStmt> action) { |
| 347 | } |
| 348 | |
| 349 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 350 | public Optional<AssertStmt> toAssertStmt() { |
| 351 | return Optional.empty(); |
| 352 | } |
| 353 | |
| 354 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 355 | public Optional<BlockStmt> toBlockStmt() { |
| 356 | return Optional.empty(); |
| 357 | } |
| 358 | |
| 359 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 360 | public Optional<BreakStmt> toBreakStmt() { |
| 361 | return Optional.empty(); |
| 362 | } |
| 363 | |
| 364 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 365 | public Optional<ContinueStmt> toContinueStmt() { |
| 366 | return Optional.empty(); |
| 367 | } |
| 368 | |
| 369 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 370 | public Optional<DoStmt> toDoStmt() { |
| 371 | return Optional.empty(); |
| 372 | } |
| 373 | |
| 374 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 375 | public Optional<EmptyStmt> toEmptyStmt() { |
| 376 | return Optional.empty(); |
| 377 | } |
| 378 | |
| 379 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 380 | public Optional<ExplicitConstructorInvocationStmt> toExplicitConstructorInvocationStmt() { |
| 381 | return Optional.empty(); |
| 382 | } |
| 383 | |
| 384 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 385 | public Optional<ExpressionStmt> toExpressionStmt() { |
| 386 | return Optional.empty(); |
| 387 | } |
| 388 | |
| 389 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 390 | public Optional<ForStmt> toForStmt() { |
| 391 | return Optional.empty(); |
| 392 | } |
| 393 | |
| 394 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 395 | public Optional<IfStmt> toIfStmt() { |
| 396 | return Optional.empty(); |
| 397 | } |
| 398 | |
| 399 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 400 | public Optional<LabeledStmt> toLabeledStmt() { |
| 401 | return Optional.empty(); |
| 402 | } |
| 403 | |
| 404 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 405 | public Optional<LocalClassDeclarationStmt> toLocalClassDeclarationStmt() { |
| 406 | return Optional.empty(); |
| 407 | } |
| 408 | |
| 409 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 410 | public Optional<ReturnStmt> toReturnStmt() { |
| 411 | return Optional.empty(); |
| 412 | } |
| 413 | |
| 414 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 415 | public Optional<SwitchStmt> toSwitchStmt() { |
| 416 | return Optional.empty(); |
| 417 | } |
| 418 | |
| 419 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 420 | public Optional<SynchronizedStmt> toSynchronizedStmt() { |
| 421 | return Optional.empty(); |
| 422 | } |
| 423 | |
| 424 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 425 | public Optional<ThrowStmt> toThrowStmt() { |
| 426 | return Optional.empty(); |
| 427 | } |
| 428 | |
| 429 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 430 | public Optional<TryStmt> toTryStmt() { |
| 431 | return Optional.empty(); |
| 432 | } |
| 433 | |
| 434 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 435 | public Optional<UnparsableStmt> toUnparsableStmt() { |
| 436 | return Optional.empty(); |
| 437 | } |
| 438 | |
| 439 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 440 | public Optional<WhileStmt> toWhileStmt() { |
| 441 | return Optional.empty(); |
| 442 | } |
| 443 | |
| 444 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 445 | public boolean isForEachStmt() { |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 450 | public ForEachStmt asForEachStmt() { |
| 451 | throw new IllegalStateException(f("%s is not an ForEachStmt", this)); |
| 452 | } |
| 453 | |
| 454 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 455 | public Optional<ForEachStmt> toForEachStmt() { |
| 456 | return Optional.empty(); |
| 457 | } |
| 458 | |
| 459 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 460 | public void ifForEachStmt(Consumer<ForEachStmt> action) { |
| 461 | } |
| 462 | |
| 463 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 464 | public boolean isYieldStmt() { |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 469 | public YieldStmt asYieldStmt() { |
| 470 | throw new IllegalStateException(f("%s is not an YieldStmt", this)); |
| 471 | } |
| 472 | |
| 473 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 474 | public Optional<YieldStmt> toYieldStmt() { |
| 475 | return Optional.empty(); |
| 476 | } |
| 477 | |
| 478 | @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") |
| 479 | public void ifYieldStmt(Consumer<YieldStmt> action) { |
| 480 | } |
| 481 | } |
| 482 |
Members