Package org.codehaus.janino

# Class Java.CompilationUnit

java.lang.Object
org.codehaus.janino.Java.AbstractCompilationUnit
org.codehaus.janino.Java.CompilationUnit

All Implemented Interfaces:
  `Java.Scope`

Enclosing class:
  `Java`

public static final class Java.CompilationUnit extends Java.AbstractCompilationUnit
Representation of an "ordinary compilation unit" as explained in JLS9 7.3 (before Java 9 known as "compilation unit" and described in JLS8 7.3).

## Nested Class Summary

## Nested classes/interfaces inherited from class org.codehaus.janino.Java.AbstractCompilationUnit

`Java.AbstractCompilationUnit.ImportDeclaration, Java.AbstractCompilationUnit.SingleStaticImportDeclaration, Java.AbstractCompilationUnit.SingleTypeImportDeclaration, Java.AbstractCompilationUnit.StaticImportOnDemandDeclaration, Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration`

## Field Summary

Fields
Modifier and Type
Field
Description
`Java.PackageDeclaration`
`packageDeclaration`
The package declaration at the very top of this compilation unit (if any).
`final List<Java.PackageMemberTypeDeclaration>`
`packageMemberTypeDeclarations`
The top-level declarations in this compilation unit.

### Fields inherited from class org.codehaus.janino.Java.AbstractCompilationUnit

`fileName, importDeclarations`

## Constructor Summary

Constructors
Constructor
Description
`CompilationUnit(String fileName)`
`CompilationUnit(String fileName, Java.AbstractCompilationUnit.ImportDeclaration[] importDeclarations)`

## Method Summary

Modifier and Type
Method
Description
`<R, EX extends Throwable>
R`
`accept(Visitor.AbstractCompilationUnitVisitor<R,EX> visitor)`
Invokes the "`visit...()`" method of `Visitor.AbstractCompilationUnitVisitor` for the concrete `Java.AbstractCompilationUnit` type.
`void`
`addPackageMemberTypeDeclaration(Java.PackageMemberTypeDeclaration pmtd)`
Adds one top-level type declaration to this compilation unit.
`Java.PackageMemberTypeDeclaration`
`getPackageMemberTypeDeclaration(String name)`
Returns the package member class or interface declared with the given name.
`Java.PackageMemberTypeDeclaration[]`
`getPackageMemberTypeDeclarations()`
Gets all classes and interfaces declared in this compilation unit.
`void`
`setPackageDeclaration(Java.PackageDeclaration packageDeclaration)`
Sets the package declaration of this compilation unit.

### Methods inherited from class org.codehaus.janino.Java.AbstractCompilationUnit

`getEnclosingScope`

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

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

## Field Details

### packageDeclaration

@Nullable public Java.PackageDeclaration packageDeclaration
The package declaration at the very top of this compilation unit (if any).

### packageMemberTypeDeclarations

public final List<Java.PackageMemberTypeDeclaration> packageMemberTypeDeclarations
The top-level declarations in this compilation unit.

## Constructor Details

### CompilationUnit

public CompilationUnit(@Nullable String fileName)

### CompilationUnit

public CompilationUnit(@Nullable String fileName, Java.AbstractCompilationUnit.ImportDeclaration[] importDeclarations)

## Method Details

### setPackageDeclaration

public void setPackageDeclaration(@Nullable Java.PackageDeclaration packageDeclaration)
Sets the package declaration of this compilation unit.

### addPackageMemberTypeDeclaration

public void addPackageMemberTypeDeclaration(Java.PackageMemberTypeDeclaration pmtd)
Adds one top-level type declaration to this compilation unit.

### getPackageMemberTypeDeclarations

public Java.PackageMemberTypeDeclaration[] getPackageMemberTypeDeclarations()
Gets all classes and interfaces declared in this compilation unit.

### getPackageMemberTypeDeclaration

@Nullable public Java.PackageMemberTypeDeclaration getPackageMemberTypeDeclaration(String name)
Returns the package member class or interface declared with the given name.

Parameters:
  `name` - Declared (i.e. not the fully qualified) name
Returns:
  `null` if a package member type with that name is not declared in this compilation unit

### accept

@Nullable public <R, EX extends Throwable> R accept(Visitor.AbstractCompilationUnitVisitor<R,EX> visitor) throws EX
Description copied from class: `Java.AbstractCompilationUnit`
Invokes the "`visit...()`" method of `Visitor.AbstractCompilationUnitVisitor` for the concrete `Java.AbstractCompilationUnit` type.

Specified by:
  `accept` in class `Java.AbstractCompilationUnit`
Throws:
  `EX`