MCPcopy Create free account
hub / github.com/apache/groovy / CompileUnit

Class CompileUnit

src/main/java/org/codehaus/groovy/ast/CompileUnit.java:49–320  ·  view source on GitHub ↗

Represents a complete compilation step involving one or more ModuleNode instances. A single CompileUnit is shared across all modules and classes compiled in one invocation, serving as a central repository for class metadata, import resolution, and compilation state. The compile u

Source from the content-addressed store, hash-verified

47 * @see CompilerConfiguration
48 */
49public class CompileUnit implements NodeMetaDataHandler {
50
51 private final CompilerConfiguration config;
52 private final GroovyClassLoader loader;
53 private final CodeSource codeSource;
54 private volatile Map<?, ?> metaDataMap;
55
56 private final List<ModuleNode> modules = new ArrayList<>();
57 private final Map<String, ClassNode> classes = new LinkedHashMap<>();
58 private final Map<String, ClassNode> classesToCompile = new LinkedHashMap<>();
59 private final Map<String, SourceUnit> classNameToSource = new LinkedHashMap<>();
60 private final Map<String, InnerClassNode> generatedInnerClasses = new LinkedHashMap<>();
61
62 /**
63 * Creates a compile unit with the given classloader and compiler configuration.
64 * The code source is set to {@code null}.
65 *
66 * @param classLoader the {@link GroovyClassLoader} to use for loading classes
67 * @param config the {@link CompilerConfiguration} defining compilation behavior
68 */
69 public CompileUnit(final GroovyClassLoader classLoader, final CompilerConfiguration config) {
70 this(classLoader, null, config);
71 }
72
73 /**
74 * Creates a compile unit with the given classloader, code source, and compiler configuration.
75 *
76 * @param classLoader the {@link GroovyClassLoader} to use for loading classes
77 * @param codeSource the {@link CodeSource} for code permissions or {@code null}
78 * @param config the {@link CompilerConfiguration} defining compilation behavior
79 */
80 public CompileUnit(final GroovyClassLoader classLoader, final CodeSource codeSource, final CompilerConfiguration config) {
81 this.loader = classLoader;
82 this.codeSource = codeSource;
83 this.config = config;
84 }
85
86 /**
87 * Returns the compiler configuration for this compilation.
88 *
89 * @return the {@link CompilerConfiguration}
90 */
91 public CompilerConfiguration getConfig() {
92 return config;
93 }
94
95 /**
96 * Returns the Groovy classloader used for loading classes during compilation.
97 *
98 * @return the {@link GroovyClassLoader}
99 */
100 public GroovyClassLoader getClassLoader() {
101 return loader;
102 }
103
104 /**
105 * Returns the code source used for Java security permissions.
106 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected