public abstract class BaseGenerator
extends Object
Base class for groovy-contracts code generators.
| Modifiers | Name | Description |
|---|---|---|
static String |
INVARIANT_CLOSURE_PREFIX |
Prefix used for synthetic methods that evaluate class invariants. |
static String |
META_DATA_USE_INLINE_MODE |
Node metadata flag indicating that assertions can be emitted in inline mode. |
protected ReaderSource |
source |
Reader source used by generators that need source-aware AST construction. |
| Constructor and description |
|---|
protected BaseGenerator(ReaderSource source)Creates a generator bound to the supplied reader source. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
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. |
|
protected static void |
ensureBlockBody(MethodNode method)Ensures the given method's body is a BlockStatement so that contract code generators can weave assertions into it. |
|
protected BlockStatement |
getInlineModeBlockStatement(BlockStatement blockStatement)Extracts the inline-mode assertion block from the supplied wrapper block. |
|
public static String |
getInvariantMethodName(ClassNode classNode)
|
|
public static MethodNode |
getInvariantMethodNode(ClassNode classNode)
|
|
protected BlockStatement |
wrapAssertionBooleanExpression(ClassNode type, MethodNode methodNode, BooleanExpression classInvariantExpression, String assertionType)Wraps a contract predicate with tracking, violation rethrowing, and execution guards. |
Prefix used for synthetic methods that evaluate class invariants.
Node metadata flag indicating that assertions can be emitted in inline mode.
Reader source used by generators that need source-aware AST construction.
Creates a generator bound to the supplied reader source.
source - the reader source backing the current source unitMerges inherited contract closures into the supplied predicate for the given method.
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 Ensures the given method's body is a BlockStatement so that contract code generators can
weave assertions into it. Earlier transforms (e.g. @Synchronized, which runs at
CANONICALIZATION) may have replaced the body with a non-block statement such as a
SynchronizedStatement; in that case the original statement is wrapped in a fresh block.
A null body (e.g. an abstract method or a not-yet-populated synthetic body) is left
untouched. Mirrors the body normalization the precondition path already performs (GROOVY-12066)
so the post-condition and invariant generators see a consistent body shape (GROOVY-12084).
method - the method whose body should be normalized to a blockExtracts the inline-mode assertion block from the supplied wrapper block.
blockStatement - the block containing generated assertion statements
classNode - the ClassNode used to look up the invariant closure field
classNode - the ClassNode used to look up the invariant closure fieldWraps a contract predicate with tracking, violation rethrowing, and execution guards.
type - the declaring classmethodNode - the method whose assertion is being emittedclassInvariantExpression - the predicate to evaluateassertionType - the logical assertion kindCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.