Class GeneralUtils

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

public class GeneralUtils extends Object
Handy methods when working with the Groovy AST. Provides factory methods for creating common AST nodes and utility methods for expression and statement construction.

This utility class offers shorthand methods (often with abbreviated names) for building AST structures:

  • Statement constructors: block(), expr(), assign(), ret(), etc.
  • Expression constructors: var(), constX(), classX(), cast(), etc.
  • Operator expressions: binX(), andX(), orX(), cmp(), etc.
  • Collection literals: list(), map(), tuple(), array(), etc.
  • Method calls: call(), invokeMethod(), staticCall(), etc.

Common patterns use abbreviated names like X suffix for expression factories (e.g., varX() for VariableExpression) and S suffix for statement factories (e.g., blockS() for BlockStatement).

Null Handling: Most methods handle null gracefully, often returning empty or no-op structures rather than throwing exceptions.

See Also: