Class AssertStatementCreationUtility

java.lang.Object
org.apache.groovy.contracts.generation.AssertStatementCreationUtility

public final class AssertStatementCreationUtility extends Object
Central place to create AssertStatement instances in groovy-contracts. Utilized to centralize AssertionError message generation.
See Also:
  • Constructor Details

    • AssertStatementCreationUtility

      public AssertStatementCreationUtility()
  • Method Details

    • getAssertionStatements

      public static BlockStatement getAssertionStatements(List<BooleanExpression> booleanExpressions)
      Reusable method for creating assert statements for the given booleanExpression.
      Parameters:
      booleanExpressions - the assertion's BooleanExpression instances
      Returns:
      a newly created AssertStatement
    • getAssertionStatement

      public static AssertStatement getAssertionStatement(BooleanExpression booleanExpression)
      Reusable method for creating assert statements for the given booleanExpression.
      Parameters:
      booleanExpression - the assertion's BooleanExpression
      Returns:
      a newly created AssertStatement
    • getReturnStatements

      public static List<ReturnStatement> getReturnStatements(MethodNode method)
      Gets a list of ReturnStatement instances from the given MethodNode.
      Parameters:
      method - the MethodNode that holds the given lastStatement
      Returns:
      a ReturnStatement or null
    • injectResultVariableReturnStatementAndAssertionCallStatement

      public static void injectResultVariableReturnStatementAndAssertionCallStatement(BlockStatement statement, ClassNode returnType, ReturnStatement returnStatement, BlockStatement assertionCallStatement)
      Rewrites the target return statement so it stores the result value, executes the assertion block, and then returns the stored result.
      Parameters:
      statement - the surrounding block to rewrite
      returnType - the declared return type
      returnStatement - the return statement to replace
      assertionCallStatement - the assertion block to insert
    • addAssertionCallStatementToReturnStatement

      public static void addAssertionCallStatementToReturnStatement(BlockStatement statement, ReturnStatement returnStatement, Statement assertionCallStatement)
      Rewrites the target return statement so it evaluates the return expression once, executes the assertion call, and finally returns the stored value.
      Parameters:
      statement - the surrounding block to rewrite
      returnStatement - the return statement to replace
      assertionCallStatement - the assertion statement to insert