Package org.codehaus.groovy.ast

## Class CompileUnit

- java.lang.Object
- - org.codehaus.groovy.ast.CompileUnit

-     public class CompileUnit
      extends Object

  Represents the entire contents of a compilation step which consists of one or more `ModuleNode` instances. There's one instance of this that's shared by all modules and classes compiled during a single invocation of the compiler.

  It's attached to MethodNodes and ClassNodes and is used to find fully qualified names of classes, resolve imports, and that sort of thing.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `CompileUnit.ConstructedOuterNestedClassNode` | Represents a resolved type as a placeholder, SEE GROOVY-7812

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CompileUnit​(GroovyClassLoader classLoader, CodeSource codeSource, CompilerConfiguration config)` |
    `CompileUnit​(GroovyClassLoader classLoader, CompilerConfiguration config)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addClass​(ClassNode node)` | Adds a class to the unit.
    `void` | `addClassNodeToCompile​(ClassNode node, SourceUnit location)` | this method actually does not compile a class.
    `void` | `addClassNodeToResolve​(CompileUnit.ConstructedOuterNestedClassNode cn)` | Add a constructed class node as a placeholder to resolve outer nested class further.
    `void` | `addGeneratedInnerClass​(InnerClassNode icn)` |
    `void` | `addModule​(ModuleNode node)` |
    `ClassNode` | `getClass​(String name)` |
    `List<ClassNode>` | `getClasses()` |
    `Map<String,​ClassNode>` | `getClassesToCompile()` |
    `Map<String,​CompileUnit.ConstructedOuterNestedClassNode>` | `getClassesToResolve()` |
    `GroovyClassLoader` | `getClassLoader()` |
    `CodeSource` | `getCodeSource()` |
    `CompilerConfiguration` | `getConfig()` |
    `InnerClassNode` | `getGeneratedInnerClass​(String name)` |
    `Map<String,​InnerClassNode>` | `getGeneratedInnerClasses()` |
    `ListHashMap` | `getMetaDataMap()` |
    `List<ModuleNode>` | `getModules()` |
    `Map<?,​?>` | `getNodeMetaData()` | Returns an unmodifiable view of the current node metadata.
    `<T> T` | `getNodeMetaData​(Object key)` | Gets the node meta data for the provided key.
    `SourceUnit` | `getScriptSourceLocation​(String className)` |
    `boolean` | `hasClassNodeToCompile()` |
    `Iterator<String>` | `iterateClassNodeToCompile()` |
    `Object` | `putNodeMetaData​(Object key, Object value)` | Sets the node meta data but allows overwriting values.
    `void` | `removeNodeMetaData​(Object key)` | Removes a node meta data entry.
    `void` | `setNodeMetaData​(Object key, Object value)` | Sets the node meta data for the provided key.

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

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

- - ### Constructor Detail

    - #### CompileUnit

          public CompileUnit​(GroovyClassLoader classLoader,
                             CompilerConfiguration config)

    - #### CompileUnit

          public CompileUnit​(GroovyClassLoader classLoader,
                             CodeSource codeSource,
                             CompilerConfiguration config)

  - ### Method Detail

    - #### getModules

          public List<ModuleNode> getModules()

    - #### addModule

          public void addModule​(ModuleNode node)

    - #### getClass

          public ClassNode getClass​(String name)

      Returns:
        the ClassNode for the given qualified name or returns null if the name does not exist in the current compilation unit (ignoring the .class files on the classpath)

    - #### getClasses

          public List<ClassNode> getClasses()

      Returns:
        a list of all the classes in each module in the compilation unit

    - #### getConfig

          public CompilerConfiguration getConfig()

    - #### getClassLoader

          public GroovyClassLoader getClassLoader()

    - #### getCodeSource

          public CodeSource getCodeSource()

    - #### addClass

          public void addClass​(ClassNode node)

      Adds a class to the unit.

    - #### addClassNodeToCompile

          public void addClassNodeToCompile​(ClassNode node,
                                            SourceUnit location)

      this method actually does not compile a class. It's only a marker that this type has to be compiled by the CompilationUnit at the end of a parse step no node should be be left.

    - #### getScriptSourceLocation

          public SourceUnit getScriptSourceLocation​(String className)

    - #### hasClassNodeToCompile

          public boolean hasClassNodeToCompile()

    - #### iterateClassNodeToCompile

          public Iterator<String> iterateClassNodeToCompile()

    - #### getGeneratedInnerClass

          public InnerClassNode getGeneratedInnerClass​(String name)

    - #### addGeneratedInnerClass

          public void addGeneratedInnerClass​(InnerClassNode icn)

    - #### getGeneratedInnerClasses

          public Map<String,​InnerClassNode> getGeneratedInnerClasses()

    - #### getClassesToCompile

          public Map<String,​ClassNode> getClassesToCompile()

    - #### getClassesToResolve

          public Map<String,​CompileUnit.ConstructedOuterNestedClassNode> getClassesToResolve()

    - #### addClassNodeToResolve

          public void addClassNodeToResolve​(CompileUnit.ConstructedOuterNestedClassNode cn)

      Add a constructed class node as a placeholder to resolve outer nested class further.
      Parameters:
        `cn` - the constructed class node

    - #### getNodeMetaData

          public <T> T getNodeMetaData​(Object key)

      Gets the node meta data for the provided key.
      Parameters:
        `key` - - the meta data key
      Returns:
        the node meta data value for this key

    - #### setNodeMetaData

          public void setNodeMetaData​(Object key,
                                      Object value)

      Sets the node meta data for the provided key.
      Parameters:
        `key` - - the meta data key
        `value` - - the meta data value
      Throws:
        `GroovyBugError` - if key is null or there is already meta data under that key

    - #### putNodeMetaData

          public Object putNodeMetaData​(Object key,
                                        Object value)

      Sets the node meta data but allows overwriting values.
      Parameters:
        `key` - - the meta data key
        `value` - - the meta data value
      Returns:
        the old node meta data value for this key
      Throws:
        `GroovyBugError` - if key is null

    - #### removeNodeMetaData

          public void removeNodeMetaData​(Object key)

      Removes a node meta data entry.
      Parameters:
        `key` - - the meta data key
      Throws:
        `GroovyBugError` - if the key is null

    - #### getNodeMetaData

          public Map<?,​?> getNodeMetaData()

      Returns an unmodifiable view of the current node metadata.
      Returns:
        the node metadata. Always not null.

    - #### getMetaDataMap

          public ListHashMap getMetaDataMap()