Package: org.codehaus.groovy.control

## [Java] Class LabelVerifier

- org.codehaus.groovy.control.LabelVerifier

-     public class LabelVerifier
      extends PrePostStatementVisitor

  This class checks the handling of labels in the AST

- - ### Constructor Summary

    Constructors
    Constructor and description
    `LabelVerifier(SourceUnit src)` Creates a verifier for label usage in one source unit.

  - ### Methods Summary

    Methods
    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).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class PrePostStatementVisitor` | `postVisitStatement, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitContinueStatement, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitForLoop, visitIfElse, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop, visitYieldStatement`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSwitchExpression, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop, visitYieldStatement`

- - ### Constructor Detail

    - #### public LabelVerifier(SourceUnit src)

      Creates a verifier for label usage in one source unit.

      Parameters:
        `src` - the source unit to report errors against

  - ### Method Detail

    - #### 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.

      Returns:
        the active source unit

    - #### protected void postVisitStatement(Statement s)

      Removes any labels that go out of scope after visiting the current statement.

      Parameters:
        `s` - the statement being exited

    - #### public void visitBreakStatement(BreakStatement breakStatement)

      Verifies that a `break` statement appears in a valid context.

      Parameters:
        `breakStatement` - the break statement to inspect

    - #### protected void visitClassCodeContainer(Statement code)

      Resets label-tracking state before verifying a class code block.

      Parameters:
        `code` - the statement container to verify

    - #### public void visitClosureExpression(ClosureExpression expression)

    - #### public void visitContinueStatement(ContinueStatement continueStatement)

      Verifies that a `continue` statement appears in a valid loop context.

      Parameters:
        `continueStatement` - the continue statement to inspect

    - #### public void visitDoWhileLoop(DoWhileStatement loop)

      Verifies labels inside a `do`/`while` loop.

      Parameters:
        `loop` - the loop to inspect

    - #### public void visitForLoop(ForStatement loop)

      Verifies labels inside a `for` loop.

      Parameters:
        `loop` - the loop to inspect

    - #### public void visitIfElse(IfStatement cond)

      Verifies labels inside an `if`/`else` statement.

      Parameters:
        `cond` - the conditional statement to inspect

    - #### public void visitLambdaExpression(LambdaExpression expression)

    - #### protected void visitStatement(Statement s)

      Registers any labels introduced by the current statement.

      Parameters:
        `s` - the statement being entered

    - #### public void visitSwitch(SwitchStatement switchStatement)

      Verifies labels inside a `switch` statement.

      Parameters:
        `switchStatement` - the switch statement to inspect

    - #### public void visitSwitchExpression(SwitchExpression expression)

      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.

      Parameters:
        `expression` - the switch expression to inspect
      Since:
        6.0.0

    - #### public void visitWhileLoop(WhileStatement loop)

      Verifies labels inside a `while` loop.

      Parameters:
        `loop` - the loop to inspect

    - #### 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). A switch expression that itself lives inside a closure (for example a GINQ query) is allowed.

      Parameters:
        `statement` - the yield statement to inspect
      Since:
        6.0.0