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.
| 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 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. |
| 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). |
The output module node being constructed.
Static map for type resolutions, cleared on each build for safety.
Constructs an ASTHelper with a source unit and class loader.
controller - the SourceUnit that controls this helperclassLoader - the ClassLoader for resolving external typesConstructs an ASTHelper with no controller or class loader. These must be set later via setController(SourceUnit) and setClassLoader(ClassLoader).
Adds a type import to the module.
Equivalent to addImport(type, name, aliasName, new ArrayList<>()).
type - the ClassNode to importname - the original namealiasName - the alias name to use (or the same as name if not aliased)Adds a type import to the module with optional annotations.
type - the ClassNode to importname - the original namealiasName - the alias name to use (or the same as name if not aliased)annotations - annotations for this import Adds a star import (imports all classes in a package) to the module.
Equivalent to addStarImport(importPackage, new ArrayList<>()).
importPackage - the package nameAdds a star import (imports all classes in a package) to the module with optional annotations.
importPackage - the package nameannotations - annotations for this import Adds a static import to the module.
Equivalent to addStaticImport(type, name, alias, new ArrayList<>()).
type - the ClassNode containing the static membername - the static member namealias - the alias to use in the codeAdds a static import to the module with optional annotations.
type - the ClassNode containing the static membername - the static member namealias - the alias to use in the codeannotations - annotations for this import Adds a static star import (imports all static members) to the module.
Equivalent to addStaticStarImport(type, importClass, new ArrayList<>()).
type - the ClassNode containing the static membersimportClass - the class nameAdds a static star import (imports all static members) to the module with optional annotations.
type - the ClassNode containing the static membersimportClass - the class nameannotations - annotations for this importJoins two names with a dot, returning the base name unchanged if empty. Useful for constructing fully qualified names.
base - the base name (typically a package), or nullname - the name to append (typically a class name)name if base is null or empty Equivalent to dot(base, ""). Returns the base with a trailing dot, or empty string.
Useful for constructing package names.
base - the base name (typically a package)Returns the class loader used for resolving external types.
null if not setReturns the source unit controlling this helper.
null if not setReturns the package name in which this module is located.
null if not setInitializes the output module node and clears resolution cache. Called at the start of parsing.
Sets the class loader to use for resolving external types.
classLoader - the ClassLoader to useSets the source unit that controls this helper.
controller - the SourceUnit to useSets the package for this module with optional annotations.
packageName - the package name (will have a dot appended if non-empty)annotations - annotations to apply to the package Sets the package name for this module (without trailing dot).
Convenience method equivalent to setPackage(packageName, new ArrayList<>()).
packageName - the package nameCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.