Top Description Constructors Methods
org.codehaus.groovy.ast.tools

public Class ClosureUtils

extends Object
Class Inheritance
Imports
groovy.lang.Closure, org.codehaus.groovy.ast.Parameter, org.codehaus.groovy.ast.expr.ClosureExpression, org.codehaus.groovy.control.io.ReaderSource

Handy methods when working with Closure AST data structures.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the source the closure was created from
convertClosureToSource
(final ReaderSource
a source
readerSource
,
final ClosureExpression
a closure. Can't be null
expression
)

Converts a ClosureExpression into the String source.

public static Parameter[]

Returns:

the parameters for the ClosureExpression
getParametersSafe
(final ClosureExpression ce)

public static String
getResolveStrategyName(final int resolveStrategy)

Returns the constant name associated with the given resolve strategy.

public static boolean

Returns:

true if the ClosureExpression has an implicit 'it' parameter
hasImplicitParameter
(final ClosureExpression ce)

public static boolean

Returns:

true if it has exactly one argument and the type is char or Character
hasSingleCharacterArg
(final Closure<V>
a Closure
c
)

Does the Closure have a single char-like (char or Character) argument.

public static boolean

Returns:

true if it has exactly one argument and the type is String
hasSingleStringArg
(final Closure<V>
a Closure
c
)

Does the Closure have a single String argument.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ClosureUtilsback to summary
public ClosureUtils()

Method Detail

convertClosureToSourceback to summary
public static String convertClosureToSource(final ReaderSource readerSource, final ClosureExpression expression) throws Exception

Converts a ClosureExpression into the String source.

Parameters
readerSource:ReaderSource

a source

expression:ClosureExpression

a closure. Can't be null

Returns:String

the source the closure was created from

Exceptions
Exception:
when closure can't be read from source
IllegalArgumentException:
when expression is null
getParametersSafeback to summary
public static Parameter[] getParametersSafe(final ClosureExpression ce)
Returns:Parameter[]

the parameters for the ClosureExpression

getResolveStrategyNameback to summary
public static String getResolveStrategyName(final int resolveStrategy)

Returns the constant name associated with the given resolve strategy.

Since
3.0.5
See Also
Closure#DELEGATE_FIRST, et al.
hasImplicitParameterback to summary
public static boolean hasImplicitParameter(final ClosureExpression ce)
Returns:boolean

true if the ClosureExpression has an implicit 'it' parameter

hasSingleCharacterArgback to summary
public static boolean hasSingleCharacterArg(final Closure<V> c)

Does the Closure have a single char-like (char or Character) argument.

Parameters
c:Closure<V>

a Closure

Returns:boolean

true if it has exactly one argument and the type is char or Character

hasSingleStringArgback to summary
public static boolean hasSingleStringArg(final Closure<V> c)

Does the Closure have a single String argument.

Parameters
c:Closure<V>

a Closure

Returns:boolean

true if it has exactly one argument and the type is String