Package org.fife.rsta.ac.java.rjc.ast
Class CompilationUnit
- java.lang.Object
-
- org.fife.rsta.ac.java.rjc.ast.AbstractASTNode
-
- org.fife.rsta.ac.java.rjc.ast.CompilationUnit
-
- All Implemented Interfaces:
ASTNode,TypeDeclarationContainer
public class CompilationUnit extends AbstractASTNode implements TypeDeclarationContainer
ACompilationUnitis the root node of an AST for a Java source file.CompilationUnit: [[Annotations] 'package' QualifiedIdentifier ';' ] {ImportDeclaration} {TypeDeclaration}- Version:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCompilationUnit.ZeroOffsetAn offset that always returns 0.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Annotation>annotationsprivate java.util.List<ImportDeclaration>importsprivate java.util.List<ParserNotice>noticesprivate Packagepkgprivate java.util.List<TypeDeclaration>typeDeclarationsprivate static OffsetZERO_OFFSET
-
Constructor Summary
Constructors Constructor Description CompilationUnit(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddImportDeclaration(ImportDeclaration dec)Adds an import declaration to this compilation unit.voidaddParserNotice(Token t, java.lang.String msg)Shorthand for "addParserNotice(new ParserNotice(t, msg))".voidaddParserNotice(ParserNotice notice)Adds a parser notice to this compilation unit.voidaddTypeDeclaration(TypeDeclaration typeDec)Adds a type declaration to this container.intgetAnnotationCount()java.util.Iterator<Annotation>getAnnotationIterator()TypeDeclarationgetDeepestTypeDeclarationAtOffset(int offs)Returns the deepest-nested type declaration that contains a given offset.java.awt.PointgetEnclosingMethodRange(int offs)TODO: Return range for more instances than just class methods.intgetImportCount()java.util.Iterator<ImportDeclaration>getImportIterator()java.util.List<ImportDeclaration>getImports()Returns the import declarations of this compilation unit.PackagegetPackage()Returns the package of this compilation unit.java.lang.StringgetPackageName()Returns the fully-qualified package name of this compilation unit.ParserNoticegetParserNotice(int index)Returns the specified parser notice.intgetParserNoticeCount()TypeDeclarationgetTypeDeclaration(int index)Returns the specified type declaration.TypeDeclarationgetTypeDeclarationAtOffset(int offs)Returns the type declaration in this file that contains the specified offset.intgetTypeDeclarationCount()java.util.Iterator<TypeDeclaration>getTypeDeclarationIterator()voidsetPackage(Package pkg)-
Methods inherited from class org.fife.rsta.ac.java.rjc.ast.AbstractASTNode
getName, getNameEndOffset, getNameStartOffset, setDeclarationEndOffset, setDeclarationOffsets, toString
-
-
-
-
Field Detail
-
annotations
private java.util.List<Annotation> annotations
-
pkg
private Package pkg
-
imports
private java.util.List<ImportDeclaration> imports
-
typeDeclarations
private java.util.List<TypeDeclaration> typeDeclarations
-
notices
private java.util.List<ParserNotice> notices
-
ZERO_OFFSET
private static final Offset ZERO_OFFSET
-
-
Method Detail
-
addImportDeclaration
public void addImportDeclaration(ImportDeclaration dec)
Adds an import declaration to this compilation unit.- Parameters:
dec- The import declaration.- See Also:
getImports()
-
addParserNotice
public void addParserNotice(Token t, java.lang.String msg)
Shorthand for "addParserNotice(new ParserNotice(t, msg))".- Parameters:
t- The token to add a parser notice for.msg- The message of the parser notice.- See Also:
addParserNotice(ParserNotice)
-
addParserNotice
public void addParserNotice(ParserNotice notice)
Adds a parser notice to this compilation unit.- Parameters:
notice- The notice to add.- See Also:
addParserNotice(Token, String)
-
addTypeDeclaration
public void addTypeDeclaration(TypeDeclaration typeDec)
Description copied from interface:TypeDeclarationContainerAdds a type declaration to this container.- Specified by:
addTypeDeclarationin interfaceTypeDeclarationContainer- Parameters:
typeDec- The new type declaration.
-
getAnnotationCount
public int getAnnotationCount()
-
getAnnotationIterator
public java.util.Iterator<Annotation> getAnnotationIterator()
-
getDeepestTypeDeclarationAtOffset
public TypeDeclaration getDeepestTypeDeclarationAtOffset(int offs)
Returns the deepest-nested type declaration that contains a given offset.- Parameters:
offs- The offset.- Returns:
- The deepest-nested type declaration containing the offset, or
nullif the offset is outside any type declaration (such as in the import statements, etc.). - See Also:
getTypeDeclarationAtOffset(int)
-
getEnclosingMethodRange
public java.awt.Point getEnclosingMethodRange(int offs)
TODO: Return range for more instances than just class methods. Also handle child TypeDeclarations.- Parameters:
offs- The offset to check.- Returns:
- The starting and ending offset of the enclosing method range.
-
getImportCount
public int getImportCount()
-
getImports
public java.util.List<ImportDeclaration> getImports()
Returns the import declarations of this compilation unit. This is a copy of the list of imports, but the actual individualImportDeclarations are not copies, so modifying them will modify this compilation unit!- Returns:
- A list or imports, or an empty list if there are none.
-
getImportIterator
public java.util.Iterator<ImportDeclaration> getImportIterator()
-
getPackage
public Package getPackage()
Returns the package of this compilation unit.- Returns:
- The package of this compilation unit, or
nullif this compilation unit is not in a package. - See Also:
getPackageName()
-
getPackageName
public java.lang.String getPackageName()
Returns the fully-qualified package name of this compilation unit.- Returns:
- The package name, or
nullif this compilation unit is not in a package (in the default package). - See Also:
getPackage()
-
getParserNotice
public ParserNotice getParserNotice(int index)
Returns the specified parser notice.- Parameters:
index- The index of the parser notice.- Returns:
- The parser notice.
- See Also:
getParserNoticeCount()
-
getParserNoticeCount
public int getParserNoticeCount()
-
getTypeDeclaration
public TypeDeclaration getTypeDeclaration(int index)
Returns the specified type declaration.- Parameters:
index- The index of the type declaration.- Returns:
- The type declaration.
- See Also:
getTypeDeclarationCount()
-
getTypeDeclarationAtOffset
public TypeDeclaration getTypeDeclarationAtOffset(int offs)
Returns the type declaration in this file that contains the specified offset.- Parameters:
offs- The offset.- Returns:
- The type declaration, or
nullif the offset is outside any type declaration. - See Also:
getDeepestTypeDeclarationAtOffset(int)
-
getTypeDeclarationCount
public int getTypeDeclarationCount()
-
getTypeDeclarationIterator
public java.util.Iterator<TypeDeclaration> getTypeDeclarationIterator()
-
setPackage
public void setPackage(Package pkg)
-
-