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.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.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.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.Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, visitAnnotation, visitAnnotations, visitAnnotations, visitClass, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitDeclarationExpression, visitField, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitStatementAnnotationsMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitFieldExpression, visitGStringExpression, visitLambdaExpression, 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
-
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
-