Package org.apache.groovy.contracts.generation

# Class TryCatchBlockGenerator

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

public class TryCatchBlockGenerator extends Object
Creates a try-catch block around a given `AssertStatement` and catches a PowerAssertionError to reuse the generated visual output.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TryCatchBlockGenerator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static BlockStatement`
  `generateTryCatchBlock(ClassNode assertionErrorClass, String message, Statement assertStatement)`
  Wraps an assertion block so it returns a boolean result while preserving Groovy power assertion details.
  `static BlockStatement`
  `generateTryCatchBlockForInlineMode(ClassNode assertionErrorClass, String message, Statement assertStatement)`
  Wraps an inline assertion block so a Groovy power assertion is converted into the requested violation type.

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

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

- ## Constructor Details

  - ### TryCatchBlockGenerator

    public TryCatchBlockGenerator()

- ## Method Details

  - ### generateTryCatchBlockForInlineMode

    public static BlockStatement generateTryCatchBlockForInlineMode(ClassNode assertionErrorClass, String message, Statement assertStatement)
    Wraps an inline assertion block so a Groovy power assertion is converted into the requested violation type.
    Parameters:
      `assertionErrorClass` - the assertion violation class to instantiate on failure
      `message` - the message prefix to prepend to the power assertion output
      `assertStatement` - the assertion block to execute
    Returns:
      the generated try/catch wrapper

  - ### generateTryCatchBlock

    public static BlockStatement generateTryCatchBlock(ClassNode assertionErrorClass, String message, Statement assertStatement)
    Wraps an assertion block so it returns a boolean result while preserving Groovy power assertion details.
    Parameters:
      `assertionErrorClass` - the assertion violation class to instantiate on failure
      `message` - the message prefix to prepend to the power assertion output
      `assertStatement` - the assertion block to execute
    Returns:
      the generated try/catch wrapper that returns the assertion outcome