Package org.apache.groovy.contracts.generation

# Class PreconditionGenerator

java.lang.Object
org.apache.groovy.contracts.generation.BaseGenerator
org.apache.groovy.contracts.generation.PreconditionGenerator

public class PreconditionGenerator extends BaseGenerator
Code generator for preconditions.

- ## Field Summary

  ### Fields inherited from class org.apache.groovy.contracts.generation.BaseGenerator

  `INVARIANT_CLOSURE_PREFIX, META_DATA_USE_INLINE_MODE, source`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PreconditionGenerator(ReaderSource source)`
  Creates a generator for precondition support code.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `generateDefaultPreconditionStatement(ClassNode type, MethodNode methodNode)`
  Generates the default precondition statement for `MethodNode` instances with the `Precondition` annotation.
  `void`
  `generatePreconditionAssertionStatement(MethodNode method, Precondition precondition)`
  Injects a precondition assertion statement in the given `method`, based on the given `annotation` of type `Requires`.

  ### Methods inherited from class org.apache.groovy.contracts.generation.BaseGenerator

  `addCallsToSuperMethodNodeAnnotationClosure, ensureBlockBody, getInlineModeBlockStatement, getInvariantMethodName, getInvariantMethodNode, inlineModeKey, wrapAssertionBooleanExpression`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PreconditionGenerator

    public PreconditionGenerator(ReaderSource source)
    Creates a generator for precondition support code.
    Parameters:
      `source` - the reader source backing the current source unit

- ## Method Details

  - ### generatePreconditionAssertionStatement

    public void generatePreconditionAssertionStatement(MethodNode method, Precondition precondition)
    Injects a precondition assertion statement in the given `method`, based on the given `annotation` of type `Requires`.
    Parameters:
      `method` - the `MethodNode` for assertion injection
      `precondition` - the `Precondition` the assertion statement should be generated from

  - ### generateDefaultPreconditionStatement

    public void generateDefaultPreconditionStatement(ClassNode type, MethodNode methodNode)
    Generates the default precondition statement for `MethodNode` instances with the `Precondition` annotation.
    Parameters:
      `type` - the current `ClassNode`
      `methodNode` - the `MethodNode` with a `Precondition` annotation