public class CompilationUnit extends JavaNonTerminalProgramElement implements TypeDeclarationContainer, TypeScope
TypeDeclarations and an optional PackageSpecification
and an optional set of Imports. In Java, any source file
may contain at most one public class type definition.
This class is taken from COMPOST and changed so that it can be
used as an immutable classJavaProgramElement.NameAbstractionTableDisabled| Modifier and Type | Field and Description |
|---|---|
protected ImmutableArray<Import> |
imports
Imports.
|
protected PackageSpecification |
packageSpec
Package spec.
|
protected ImmutableArray<TypeDeclaration> |
typeDeclarations
Type declarations.
|
| Constructor and Description |
|---|
CompilationUnit(ExtList children)
creates a compilation unit
|
CompilationUnit(PackageSpecification packageSpec,
Import[] imports,
TypeDeclaration[] typeDeclarations)
creates a compilation unit
|
| Modifier and Type | Method and Description |
|---|---|
ProgramElement |
getChildAt(int index)
Returns the child at the specified index in this node's "virtual"
child array
|
int |
getChildCount()
Returns the number of children of this node.
|
ImmutableArray<TypeDeclaration> |
getDeclarations()
Get declarations.
|
SourceElement |
getFirstElement()
Finds the source element that occurs first in the source.
|
SourceElement |
getFirstElementIncludingBlocks()
Finds the source element that occurs first in the source.
|
ImmutableArray<Import> |
getImports()
Get imports.
|
SourceElement |
getLastElement()
Finds the source element that occurs last in the source.
|
java.lang.String |
getName()
Get name of the unit.
|
PackageSpecification |
getPackageSpecification()
Get package specification.
|
TypeDeclaration |
getPrimaryTypeDeclaration()
Gets the primary type declaration of the compilation unit.
|
TypeDeclaration |
getTypeDeclarationAt(int index) |
int |
getTypeDeclarationCount()
Get the number of type declarations in this container.
|
void |
prettyPrint(PrettyPrinter p)
Pretty printing the source element.
|
java.lang.String |
toString()
toString
|
void |
visit(Visitor v)
calls the corresponding method of a visitor in order to
perform some action/transformation on this element
|
compatibleBlockSize, computeHashCode, equals, equalsModRenaming, getArrayPos, match, matchChildrengetComments, hashCode, prettyPrintMain, reuseSignaturegetEndPosition, getParentClass, getPositionInfo, getRelativePosition, getStartPosition, setParentClass, toSource, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetComments, matchequalsModRenaming, getEndPosition, getPositionInfo, getRelativePosition, getStartPositionprotected final PackageSpecification packageSpec
protected final ImmutableArray<Import> imports
protected final ImmutableArray<TypeDeclaration> typeDeclarations
public CompilationUnit(PackageSpecification packageSpec, Import[] imports, TypeDeclaration[] typeDeclarations)
packageSpec - a PackageSpecification (pck of this CU)imports - an array of Import (all it imports)typeDeclarations - an array of TypeDeclaration (the
type declared in it)public CompilationUnit(ExtList children)
children - list with the children of this unitpublic SourceElement getFirstElement()
JavaSourceElementgetFirstElement in interface SourceElementgetFirstElement in class JavaSourceElementJavaSourceElement.toSource(),
JavaSourceElement.getStartPosition()public SourceElement getFirstElementIncludingBlocks()
SourceElementgetFirstElementIncludingBlocks in interface SourceElementgetFirstElementIncludingBlocks in class JavaSourceElementSourceElement.getStartPosition()public SourceElement getLastElement()
JavaSourceElementgetLastElement in interface SourceElementgetLastElement in class JavaSourceElementJavaSourceElement.toSource(),
JavaSourceElement.getEndPosition()public java.lang.String getName()
public int getChildCount()
getChildCount in interface NonTerminalProgramElementpublic ProgramElement getChildAt(int index)
getChildAt in interface NonTerminalProgramElementindex - an index into this node's "virtual" child arrayjava.lang.ArrayIndexOutOfBoundsException - if index is out
of boundspublic ImmutableArray<Import> getImports()
public PackageSpecification getPackageSpecification()
public int getTypeDeclarationCount()
getTypeDeclarationCount in interface TypeDeclarationContainerpublic TypeDeclaration getTypeDeclarationAt(int index)
getTypeDeclarationAt in interface TypeDeclarationContainerpublic ImmutableArray<TypeDeclaration> getDeclarations()
public TypeDeclaration getPrimaryTypeDeclaration()
null.public void prettyPrint(PrettyPrinter p) throws java.io.IOException
JavaSourceElementprettyPrint in interface SourceElementprettyPrint in class JavaProgramElementp - a pretty printer.java.io.IOException - occasionally thrown.public void visit(Visitor v)
visit in interface SourceElementv - the Visitorpublic java.lang.String toString()
toString in class JavaSourceElement