Class Contract

java.lang.Object
org.apache.groovy.contracts.domain.Contract

public class Contract extends Object

Represents a contract between a supplier and a customer of a class.

  • Constructor Details

    • Contract

      public Contract(ClassNode classNode)
      Creates a contract model for the supplied class.
      Parameters:
      classNode - the class described by this contract
  • Method Details

    • classNode

      public ClassNode classNode()
      Returns the class represented by this contract.
      Returns:
      the contracted class node
    • setClassInvariant

      public void setClassInvariant(ClassInvariant classInvariant)
      Replaces the class invariant associated with this contract.
      Parameters:
      classInvariant - the invariant to store
    • preconditions

      public AssertionMap<Precondition> preconditions()
      Returns the preconditions indexed by method.
      Returns:
      the precondition map
    • postconditions

      public AssertionMap<Postcondition> postconditions()
      Returns the postconditions indexed by method.
      Returns:
      the postcondition map
    • hasDefaultClassInvariant

      public boolean hasDefaultClassInvariant()
      Indicates whether the contract still uses the shared default class invariant.
      Returns:
      true if no custom class invariant has been set
    • classInvariant

      public ClassInvariant classInvariant()
      Returns the current class invariant.
      Returns:
      the configured class invariant