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
A CompilationUnit is the root node of an AST for a Java source file.
 CompilationUnit:
    [[Annotations] 'package' QualifiedIdentifier ';' ] {ImportDeclaration} {TypeDeclaration}
 
Version:
1.0
  • Field Details

  • Constructor Details

    • CompilationUnit

      public CompilationUnit(String name)
  • Method Details

    • addImportDeclaration

      public void addImportDeclaration(ImportDeclaration dec)
      Adds an import declaration to this compilation unit.
      Parameters:
      dec - The import declaration.
      See Also:
    • addParserNotice

      public void addParserNotice(Token t, 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

      public void addParserNotice(ParserNotice notice)
      Adds a parser notice to this compilation unit.
      Parameters:
      notice - The notice to add.
      See Also:
    • addTypeDeclaration

      public void addTypeDeclaration(TypeDeclaration typeDec)
      Description copied from interface: TypeDeclarationContainer
      Adds a type declaration to this container.
      Specified by:
      addTypeDeclaration in interface TypeDeclarationContainer
      Parameters:
      typeDec - The new type declaration.
    • getAnnotationCount

      public int getAnnotationCount()
    • getAnnotationIterator

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

      public 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 List<ImportDeclaration> 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<ImportDeclaration> 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

      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:
    • 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

      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:
    • 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 any type declaration.
      See Also:
    • getTypeDeclarationCount

      public int getTypeDeclarationCount()
    • getTypeDeclarationIterator

      public Iterator<TypeDeclaration> getTypeDeclarationIterator()
    • setPackage

      public void setPackage(Package pkg)