public final class CompilationUnit extends Node
This class represents the entire compilation unit. Each java file denotes a compilation unit.
The CompilationUnit is constructed following the syntax:CompilationUnit ::= (
PackageDeclaration
)? (
ImportDeclaration
)* (
TypeDeclaration
)*
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE
Constructor and Description |
---|
CompilationUnit() |
CompilationUnit(int beginLine,
int beginColumn,
int endLine,
int endColumn,
PackageDeclaration pakage,
List<ImportDeclaration> imports,
List<TypeDeclaration> types)
Deprecated.
prefer using Range objects.
|
CompilationUnit(PackageDeclaration pakage,
List<ImportDeclaration> imports,
List<TypeDeclaration> types) |
CompilationUnit(Range range,
PackageDeclaration pakage,
List<ImportDeclaration> imports,
List<TypeDeclaration> types) |
Modifier and Type | Method and Description |
---|---|
<R,A> R |
accept(GenericVisitor<R,A> v,
A arg)
Accept method for visitor support.
|
<A> void |
accept(VoidVisitor<A> v,
A arg)
Accept method for visitor support.
|
List<Comment> |
getComments()
Return a list containing all comments declared in this compilation unit.
|
List<ImportDeclaration> |
getImports()
Retrieves the list of imports declared in this compilation unit or
null if there is no import. |
PackageDeclaration |
getPackage()
Retrieves the package declaration of this compilation unit.
If this compilation unit has no package declaration (default package), null is returned. |
List<TypeDeclaration> |
getTypes()
Return the list of types declared in this compilation unit.
If there is no types declared, null is returned. |
void |
setComments(List<Comment> comments)
Sets the list of comments of this compilation unit.
|
void |
setImports(List<ImportDeclaration> imports)
Sets the list of imports of this compilation unit.
|
void |
setPackage(PackageDeclaration pakage)
Sets or clear the package declarations of this compilation unit.
|
void |
setTypes(List<TypeDeclaration> types)
Sets the list of types declared in this compilation unit.
|
addOrphanComment, clone, contains, equals, getAllContainedComments, getBegin, getBeginColumn, getBeginLine, getChildrenNodes, getComment, getData, getEnd, getEndColumn, getEndLine, getOrphanComments, getParentNode, getRange, hasComment, hashCode, isPositionedAfter, isPositionedAfter, isPositionedBefore, isPositionedBefore, setAsParentNodeOf, setAsParentNodeOf, setBegin, setBeginColumn, setBeginLine, setComment, setData, setEnd, setEndColumn, setEndLine, setParentNode, setRange, toString, toStringWithoutComments
public CompilationUnit()
public CompilationUnit(PackageDeclaration pakage, List<ImportDeclaration> imports, List<TypeDeclaration> types)
@Deprecated public CompilationUnit(int beginLine, int beginColumn, int endLine, int endColumn, PackageDeclaration pakage, List<ImportDeclaration> imports, List<TypeDeclaration> types)
public CompilationUnit(Range range, PackageDeclaration pakage, List<ImportDeclaration> imports, List<TypeDeclaration> types)
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Node
public <A> void accept(VoidVisitor<A> v, A arg)
Node
public List<Comment> getComments()
null
is returned.null
JavadocComment
,
LineComment
,
BlockComment
public List<ImportDeclaration> getImports()
null
if there is no import.null
if there is no importpublic PackageDeclaration getPackage()
null
is returned.null
public List<TypeDeclaration> getTypes()
null
is returned.null
null if there is no typeAnnotationDeclaration
,
ClassOrInterfaceDeclaration
,
EmptyTypeDeclaration
,
EnumDeclaration
public void setComments(List<Comment> comments)
comments
- the list of commentspublic void setImports(List<ImportDeclaration> imports)
null
.imports
- the list of importspublic void setPackage(PackageDeclaration pakage)
pakage
- the pakage declaration to set or null
to default
packagepublic void setTypes(List<TypeDeclaration> types)
types
- the lis of typesCopyright © 2007–2016. All rights reserved.