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.
| 34 | * Manages module-level information including the package, imports, and related AST construction utilities. |
| 35 | */ |
| 36 | public class ASTHelper { |
| 37 | |
| 38 | /** The SourceUnit controlling this helper. */ |
| 39 | private SourceUnit controller; |
| 40 | |
| 41 | /** The ClassLoader providing information on external types. */ |
| 42 | private ClassLoader classLoader; |
| 43 | |
| 44 | /** The output module node being constructed. */ |
| 45 | protected ModuleNode output; |
| 46 | |
| 47 | /** The package name in which the module is located. */ |
| 48 | private String packageName; |
| 49 | |
| 50 | /** Static map for type resolutions, cleared on each build for safety. */ |
| 51 | protected static final Map resolutions = new HashMap(); |
| 52 | |
| 53 | /** |
| 54 | * Constructs an ASTHelper with a source unit and class loader. |
| 55 | * |
| 56 | * @param controller the {@link SourceUnit} that controls this helper |
| 57 | * @param classLoader the {@link ClassLoader} for resolving external types |
| 58 | */ |
| 59 | public ASTHelper(SourceUnit controller, ClassLoader classLoader) { |
| 60 | this(); |
| 61 | this.controller = controller; |
| 62 | this.classLoader = classLoader; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Constructs an ASTHelper with no controller or class loader. |
| 67 | * These must be set later via {@link #setController(SourceUnit)} and {@link #setClassLoader(ClassLoader)}. |
| 68 | */ |
| 69 | public ASTHelper() { |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns the package name in which this module is located. |
| 74 | * |
| 75 | * @return the package name, or {@code null} if not set |
| 76 | */ |
| 77 | public String getPackageName() { |
| 78 | return packageName; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Sets the package name for this module (without trailing dot). |
| 83 | * Convenience method equivalent to {@code setPackage(packageName, new ArrayList<>())}. |
| 84 | * |
| 85 | * @param packageName the package name |
| 86 | */ |
| 87 | public void setPackageName(String packageName) { |
| 88 | setPackage(packageName, new ArrayList<>()); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets the package for this module with optional annotations. |
| 93 | * |
nothing calls this directly
no outgoing calls
no test coverage detected