public class CompilationUnit extends JavaNonTerminalProgramElement implements TypeDeclarationContainer, TypeScope
TypeDeclaration
s and an optional PackageSpecification
and an optional set of Import
s. 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, matchChildren
getComments, hashCode, prettyPrintMain, reuseSignature
getEndPosition, getParentClass, getPositionInfo, getRelativePosition, getStartPosition, setParentClass, toSource, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getComments, match
equalsModRenaming, getEndPosition, getPositionInfo, getRelativePosition, getStartPosition
protected 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()
JavaSourceElement
getFirstElement
in interface SourceElement
getFirstElement
in class JavaSourceElement
JavaSourceElement.toSource()
,
JavaSourceElement.getStartPosition()
public SourceElement getFirstElementIncludingBlocks()
SourceElement
getFirstElementIncludingBlocks
in interface SourceElement
getFirstElementIncludingBlocks
in class JavaSourceElement
SourceElement.getStartPosition()
public SourceElement getLastElement()
JavaSourceElement
getLastElement
in interface SourceElement
getLastElement
in class JavaSourceElement
JavaSourceElement.toSource()
,
JavaSourceElement.getEndPosition()
public java.lang.String getName()
public int getChildCount()
getChildCount
in interface NonTerminalProgramElement
public ProgramElement getChildAt(int index)
getChildAt
in interface NonTerminalProgramElement
index
- 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 TypeDeclarationContainer
public TypeDeclaration getTypeDeclarationAt(int index)
getTypeDeclarationAt
in interface TypeDeclarationContainer
public ImmutableArray<TypeDeclaration> getDeclarations()
public TypeDeclaration getPrimaryTypeDeclaration()
null
.public void prettyPrint(PrettyPrinter p) throws java.io.IOException
JavaSourceElement
prettyPrint
in interface SourceElement
prettyPrint
in class JavaProgramElement
p
- a pretty printer.java.io.IOException
- occasionally thrown.public void visit(Visitor v)
visit
in interface SourceElement
v
- the Visitorpublic java.lang.String toString()
toString
in class JavaSourceElement