public class NormalCompletionVisitor extends GenericVisitorWithDefaults<Boolean,Void>
https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-14.22.
The JLS specifies that a statement can complete normally only if it is reachable and specifies rules for what it
means for a statement to be reachable, but that part can be ignored in JavaParser since having unreachable code
results in a compilation error and is thus not supported. This means that all of the rules are implemented with the
assumption that provided nodes are reachable.
An example of where this is needed is for the following rule regarding pattern variables introduced by if-statements.
6.3.2.2. if Statements https://docs.oracle.com/javase/specs/jls/se22/html/jls-6.html#jls-6.3.2.2:
The following rules apply to a statement if (e) S (ยง14.9.1):
A pattern variable is introduced by if (e) S iff (i) it is introduced by e when false and (ii) S cannot complete
normally.
This means that in this example:
if (!(x instanceof Foo f)) {
return;
}
System.out.println(f);
f will be in scope for the println call since the block making up the then-block of the if statement (S in the rule
above) cannot complete normally (since the last statement, return, cannot complete normally).
But, in this example:
if (!(x instanceof Foo f)) { }
f is not introduced by the if statement since the empty then-block can complete normally.| Constructor and Description |
|---|
NormalCompletionVisitor() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsCorrespondingBreak(Statement statement) |
Boolean |
defaultAction(Node n,
Void unused) |
Boolean |
visit(BlockStmt block,
Void unused)
An empty block that is not a switch block can complete normally iff it is reachable.
|
Boolean |
visit(BreakStmt breakStmt,
Void unused)
A break statement cannot complete normally.
|
Boolean |
visit(ContinueStmt continueStmt,
Void unused)
A continue statement cannot complete normally.
|
Boolean |
visit(DoStmt doStmt,
Void unused)
A do statement can complete normally iff at least one of the following is true:
- The contained statement can complete normally and the condition expression is not a constant expression
with value true
|
Boolean |
visit(ForStmt forStmt,
Void unused)
A basic for statement can complete normally iff at least one of the following is true:
- The for statement is reachable, there is a condition expression, and the condition expression is not a constant
expression with value true
|
Boolean |
visit(IfStmt ifStmt,
Void unused)
An if-then statement can complete normally iff it is reachable.
|
Boolean |
visit(LabeledStmt labeledStmt,
Void unused)
A labeled statement can complete normally if at least one of the following is true:
- The contained statement can complete normally
|
Boolean |
visit(ReturnStmt returnStmt,
Void unused)
A return statement cannot complete normally.
|
Boolean |
visit(SwitchStmt switchStmt,
Void unused)
A switch statement whose switch block is empty, or contains only switch labels, can complete normally.
|
Boolean |
visit(SynchronizedStmt synchronizedStmt,
Void unused)
A synchronized statement can complete normally iff the contained statement can complete normally.
|
Boolean |
visit(ThrowStmt throwStmt,
Void unused)
A throw statement cannot complete normally.
|
Boolean |
visit(TryStmt tryStmt,
Void unused)
A try statement can complete normally iff both of the following are true:
- The try block can complete normally or any catch block can complete normally
|
Boolean |
visit(WhileStmt whileStmt,
Void unused)
A while statement can complete normally iff at least one of the following is true:
- The while statement is reachable and the condition expression is not a constant expression with value true
|
Boolean |
visit(YieldStmt yieldStmt,
Void unused)
A yield statement cannot complete normally.
|
defaultAction, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitpublic Boolean defaultAction(Node n, Void unused)
defaultAction in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(BreakStmt breakStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(ContinueStmt continueStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(ReturnStmt returnStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(ThrowStmt throwStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(YieldStmt yieldStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(BlockStmt block, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(LabeledStmt labeledStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(IfStmt ifStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(WhileStmt whileStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(DoStmt doStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(ForStmt forStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(SynchronizedStmt synchronizedStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(TryStmt tryStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public Boolean visit(SwitchStmt switchStmt, Void unused)
visit in interface GenericVisitor<Boolean,Void>visit in class GenericVisitorWithDefaults<Boolean,Void>public static boolean containsCorrespondingBreak(Statement statement)
statement - should be one of: SwitchStatement, WhileStatement, DoStatement, ForStatementCopyright © 2007–2025. All rights reserved.