Package org.apache.groovy.contracts.ast
Class LoopInvariantASTTransformation
java.lang.Object
org.apache.groovy.contracts.ast.LoopInvariantASTTransformation
- All Implemented Interfaces:
CompilationUnitAware,ASTTransformation
public class LoopInvariantASTTransformation
extends Object
implements ASTTransformation, CompilationUnitAware
Handles
Invariant annotations placed on loop statements (for,
while, do-while). The invariant closure is evaluated as an
assertion at the start of each loop iteration.
When @Invariant is placed on a class (its original usage), this
transform returns immediately, letting the existing global contract pipeline
handle it.
Example:
int sum = 0
@Invariant({ 0 <= i && i <= 4 })
for (int i in 0..4) {
sum += i
}
- Since:
- 6.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the compilation unit currently applying this transformation.voidvisit(ASTNode[] nodes, SourceUnit source) Rewrites a loop-levelInvariantannotation into assertion checks injected at the start of the loop body.
-
Constructor Details
-
LoopInvariantASTTransformation
public LoopInvariantASTTransformation()
-
-
Method Details
-
setCompilationUnit
Description copied from interface:CompilationUnitAwareSets the compilation unit currently applying this transformation.- Specified by:
setCompilationUnitin interfaceCompilationUnitAware- Parameters:
unit- the active compilation unit
-
visit
Rewrites a loop-levelInvariantannotation into assertion checks injected at the start of the loop body.- Specified by:
visitin interfaceASTTransformation- Parameters:
nodes- the annotated AST nodes supplied by the compilersource- the current source unit
-