Package org.codehaus.groovy.syntax

# Class ASTHelper

java.lang.Object
org.codehaus.groovy.syntax.ASTHelper

public class ASTHelper extends Object
Common base class providing shared AST helper methods used by both the classic and new parsers. Manages module-level information including the package, imports, and related AST construction utilities.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected ModuleNode`
  `output`
  The output module node being constructed.
  `protected static final Map`
  `resolutions`
  Static map for type resolutions, cleared on each build for safety.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ASTHelper()`
  Constructs an ASTHelper with no controller or class loader.
  `ASTHelper(SourceUnit controller, ClassLoader classLoader)`
  Constructs an ASTHelper with a source unit and class loader.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addImport(ClassNode type, String name, String aliasName)`
  Adds a type import to the module.
  `protected void`
  `addImport(ClassNode type, String name, String aliasName, List<AnnotationNode> annotations)`
  Adds a type import to the module with optional annotations.
  `protected void`
  `addStarImport(String importPackage)`
  Adds a star import (imports all classes in a package) to the module.
  `protected void`
  `addStarImport(String importPackage, List<AnnotationNode> annotations)`
  Adds a star import (imports all classes in a package) to the module with optional annotations.
  `protected void`
  `addStaticImport(ClassNode type, String name, String alias)`
  Adds a static import to the module.
  `protected void`
  `addStaticImport(ClassNode type, String name, String alias, List<AnnotationNode> annotations)`
  Adds a static import to the module with optional annotations.
  `protected void`
  `addStaticStarImport(ClassNode type, String importClass)`
  Adds a static star import (imports all static members) to the module.
  `protected void`
  `addStaticStarImport(ClassNode type, String importClass, List<AnnotationNode> annotations)`
  Adds a static star import (imports all static members) to the module with optional annotations.
  `protected String`
  `dot(String base)`
  Equivalent to `dot(base, "")`.
  `static String`
  `dot(String base, String name)`
  Joins two names with a dot, returning the base name unchanged if empty.
  `ClassLoader`
  `getClassLoader()`
  Returns the class loader used for resolving external types.
  `SourceUnit`
  `getController()`
  Returns the source unit controlling this helper.
  `String`
  `getPackageName()`
  Returns the package name in which this module is located.
  `protected void`
  `makeModule()`
  Initializes the output module node and clears resolution cache.
  `void`
  `setClassLoader(ClassLoader classLoader)`
  Sets the class loader to use for resolving external types.
  `void`
  `setController(SourceUnit controller)`
  Sets the source unit that controls this helper.
  `PackageNode`
  `setPackage(String packageName, List<AnnotationNode> annotations)`
  Sets the package for this module with optional annotations.
  `void`
  `setPackageName(String packageName)`
  Sets the package name for this module (without trailing dot).

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

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

- ## Field Details

  - ### output

    protected ModuleNode output
    The output module node being constructed.

  - ### resolutions

    protected static final Map resolutions
    Static map for type resolutions, cleared on each build for safety.

- ## Constructor Details

  - ### ASTHelper

    public ASTHelper(SourceUnit controller, ClassLoader classLoader)
    Constructs an ASTHelper with a source unit and class loader.
    Parameters:
      `controller` - the `SourceUnit` that controls this helper
      `classLoader` - the `ClassLoader` for resolving external types

  - ### ASTHelper

    public ASTHelper()
    Constructs an ASTHelper with no controller or class loader. These must be set later via `setController(SourceUnit)` and `setClassLoader(ClassLoader)`.

- ## Method Details

  - ### getPackageName

    public String getPackageName()
    Returns the package name in which this module is located.
    Returns:
      the package name, or `null` if not set

  - ### setPackageName

    public void setPackageName(String packageName)
    Sets the package name for this module (without trailing dot). Convenience method equivalent to `setPackage(packageName, new ArrayList<>())`.
    Parameters:
      `packageName` - the package name

  - ### setPackage

    public PackageNode setPackage(String packageName, List<AnnotationNode> annotations)
    Sets the package for this module with optional annotations.
    Parameters:
      `packageName` - the package name (will have a dot appended if non-empty)
      `annotations` - annotations to apply to the package
    Returns:
      the created `PackageNode`

  - ### getClassLoader

    public ClassLoader getClassLoader()
    Returns the class loader used for resolving external types.
    Returns:
      the `ClassLoader`, or `null` if not set

  - ### setClassLoader

    public void setClassLoader(ClassLoader classLoader)
    Sets the class loader to use for resolving external types.
    Parameters:
      `classLoader` - the `ClassLoader` to use

  - ### getController

    public SourceUnit getController()
    Returns the source unit controlling this helper.
    Returns:
      the `SourceUnit`, or `null` if not set

  - ### setController

    public void setController(SourceUnit controller)
    Sets the source unit that controls this helper.
    Parameters:
      `controller` - the `SourceUnit` to use

  - ### dot

    public static String dot(String base, String name)
    Joins two names with a dot, returning the base name unchanged if empty. Useful for constructing fully qualified names.
    Parameters:
      `base` - the base name (typically a package), or `null`
      `name` - the name to append (typically a class name)
    Returns:
      the joined name, or `name` if base is `null` or empty

  - ### makeModule

    protected void makeModule()
    Initializes the output module node and clears resolution cache. Called at the start of parsing.

  - ### dot

    protected String dot(String base)
    Equivalent to `dot(base, "")`. Returns the base with a trailing dot, or empty string. Useful for constructing package names.
    Parameters:
      `base` - the base name (typically a package)
    Returns:
      the base with a trailing dot, or empty string if base is empty

  - ### addImport

    protected void addImport(ClassNode type, String name, String aliasName)
    Adds a type import to the module. Equivalent to `addImport(type, name, aliasName, new ArrayList<>())`.
    Parameters:
      `type` - the `ClassNode` to import
      `name` - the original name
      `aliasName` - the alias name to use (or the same as name if not aliased)

  - ### addImport

    protected void addImport(ClassNode type, String name, String aliasName, List<AnnotationNode> annotations)
    Adds a type import to the module with optional annotations.
    Parameters:
      `type` - the `ClassNode` to import
      `name` - the original name
      `aliasName` - the alias name to use (or the same as name if not aliased)
      `annotations` - annotations for this import

  - ### addStaticImport

    protected void addStaticImport(ClassNode type, String name, String alias)
    Adds a static import to the module. Equivalent to `addStaticImport(type, name, alias, new ArrayList<>())`.
    Parameters:
      `type` - the `ClassNode` containing the static member
      `name` - the static member name
      `alias` - the alias to use in the code

  - ### addStaticImport

    protected void addStaticImport(ClassNode type, String name, String alias, List<AnnotationNode> annotations)
    Adds a static import to the module with optional annotations.
    Parameters:
      `type` - the `ClassNode` containing the static member
      `name` - the static member name
      `alias` - the alias to use in the code
      `annotations` - annotations for this import

  - ### addStaticStarImport

    protected void addStaticStarImport(ClassNode type, String importClass)
    Adds a static star import (imports all static members) to the module. Equivalent to `addStaticStarImport(type, importClass, new ArrayList<>())`.
    Parameters:
      `type` - the `ClassNode` containing the static members
      `importClass` - the class name

  - ### addStaticStarImport

    protected void addStaticStarImport(ClassNode type, String importClass, List<AnnotationNode> annotations)
    Adds a static star import (imports all static members) to the module with optional annotations.
    Parameters:
      `type` - the `ClassNode` containing the static members
      `importClass` - the class name
      `annotations` - annotations for this import

  - ### addStarImport

    protected void addStarImport(String importPackage)
    Adds a star import (imports all classes in a package) to the module. Equivalent to `addStarImport(importPackage, new ArrayList<>())`.
    Parameters:
      `importPackage` - the package name

  - ### addStarImport

    protected void addStarImport(String importPackage, List<AnnotationNode> annotations)
    Adds a star import (imports all classes in a package) to the module with optional annotations.
    Parameters:
      `importPackage` - the package name
      `annotations` - annotations for this import