[Java] Class ClosureUtils

  • org.codehaus.groovy.ast.tools.ClosureUtils

Handy methods when working with Closure AST data structures.

Methods Summary

Methods
Type Params Return Type Name and description
static String convertClosureToSource(ReaderSource readerSource, ClosureExpression expression)
Converts a ClosureExpression into the String source.
static Parameter[] getParametersSafe(ClosureExpression ce)
@return the parameters for the ClosureExpression
static boolean hasImplicitParameter(ClosureExpression ce)
@return true if the ClosureExpression has an implicit 'it' parameter
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.

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

public static String convertClosureToSource(ReaderSource readerSource, ClosureExpression expression)

Converts a ClosureExpression into the String source.

throws:
java.lang.IllegalArgumentException when expression is null
throws:
java.lang.Exception when closure can't be read from source
Parameters:
readerSource - a source
expression - a closure. Can't be null
Returns:
the source the closure was created from

public static Parameter[] getParametersSafe(ClosureExpression ce)

Returns:
the parameters for the ClosureExpression

public static boolean hasImplicitParameter(ClosureExpression ce)

Returns:
true if the ClosureExpression has an implicit 'it' parameter

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

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

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.5.14/html/gapi/org/codehaus/groovy/ast/tools/ClosureUtils.html