public final class CompilationUnit
extends java.lang.Object
implements org.macroing.cit.java.util.node.Node
CompilationUnit
denotes the nonterminal symbol CompilationUnit, as defined by the Java Language Specification.
This class is mutable and therefore not suitable for concurrent use without external synchronization.
Modifier and Type | Method and Description |
---|---|
boolean |
accept(org.macroing.cit.java.util.node.NodeHierarchicalVisitor nodeHierarchicalVisitor)
Accepts a
NodeHierarchicalVisitor . |
void |
addComment(Comment comment)
Adds a
Comment to the end of this CompilationUnit instance. |
void |
addImportDeclaration(ImportDeclaration importDeclaration)
Adds an
ImportDeclaration to the end of the ImportDeclaration s section of this CompilationUnit instance. |
void |
addTypeDeclaration(TypeDeclaration typeDeclaration)
|
void |
addWhiteSpace(WhiteSpace whiteSpace)
Adds a
WhiteSpace to the end of this CompilationUnit instance. |
boolean |
equals(java.lang.Object object)
Returns
true if, and only if, object is an instance of CompilationUnit , and that CompilationUnit instance is equal to this CompilationUnit instance, false otherwise. |
java.util.List<ImportDeclaration> |
getImportDeclarations()
Returns a
List with all currently added ImportDeclaration s. |
java.util.List<TypeDeclaration> |
getTypeDeclarations()
Returns a
List with all currently added TypeDeclaration s. |
int |
hashCode()
Returns a hash code for this
CompilationUnit instance. |
static CompilationUnit |
newInstance()
Returns a new empty
CompilationUnit instance. |
void |
removeComment(Comment comment)
|
void |
removeImportDeclaration(ImportDeclaration importDeclaration)
Removes the first
ImportDeclaration from the end of the ImportDeclaration s section of this CompilationUnit instance, that is equal to importDeclaration . |
void |
removeTypeDeclaration(TypeDeclaration typeDeclaration)
Removes the first
TypeDeclaration from the end of the TypeDeclaration s section of this CompilationUnit instance, that is equal to typeDeclaration . |
void |
removeWhiteSpace(WhiteSpace whiteSpace)
Removes the first
WhiteSpace from the end of this CompilationUnit instance, that is equal to whiteSpace . |
java.lang.String |
toString()
Returns a
String representation of this CompilationUnit instance. |
public boolean accept(org.macroing.cit.java.util.node.NodeHierarchicalVisitor nodeHierarchicalVisitor)
NodeHierarchicalVisitor
.
Returns the result of nodeHierarchicalVisitor.visitLeave(this)
.
If nodeHierarchicalVisitor
is null
, a NullPointerException
will be thrown.
If a RuntimeException
is thrown by the current NodeHierarchicalVisitor
, a NodeTraversalException
will be thrown with the RuntimeException
wrapped.
This implementation will:
NullPointerException
if nodeHierarchicalVisitor
is null
.NodeTraversalException
if nodeHierarchicalVisitor
throws a RuntimeException
.Node
s, if it has any.accept
in interface org.macroing.cit.java.util.node.Node
nodeHierarchicalVisitor
- the NodeHierarchicalVisitor
to acceptnodeHierarchicalVisitor.visitLeave(this)
org.macroing.cit.java.util.node.NodeTraversalException
- thrown if, and only if, a RuntimeException
is thrown by the current NodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, nodeHierarchicalVisitor
is null
public boolean equals(java.lang.Object object)
true
if, and only if, object
is an instance of CompilationUnit
, and that CompilationUnit
instance is equal to this CompilationUnit
instance, false
otherwise.equals
in class java.lang.Object
object
- an Object
to compare to this CompilationUnit
instance for equalitytrue
if, and only if, object
is an instance of CompilationUnit
, and that CompilationUnit
instance is equal to this CompilationUnit
instance, false
otherwisepublic int hashCode()
CompilationUnit
instance.hashCode
in class java.lang.Object
CompilationUnit
instancepublic java.util.List<ImportDeclaration> getImportDeclarations()
List
with all currently added ImportDeclaration
s.
Any modifications made to the returned List
will not affect this CompilationUnit
instance.
However, modifications made to any of the returned List
s elements, will indirectly affect this CompilationUnit
instance.
List
with all currently added ImportDeclaration
spublic java.util.List<TypeDeclaration> getTypeDeclarations()
List
with all currently added TypeDeclaration
s.
Any modifications made to the returned List
will not affect this CompilationUnit
instance.
However, modifications made to any of the returned List
s elements, will indirectly affect this CompilationUnit
instance.
List
with all currently added TypeDeclaration
spublic java.lang.String toString()
String
representation of this CompilationUnit
instance.toString
in class java.lang.Object
String
representation of this CompilationUnit
instancepublic void addComment(Comment comment)
Comment
to the end of this CompilationUnit
instance.
If comment
is null
, a NullPointerException
will be thrown.
comment
- the Comment
to addjava.lang.NullPointerException
- thrown if, and only if, comment
is null
public void addImportDeclaration(ImportDeclaration importDeclaration)
ImportDeclaration
to the end of the ImportDeclaration
s section of this CompilationUnit
instance.
If importDeclaration
is null
, a NullPointerException
will be thrown.
importDeclaration
- the ImportDeclaration
to addjava.lang.NullPointerException
- thrown if, and only if, importDeclaration
is null
public void addTypeDeclaration(TypeDeclaration typeDeclaration)
TypeDeclaration
to the end of the TypeDeclaration
s section of this CompilationUnit
instance.
If typeDeclaration
is null
, a NullPointerException
will be thrown.
typeDeclaration
- the TypeDeclaration
to addjava.lang.NullPointerException
- thrown if, and only if, typeDeclaration
is null
public void addWhiteSpace(WhiteSpace whiteSpace)
WhiteSpace
to the end of this CompilationUnit
instance.
If whiteSpace
is null
, a NullPointerException
will be thrown.
whiteSpace
- the WhiteSpace
to addjava.lang.NullPointerException
- thrown if, and only if, whiteSpace
is null
public void removeComment(Comment comment)
Comment
from the end of this CompilationUnit
instance, that is equal to comment
.
If comment
is null
, a NullPointerException
will be thrown.
comment
- the Comment
to removejava.lang.NullPointerException
- thrown if, and only if, comment
is null
public void removeImportDeclaration(ImportDeclaration importDeclaration)
ImportDeclaration
from the end of the ImportDeclaration
s section of this CompilationUnit
instance, that is equal to importDeclaration
.
If importDeclaration
is null
, a NullPointerException
will be thrown.
importDeclaration
- the ImportDeclaration
to removejava.lang.NullPointerException
- thrown if, and only if, importDeclaration
is null
public void removeTypeDeclaration(TypeDeclaration typeDeclaration)
TypeDeclaration
from the end of the TypeDeclaration
s section of this CompilationUnit
instance, that is equal to typeDeclaration
.
If typeDeclaration
is null
, a NullPointerException
will be thrown.
typeDeclaration
- the TypeDeclaration
to removejava.lang.NullPointerException
- thrown if, and only if, typeDeclaration
is null
public void removeWhiteSpace(WhiteSpace whiteSpace)
WhiteSpace
from the end of this CompilationUnit
instance, that is equal to whiteSpace
.
If whiteSpace
is null
, a NullPointerException
will be thrown.
whiteSpace
- the WhiteSpace
to removejava.lang.NullPointerException
- thrown if, and only if, whiteSpace
is null
public static CompilationUnit newInstance()
CompilationUnit
instance.CompilationUnit
instance