org.fife.rsta.ac.java.rjc.ast
Class CompilationUnit

java.lang.Object
  extended by org.fife.rsta.ac.java.rjc.ast.CompilationUnit
All Implemented Interfaces:
ASTNode, TypeDeclarationContainer

public class CompilationUnit
extends Object
implements TypeDeclarationContainer

A CompilationUnit is the root node of an AST for a Java source file.

 CompilationUnit:
    [[Annotations] 'package' QualifiedIdentifier ';' ] {ImportDeclaration} {TypeDeclaration}
 

Version:
1.0
Author:
Robert Futrell

Constructor Summary
CompilationUnit(String name)
           
 
Method Summary
 void addImportDeclaration(ImportDeclaration dec)
           
 void addParserNotice(ParserNotice notice)
           
 void addParserNotice(Token t, String msg)
          Shorthand for "addParserNotice(new ParserNotice(t, msg))".
 void addTypeDeclaration(TypeDeclaration typeDec)
           
 int getAnnotationCount()
           
 Iterator getAnnotationIterator()
           
 TypeDeclaration getDeepestTypeDeclarationAtOffset(int offs)
          Returns the deepest-nested type declaration that contains a given offset.
 Point getEnclosingMethodRange(int offs)
          TODO: Return range for more instances than just class methods.
 int getImportCount()
           
 Iterator getImportIterator()
           
 List getImports()
          Returns the import declarations of this compilation unit.
 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.
 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()
           
 Iterator 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)
           
 String toString()
          Returns the name of this node (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompilationUnit

public CompilationUnit(String name)
Method Detail

addImportDeclaration

public void addImportDeclaration(ImportDeclaration dec)

addParserNotice

public void addParserNotice(Token t,
                            String msg)
Shorthand for "addParserNotice(new ParserNotice(t, msg))".

Parameters:
t -
msg -

addParserNotice

public void addParserNotice(ParserNotice notice)

addTypeDeclaration

public void addTypeDeclaration(TypeDeclaration typeDec)
Specified by:
addTypeDeclaration in interface TypeDeclarationContainer

getAnnotationCount

public int getAnnotationCount()

getAnnotationIterator

public Iterator 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 null if the offset is outside of any type declaration (such as in the import statements, etc.).
See Also:
getTypeDeclarationAtOffset(int)

getEnclosingMethodRange

public Point getEnclosingMethodRange(int offs)
TODO: Return range for more instances than just class methods. Also handle child TypeDeclarations.

Parameters:
offs -
Returns:

getImportCount

public int getImportCount()

getImports

public List getImports()
Returns the import declarations of this compilation unit. This is a copy of the list of imports, but the actual individual ImportDeclarations 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 Iterator getImportIterator()

getPackage

public Package getPackage()
Returns the package of this compilation unit.

Returns:
The package of this compilation unit, or null if this compilation unit is not in a package.
See Also:
getPackageName()

getPackageName

public String getPackageName()
Returns the fully-qualified package name of this compilation unit.

Returns:
The package name, or null if this compilation unit is not in a package (in the default package).
See Also:
getPackage()

getParserNotice

public ParserNotice getParserNotice(int index)

getParserNoticeCount

public int getParserNoticeCount()

getTypeDeclaration

public TypeDeclaration getTypeDeclaration(int index)

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 null if the offset is outside of any type declaration.
See Also:
getDeepestTypeDeclarationAtOffset(int)

getTypeDeclarationCount

public int getTypeDeclarationCount()

getTypeDeclarationIterator

public Iterator getTypeDeclarationIterator()

setPackage

public void setPackage(Package pkg)

getName

public String getName()
Returns the "name" of this node. This will be the name of the method, the name of the member or local variable, etc. For 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.

Specified by:
getName in interface ASTNode
Returns:
The "name" of this node.

getNameEndOffset

public int getNameEndOffset()
Returns the end offset of the "name" of this node.

Specified by:
getNameEndOffset in interface ASTNode
Returns:
The end offset.

getNameStartOffset

public int getNameStartOffset()
Returns the start offset of the "name" of this node.

Specified by:
getNameStartOffset in interface ASTNode
Returns:
The start offset.

setDeclarationEndOffset

public void setDeclarationEndOffset(Offset end)

setDeclarationOffsets

protected void setDeclarationOffsets(Offset start,
                                     Offset end)
Sets the start and end offsets of this node.

Parameters:
start - The start offset.
end - The end offset.

toString

public String toString()
Returns the name of this node (e.g. the value of getName()). Subclasses can override this method if appropriate.

Overrides:
toString in class Object
Returns:
A string representation of this node.


Copyright © 2003-2011. All Rights Reserved.