Package groovy.contracts


package groovy.contracts
Design-by-contract (DbC) support with compile-time assertion generation.

Stable annotations:

  • @Requires – method precondition
  • @Ensures – method postcondition; closures may reference result and old
  • @Invariant – class invariant, also usable as a loop invariant on for / while / do-while loops
  • @Contracted – package- or class-level opt-in marker that enables contract processing

Incubating in 6.0.0 (semantics may evolve in a subsequent 6.x release):

  • @Modifies – frame condition declaring which fields and parameters a method may modify
  • @Decreases – a termination measure (a strictly-decreasing, well-founded variant) for a loop (per iteration) or a recursive method (per recursive re-entry)
  • Annotation Interfaces
    Class
    Description
    Package-level and class-level annotation indicating that the package is enabled for class-invariants, pre- and post-conditions.
    Specifies a termination measure, either for a loop or for a (recursive) method.
    Represents a method postcondition.
    Container annotation for multiple Ensures postconditions on the same target.
    Represents a class-invariant or a loop invariant.
    Container annotation for multiple Invariant declarations on the same type.
    Declares the frame condition for a method: the set of fields and parameters that the method is allowed to modify.
    Container for multiple Modifies annotations on the same method.
    Represents a method precondition.
    Container annotation for multiple Requires preconditions on the same target.