ClosureUtils (Groovy 4.0.10)
Description: declaration: package: org.codehaus.groovy.ast.tools, class: ClosureUtils

Package org.codehaus.groovy.ast.tools

# Class ClosureUtils

java.lang.Object
org.codehaus.groovy.ast.tools.ClosureUtils

public class ClosureUtils extends Object
Handy methods when working with Closure AST data structures.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClosureUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `convertClosureToSource(ReaderSource readerSource, ClosureExpression expression)`
  Converts a ClosureExpression into the String source.
  `static Parameter[]`
  `getParametersSafe(ClosureExpression ce)`
  `static String`
  `getResolveStrategyName(int resolveStrategy)`
  Returns the constant name associated with the given resolve strategy.
  `static boolean`
  `hasImplicitParameter(ClosureExpression ce)`
  `static boolean`
  `hasSingleCharacterArg(Closure c)`
  Does the Closure have a single char-like (char or Character) argument.
  `static boolean`
  `hasSingleStringArg(Closure c)`
  Does the Closure have a single String argument.

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

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

- ## Constructor Details

  - ### ClosureUtils

    public ClosureUtils()

- ## Method Details

  - ### convertClosureToSource

    public static String convertClosureToSource(ReaderSource readerSource, ClosureExpression expression) throws Exception
    Converts a ClosureExpression into the String source.
    Parameters:
      `readerSource` - a source
      `expression` - a closure. Can't be null
    Returns:
      the source the closure was created from
    Throws:
      `IllegalArgumentException` - when expression is null
      `Exception` - when closure can't be read from source

  - ### hasSingleCharacterArg

    public static boolean hasSingleCharacterArg(Closure c)
    Does the Closure have a single char-like (char or Character) argument.
    Parameters:
      `c` - a Closure
    Returns:
      true if it has exactly one argument and the type is char or Character

  - ### hasSingleStringArg

    public static boolean hasSingleStringArg(Closure c)
    Does the Closure have a single String argument.
    Parameters:
      `c` - a Closure
    Returns:
      true if it has exactly one argument and the type is String

  - ### hasImplicitParameter

    public static boolean hasImplicitParameter(ClosureExpression ce)
    Returns:
      true if the ClosureExpression has an implicit 'it' parameter

  - ### getParametersSafe

    public static Parameter[] getParametersSafe(ClosureExpression ce)
    Returns:
      the parameters for the ClosureExpression

  - ### getResolveStrategyName

    public static String getResolveStrategyName(int resolveStrategy)
    Returns the constant name associated with the given resolve strategy.
    Since:
      3.0.5