Class BaseGenerator
java.lang.Object
org.apache.groovy.contracts.generation.BaseGenerator
- Direct Known Subclasses:
ClassInvariantGenerator,PostconditionGenerator,PreconditionGenerator
Base class for groovy-contracts code generators.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPrefix used for synthetic methods that evaluate class invariants.static final StringNode metadata flag indicating that assertions can be emitted in inline mode.protected final ReaderSourceReader source used by generators that need source-aware AST construction. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseGenerator(ReaderSource source) Creates a generator bound to the supplied reader source. -
Method Summary
Modifier and TypeMethodDescriptionprotected BooleanExpressionaddCallsToSuperMethodNodeAnnotationClosure(ClassNode type, MethodNode methodNode, Class<? extends Annotation> annotationType, BooleanExpression booleanExpression, boolean isPostcondition) Merges inherited contract closures into the supplied predicate for the given method.protected BlockStatementgetInlineModeBlockStatement(BlockStatement blockStatement) Extracts the inline-mode assertion block from the supplied wrapper block.static StringgetInvariantMethodName(ClassNode classNode) static MethodNodegetInvariantMethodNode(ClassNode classNode) protected BlockStatementwrapAssertionBooleanExpression(ClassNode type, MethodNode methodNode, BooleanExpression classInvariantExpression, String assertionType) Wraps a contract predicate with tracking, violation rethrowing, and execution guards.
-
Field Details
-
INVARIANT_CLOSURE_PREFIX
Prefix used for synthetic methods that evaluate class invariants.- See Also:
-
META_DATA_USE_INLINE_MODE
Node metadata flag indicating that assertions can be emitted in inline mode.- See Also:
-
source
Reader source used by generators that need source-aware AST construction.
-
-
Constructor Details
-
BaseGenerator
Creates a generator bound to the supplied reader source.- Parameters:
source- the reader source backing the current source unit
-
-
Method Details
-
getInvariantMethodName
- Parameters:
classNode- theClassNodeused to look up the invariant closure field- Returns:
- the field name of the invariant closure field of the given classNode
-
getInvariantMethodNode
- Parameters:
classNode- theClassNodeused to look up the invariant closure field- Returns:
- the
MethodNodewhich contains the invariant of the given classNode
-
getInlineModeBlockStatement
Extracts the inline-mode assertion block from the supplied wrapper block.- Parameters:
blockStatement- the block containing generated assertion statements- Returns:
- an inline-mode block guarded by the contracts-enabled flag
-
wrapAssertionBooleanExpression
protected BlockStatement wrapAssertionBooleanExpression(ClassNode type, MethodNode methodNode, BooleanExpression classInvariantExpression, String assertionType) Wraps a contract predicate with tracking, violation rethrowing, and execution guards.- Parameters:
type- the declaring classmethodNode- the method whose assertion is being emittedclassInvariantExpression- the predicate to evaluateassertionType- the logical assertion kind- Returns:
- the generated wrapper block
-
addCallsToSuperMethodNodeAnnotationClosure
protected BooleanExpression addCallsToSuperMethodNodeAnnotationClosure(ClassNode type, MethodNode methodNode, Class<? extends Annotation> annotationType, BooleanExpression booleanExpression, boolean isPostcondition) Merges inherited contract closures into the supplied predicate for the given method.- Parameters:
type- the declaring classmethodNode- the method whose inherited contracts should be consultedannotationType- the contract meta-annotation to search forbooleanExpression- the predicate built from the current declarationisPostcondition- whether postcondition calling conventions should be used- Returns:
- the predicate augmented with inherited contract closures
-