public class CompilationUnit extends java.lang.Object implements TypeDeclarationContainer
CompilationUnit is the root node of an AST for a Java
source file.
CompilationUnit:
[[Annotations] 'package' QualifiedIdentifier ';' ] {ImportDeclaration} {TypeDeclaration}
| Constructor and Description |
|---|
CompilationUnit(java.lang.String name) |
| Modifier and Type | Method and Description |
|---|---|
void |
addImportDeclaration(ImportDeclaration dec)
Adds an import declaration to this compilation unit.
|
void |
addParserNotice(ParserNotice notice)
Adds a parser notice to this compilation unit.
|
void |
addParserNotice(Token t,
java.lang.String msg)
Shorthand for "addParserNotice(new ParserNotice(t, msg))".
|
void |
addTypeDeclaration(TypeDeclaration typeDec)
Adds a type declaration to this container.
|
int |
getAnnotationCount() |
java.util.Iterator<Annotation> |
getAnnotationIterator() |
TypeDeclaration |
getDeepestTypeDeclarationAtOffset(int offs)
Returns the deepest-nested type declaration that contains a given
offset.
|
java.awt.Point |
getEnclosingMethodRange(int offs)
TODO: Return range for more instances than just class methods.
|
int |
getImportCount() |
java.util.Iterator<ImportDeclaration> |
getImportIterator() |
java.util.List<ImportDeclaration> |
getImports()
Returns the import declarations of this compilation unit.
|
java.lang.String |
getName()
Returns the "name" of this node.
|
int |
getNameEndOffset()
Returns the end offset of the "name" of this node.
|
int |
getNameStartOffset()
Returns the start offset of the "name" of this node.
|
Package |
getPackage()
Returns the package of this compilation unit.
|
java.lang.String |
getPackageName()
Returns the fully-qualified package name of this compilation unit.
|
ParserNotice |
getParserNotice(int index)
Returns the specified parser notice.
|
int |
getParserNoticeCount() |
TypeDeclaration |
getTypeDeclaration(int index)
Returns the specified type declaration.
|
TypeDeclaration |
getTypeDeclarationAtOffset(int offs)
Returns the type declaration in this file that contains the specified
offset.
|
int |
getTypeDeclarationCount() |
java.util.Iterator<TypeDeclaration> |
getTypeDeclarationIterator() |
void |
setDeclarationEndOffset(Offset end) |
protected void |
setDeclarationOffsets(Offset start,
Offset end)
Sets the start and end offsets of this node.
|
void |
setPackage(Package pkg) |
java.lang.String |
toString()
Returns the name of this node (e.g.
|
public void addImportDeclaration(ImportDeclaration dec)
dec - The import declaration.getImports()public void addParserNotice(Token t, java.lang.String msg)
t - The token to add a parser notice for.msg - The message of the parser notice.addParserNotice(ParserNotice)public void addParserNotice(ParserNotice notice)
notice - The notice to add.addParserNotice(Token, String)public void addTypeDeclaration(TypeDeclaration typeDec)
TypeDeclarationContaineraddTypeDeclaration in interface TypeDeclarationContainertypeDec - The new type declaration.public int getAnnotationCount()
public java.util.Iterator<Annotation> getAnnotationIterator()
public TypeDeclaration getDeepestTypeDeclarationAtOffset(int offs)
offs - The offset.null if the offset is outside any type
declaration (such as in the import statements, etc.).getTypeDeclarationAtOffset(int)public java.awt.Point getEnclosingMethodRange(int offs)
offs - The offset to check.public int getImportCount()
public java.util.List<ImportDeclaration> getImports()
ImportDeclarations are not copies, so modifying them will modify
this compilation unit!public java.util.Iterator<ImportDeclaration> getImportIterator()
public Package getPackage()
null if
this compilation unit is not in a package.getPackageName()public java.lang.String getPackageName()
null if this compilation unit
is not in a package (in the default package).getPackage()public ParserNotice getParserNotice(int index)
index - The index of the parser notice.getParserNoticeCount()public int getParserNoticeCount()
public TypeDeclaration getTypeDeclaration(int index)
index - The index of the type declaration.getTypeDeclarationCount()public TypeDeclaration getTypeDeclarationAtOffset(int offs)
offs - The offset.null if the offset is
outside any type declaration.getDeepestTypeDeclarationAtOffset(int)public int getTypeDeclarationCount()
public java.util.Iterator<TypeDeclaration> getTypeDeclarationIterator()
public void setPackage(Package pkg)
public java.lang.String getName()
CodeBlocks
it will be CodeBlock.NAME.Note that this may not be unique. For example, a class with an overloaded method will have multiple methods with the same "name," just with different signatures.
public int getNameEndOffset()
getNameEndOffset in interface ASTNodepublic int getNameStartOffset()
getNameStartOffset in interface ASTNodepublic void setDeclarationEndOffset(Offset end)
protected void setDeclarationOffsets(Offset start, Offset end)
start - The start offset.end - The end offset.public java.lang.String toString()
getName()).
Subclasses can override this method if appropriate.toString in class java.lang.Object