Package org.codehaus.groovy.control
Class LabelVerifier
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.control.LabelVerifier
- All Implemented Interfaces:
GroovyClassVisitor,GroovyCodeVisitor,ErrorCollecting
This class checks the handling of labels in the AST
-
Constructor Summary
ConstructorsConstructorDescriptionLabelVerifier(SourceUnit src) Creates a verifier for label usage in one source unit. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReports any labeled break or continue statements that could not be matched.protected SourceUnitReturns the source unit currently being verified.protected voidRemoves any labels that go out of scope after visiting the current statement.voidvisitAssertStatement(AssertStatement statement) Visits an assert statement and then runs post-visit bookkeeping.voidvisitBlockStatement(BlockStatement statement) Visits a block statement and then runs post-visit bookkeeping.voidvisitBreakStatement(BreakStatement breakStatement) Verifies that abreakstatement appears in a valid context.voidvisitCaseStatement(CaseStatement statement) Visits a case statement and then runs post-visit bookkeeping.voidvisitCatchStatement(CatchStatement statement) Visits a catch statement and then runs post-visit bookkeeping.protected voidResets label-tracking state before verifying a class code block.voidvisitClosureExpression(ClosureExpression expression) Visits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.voidvisitContinueStatement(ContinueStatement continueStatement) Verifies that acontinuestatement appears in a valid loop context.voidVerifies labels inside ado/whileloop.voidvisitEmptyStatement(EmptyStatement statement) Visits an empty statement and then runs post-visit bookkeeping.voidvisitExpressionStatement(ExpressionStatement statement) Visits an expression statement and then runs post-visit bookkeeping.voidvisitForLoop(ForStatement loop) Verifies labels inside aforloop.voidvisitIfElse(IfStatement cond) Verifies labels inside anif/elsestatement.voidvisitLambdaExpression(LambdaExpression expression) Visits aLambdaExpression, treating it as a closure expression.voidvisitReturnStatement(ReturnStatement statement) Visits a return statement and then runs post-visit bookkeeping.protected voidRegisters any labels introduced by the current statement.voidvisitSwitch(SwitchStatement switchStatement) Verifies labels inside aswitchstatement.voidvisitSwitchExpression(SwitchExpression expression) Verifies labels andyieldinside a switch expression (GROOVY-12255).voidvisitSynchronizedStatement(SynchronizedStatement statement) Visits a synchronized statement and then runs post-visit bookkeeping.voidvisitThrowStatement(ThrowStatement statement) Visits a throw statement and then runs post-visit bookkeeping.voidvisitTryCatchFinally(TryCatchStatement statement) Visits a try-catch-finally statement and then runs post-visit bookkeeping.voidvisitWhileLoop(WhileStatement loop) Verifies labels inside awhileloop.voidvisitYieldStatement(YieldStatement statement) Verifies that ayieldstatement targets the innermost switch expression and does not cross a closure or lambda that was entered after that switch (GROOVY-12255 / JEP 361).Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, visitAnnotation, visitAnnotations, visitAnnotations, visitClass, visitConstructor, visitConstructorOrMethod, visitDeclarationExpression, visitField, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitStatementAnnotationsMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitFieldExpression, visitGStringExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Constructor Details
-
LabelVerifier
Creates a verifier for label usage in one source unit.- Parameters:
src- the source unit to report errors against
-
-
Method Details
-
getSourceUnit
Returns the source unit currently being verified.- Specified by:
getSourceUnitin classClassCodeVisitorSupport- Returns:
- the active source unit
-
assertNoLabelsMissed
protected void assertNoLabelsMissed()Reports any labeled break or continue statements that could not be matched. -
visitStatement
Registers any labels introduced by the current statement.- Parameters:
s- the statement being entered
-
postVisitStatement
Removes any labels that go out of scope after visiting the current statement.- Parameters:
s- the statement being exited
-
visitClassCodeContainer
Resets label-tracking state before verifying a class code block.- Overrides:
visitClassCodeContainerin classClassCodeVisitorSupport- Parameters:
code- the statement container to verify
-
visitIfElse
Verifies labels inside anif/elsestatement.- Specified by:
visitIfElsein interfaceGroovyCodeVisitor- Parameters:
cond- the conditional statement to inspect
-
visitForLoop
Verifies labels inside aforloop.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Parameters:
loop- the loop to inspect
-
visitWhileLoop
Verifies labels inside awhileloop.- Specified by:
visitWhileLoopin interfaceGroovyCodeVisitor- Parameters:
loop- the loop to inspect
-
visitDoWhileLoop
Verifies labels inside ado/whileloop.- Specified by:
visitDoWhileLoopin interfaceGroovyCodeVisitor- Parameters:
loop- the loop to inspect
-
visitSwitch
Verifies labels inside aswitchstatement.- Specified by:
visitSwitchin interfaceGroovyCodeVisitor- Parameters:
switchStatement- the switch statement to inspect
-
visitSwitchExpression
Verifies labels andyieldinside a switch expression (GROOVY-12255). Per JEP 361,breakandcontinuecannot 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.- Specified by:
visitSwitchExpressionin interfaceGroovyCodeVisitor- Overrides:
visitSwitchExpressionin classCodeVisitorSupport- Parameters:
expression- the switch expression to inspect- Since:
- 6.0.0
-
visitYieldStatement
Verifies that ayieldstatement 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.- Specified by:
visitYieldStatementin interfaceGroovyCodeVisitor- Overrides:
visitYieldStatementin classClassCodeVisitorSupport- Parameters:
statement- the yield statement to inspect- Since:
- 6.0.0
-
visitClosureExpression
Description copied from class:ClassCodeVisitorSupportVisits aClosureExpressionwith annotation processing, traversing parameter annotations before delegating to parent traversal.- Specified by:
visitClosureExpressionin interfaceGroovyCodeVisitor- Overrides:
visitClosureExpressionin classClassCodeVisitorSupport- Parameters:
expression- the closure expression to visit
-
visitLambdaExpression
Description copied from class:CodeVisitorSupportVisits aLambdaExpression, treating it as a closure expression.- Specified by:
visitLambdaExpressionin interfaceGroovyCodeVisitor- Overrides:
visitLambdaExpressionin classCodeVisitorSupport- Parameters:
expression- the lambda expression
-
visitBreakStatement
Verifies that abreakstatement appears in a valid context.- Specified by:
visitBreakStatementin interfaceGroovyCodeVisitor- Parameters:
breakStatement- the break statement to inspect
-
visitContinueStatement
Verifies that acontinuestatement appears in a valid loop context.- Specified by:
visitContinueStatementin interfaceGroovyCodeVisitor- Parameters:
continueStatement- the continue statement to inspect
-
visitAssertStatement
Visits an assert statement and then runs post-visit bookkeeping.- Specified by:
visitAssertStatementin interfaceGroovyCodeVisitor- Overrides:
visitAssertStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitBlockStatement
Visits a block statement and then runs post-visit bookkeeping.- Specified by:
visitBlockStatementin interfaceGroovyCodeVisitor- Overrides:
visitBlockStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit- See Also:
-
visitCaseStatement
Visits a case statement and then runs post-visit bookkeeping.- Specified by:
visitCaseStatementin interfaceGroovyCodeVisitor- Overrides:
visitCaseStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitCatchStatement
Visits a catch statement and then runs post-visit bookkeeping.- Specified by:
visitCatchStatementin interfaceGroovyCodeVisitor- Overrides:
visitCatchStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitEmptyStatement
Visits an empty statement and then runs post-visit bookkeeping.- Specified by:
visitEmptyStatementin interfaceGroovyCodeVisitor- Overrides:
visitEmptyStatementin classCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitExpressionStatement
Visits an expression statement and then runs post-visit bookkeeping.- Specified by:
visitExpressionStatementin interfaceGroovyCodeVisitor- Overrides:
visitExpressionStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitReturnStatement
Visits a return statement and then runs post-visit bookkeeping.- Specified by:
visitReturnStatementin interfaceGroovyCodeVisitor- Overrides:
visitReturnStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitSynchronizedStatement
Visits a synchronized statement and then runs post-visit bookkeeping.- Specified by:
visitSynchronizedStatementin interfaceGroovyCodeVisitor- Overrides:
visitSynchronizedStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitThrowStatement
Visits a throw statement and then runs post-visit bookkeeping.- Specified by:
visitThrowStatementin interfaceGroovyCodeVisitor- Overrides:
visitThrowStatementin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-
visitTryCatchFinally
Visits a try-catch-finally statement and then runs post-visit bookkeeping.- Specified by:
visitTryCatchFinallyin interfaceGroovyCodeVisitor- Overrides:
visitTryCatchFinallyin classClassCodeVisitorSupport- Parameters:
statement- the statement to visit
-