Package: org.codehaus.groovy.syntax

## [Java] Class ASTHelper

- 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
    Modifiers | Name | Description
    --- | --- | ---
    `protected ModuleNode` | `output` | The output module node being constructed.
    `protected static Map` | `resolutions` | Static map for type resolutions, cleared on each build for safety.

  - ### Constructor Summary

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

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and 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.
    `` | `public static String` | `dot(String base, String name)` Joins two names with a dot, returning the base name unchanged if empty.
    `` | `protected String` | `dot(String base)` Equivalent to `dot(base, "")`.
    `` | `public ClassLoader` | `getClassLoader()` Returns the class loader used for resolving external types.
    `` | `public SourceUnit` | `getController()` Returns the source unit controlling this helper.
    `` | `public String` | `getPackageName()` Returns the package name in which this module is located.
    `` | `protected void` | `makeModule()` Initializes the output module node and clears resolution cache.
    `` | `public void` | `setClassLoader(ClassLoader classLoader)` Sets the class loader to use for resolving external types.
    `` | `public void` | `setController(SourceUnit controller)` Sets the source unit that controls this helper.
    `` | `public PackageNode` | `setPackage(String packageName, List<AnnotationNode> annotations)` Sets the package for this module with optional annotations.
    `` | `public void` | `setPackageName(String packageName)` Sets the package name for this module (without trailing dot).

  - ### Inherited Methods Summary

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

- - ### Field Detail

    - #### 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 Detail

    - #### 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

    - #### public ASTHelper()

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

  - ### Method Detail

    - #### 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)

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### public ClassLoader getClassLoader()

      Returns the class loader used for resolving external types.

      Returns:
        the ClassLoader, or `null` if not set

    - #### public SourceUnit getController()

      Returns the source unit controlling this helper.

      Returns:
        the SourceUnit, or `null` if not set

    - #### public String getPackageName()

      Returns the package name in which this module is located.

      Returns:
        the package name, or `null` if not set

    - #### protected void makeModule()

      Initializes the output module node and clears resolution cache. Called at the start of parsing.

    - #### public void setClassLoader(ClassLoader classLoader)

      Sets the class loader to use for resolving external types.

      Parameters:
        `classLoader` - the ClassLoader to use

    - #### public void setController(SourceUnit controller)

      Sets the source unit that controls this helper.

      Parameters:
        `controller` - the SourceUnit to use

    - #### 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

    - #### 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