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) |
void |
addParserNotice(ParserNotice notice) |
void |
addParserNotice(Token t,
java.lang.String msg)
Shorthand for "addParserNotice(new ParserNotice(t, msg))".
|
void |
addTypeDeclaration(TypeDeclaration typeDec) |
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) |
int |
getParserNoticeCount() |
TypeDeclaration |
getTypeDeclaration(int index) |
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)
public void addParserNotice(Token t, java.lang.String msg)
t - msg - public void addParserNotice(ParserNotice notice)
public void addTypeDeclaration(TypeDeclaration typeDec)
addTypeDeclaration in interface TypeDeclarationContainerpublic int getAnnotationCount()
public java.util.Iterator<Annotation> getAnnotationIterator()
public TypeDeclaration getDeepestTypeDeclarationAtOffset(int offs)
offs - The offset.null if the offset is outside of any type
declaration (such as in the import statements, etc.).getTypeDeclarationAtOffset(int)public java.awt.Point getEnclosingMethodRange(int offs)
offs - 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)
public int getParserNoticeCount()
public TypeDeclaration getTypeDeclaration(int index)
public TypeDeclaration getTypeDeclarationAtOffset(int offs)
offs - The offset.null if the offset is
outside of 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