public class LabelVerifier
extends PrePostStatementVisitor
This class checks the handling of labels in the AST
| Constructor and description |
|---|
LabelVerifier(SourceUnit src)Creates a verifier for label usage in one source unit. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
assertNoLabelsMissed()Reports any labeled break or continue statements that could not be matched. |
|
protected SourceUnit |
getSourceUnit()Returns the source unit currently being verified. |
|
protected void |
postVisitStatement(Statement s)Removes any labels that go out of scope after visiting the current statement. |
|
public void |
visitBreakStatement(BreakStatement breakStatement)Verifies that a break statement appears in a valid context. |
|
protected void |
visitClassCodeContainer(Statement code)Resets label-tracking state before verifying a class code block. |
|
public void |
visitClosureExpression(ClosureExpression expression) |
|
public void |
visitContinueStatement(ContinueStatement continueStatement)Verifies that a continue statement appears in a valid loop context. |
|
public void |
visitDoWhileLoop(DoWhileStatement loop)Verifies labels inside a do/while loop. |
|
public void |
visitForLoop(ForStatement loop)Verifies labels inside a for loop. |
|
public void |
visitIfElse(IfStatement cond)Verifies labels inside an if/else statement. |
|
public void |
visitLambdaExpression(LambdaExpression expression) |
|
protected void |
visitStatement(Statement s)Registers any labels introduced by the current statement. |
|
public void |
visitSwitch(SwitchStatement switchStatement)Verifies labels inside a switch statement. |
|
public void |
visitSwitchExpression(SwitchExpression expression)Verifies labels and yield inside a switch expression
(GROOVY-12255). |
|
public void |
visitWhileLoop(WhileStatement loop)Verifies labels inside a while loop. |
|
public void |
visitYieldStatement(YieldStatement statement)Verifies that a yield statement targets the innermost switch
expression and does not cross a closure or lambda that was entered
after that switch (GROOVY-12255 / JEP 361). |
Creates a verifier for label usage in one source unit.
src - the source unit to report errors againstReports any labeled break or continue statements that could not be matched.
Returns the source unit currently being verified.
Removes any labels that go out of scope after visiting the current statement.
s - the statement being exited Verifies that a break statement appears in a valid context.
breakStatement - the break statement to inspectResets label-tracking state before verifying a class code block.
code - the statement container to verify Verifies that a continue statement appears in a valid loop context.
continueStatement - the continue statement to inspect Verifies labels inside a do/while loop.
loop - the loop to inspect Verifies labels inside a for loop.
loop - the loop to inspect Verifies labels inside an if/else statement.
cond - the conditional statement to inspectRegisters any labels introduced by the current statement.
s - the statement being entered Verifies labels inside a switch statement.
switchStatement - the switch statement to inspect Verifies labels and yield inside a switch expression
(GROOVY-12255). Per JEP 361, break and continue cannot
transfer control out of a switch expression, so the enclosing loop,
switch, and label context does not flow into the arms; loops and labels
declared inside an arm remain valid targets.
expression - the switch expression to inspect Verifies labels inside a while loop.
loop - the loop to inspect Verifies that a yield statement targets the innermost switch
expression and does not cross a closure or lambda that was entered
after that switch (GROOVY-12255 / JEP 361). A switch expression
that itself lives inside a closure (for example a GINQ query) is allowed.
statement - the yield statement to inspectCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.