NormalCompletionVisitor

When deciding into which scope pattern variables should be introduced, it is sometimes necessary to determine whether a statement can complete normally {@see 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 {@see 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.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
Link copied to clipboard
open fun defaultAction(n: Node, unused: Void): Boolean
Link copied to clipboard
open fun visit(n: AnnotationDeclaration, arg: A): R

open fun visit(block: BlockStmt, unused: Void): Boolean
An empty block that is not a switch block can complete normally iff it is reachable.
open fun visit(breakStmt: BreakStmt, unused: Void): Boolean
A break statement cannot complete normally.
open fun visit(continueStmt: ContinueStmt, unused: Void): Boolean
A continue statement cannot complete normally.
open fun visit(doStmt: DoStmt, unused: Void): Boolean
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.
open fun visit(forStmt: ForStmt, unused: Void): Boolean
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.
open fun visit(ifStmt: IfStmt, unused: Void): Boolean
An if-then statement can complete normally iff it is reachable.
open fun visit(labeledStmt: LabeledStmt, unused: Void): Boolean
A labeled statement can complete normally if at least one of the following is true: - The contained statement can complete normally.
open fun visit(returnStmt: ReturnStmt, unused: Void): Boolean
A return statement cannot complete normally.
open fun visit(switchStmt: SwitchStmt, unused: Void): Boolean
A switch statement whose switch block is empty, or contains only switch labels, can complete normally.
open fun visit(synchronizedStmt: SynchronizedStmt, unused: Void): Boolean
A synchronized statement can complete normally iff the contained statement can complete normally.
open fun visit(throwStmt: ThrowStmt, unused: Void): Boolean
A throw statement cannot complete normally.
open fun visit(tryStmt: TryStmt, unused: Void): Boolean
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.
open fun visit(whileStmt: WhileStmt, unused: Void): Boolean
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.
open fun visit(yieldStmt: YieldStmt, unused: Void): Boolean
A yield statement cannot complete normally.