openjava.ptree
Class CompilationUnit

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.NonLeaf
              |
              +--openjava.ptree.CompilationUnit
All Implemented Interfaces:
java.lang.Cloneable, ParseTree

public class CompilationUnit
extends NonLeaf

The CompilationUnit class presents for the whole parse tree in a file. CompilationUnits consists of (package statement) (import statement list) (type declaration list) QualifiedName ImportStatementList ClassDeclarationList

See Also:
ClassDeclarationList

Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
CompilationUnit(java.lang.String e0, java.lang.String[] e1, ClassDeclarationList e2)
          Allocates this object with specified parse-tree elements.
 
Method Summary
 void accept(ParseTreeVisitor v)
          Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern. This invoke an appropriate visit() method on the accepted visitor.
 ClassDeclarationList getClassDeclarations()
          Obtains the type declaration list of this compilation unit
 java.lang.String[] getDeclaredImports()
          Obtains the import statement list of this compilation unit
 java.lang.String getPackage()
          Obtains the package of this compilation unit
 ClassDeclaration getPublicClass()
          Obtains the public class in this compilation unit.
static boolean isOnDemandImport(java.lang.String import_decl)
          Tests if the declared import string represents on demand importation.
 void setClassDeclarations(ClassDeclarationList tdlst)
          Sets the type declaration list of this compilation unit
 void setDeclaredImports(java.lang.String[] islst)
          Sets the import statement list of this compilation unit
 void setPackage(java.lang.String qn)
          Sets the package of this compilation unit
static java.lang.String trimOnDemand(java.lang.String import_decl)
          Removes ".*" at tail if it exists.
 void writeCode()
          Overrides the writing code method
 
Methods inherited from class openjava.ptree.NonLeaf
childrenAccept, elementAt, equals, getComment, getContents, getLength, makeRecursiveCopy, replaceChildWith, set, set, set, set, set, set, set, set, set, setComment, setElementAt
 
Methods inherited from class openjava.ptree.ParseTreeObject
clone, eq, eq, equal, flushPrintWriter, getDebugFlag, getNest, getObjectID, getParent, getPrintWriter, getTab, hashCode, lastObjectID, makeCopy, popNest, popPrintWriter, pushNest, pushPrintWriter, replace, setDebugFlag, setDebugLevel, setNest, setParent, setPrintStream, setTab, toFlattenString, toString, writeDebug, writeDebugL, writeDebugLln, writeDebugln, writeDebugLR, writeDebugR, writeDebugRln, writeTab
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface openjava.ptree.ParseTree
eq, getObjectID, makeCopy, replace, toFlattenString, toString
 

Constructor Detail

CompilationUnit

public CompilationUnit(java.lang.String e0,
                       java.lang.String[] e1,
                       ClassDeclarationList e2)
Allocates this object with specified parse-tree elements.
Method Detail

writeCode

public void writeCode()
Overrides the writing code method
Overrides:
writeCode in class NonLeaf

setPackage

public void setPackage(java.lang.String qn)
Sets the package of this compilation unit
Parameters:
qn - the qualified name indicating this package

getPackage

public java.lang.String getPackage()
Obtains the package of this compilation unit
Returns:
the qualified name indicating this package

setDeclaredImports

public void setDeclaredImports(java.lang.String[] islst)
Sets the import statement list of this compilation unit
Parameters:
islst - the import statement list of this compilation unit

getDeclaredImports

public java.lang.String[] getDeclaredImports()
Obtains the import statement list of this compilation unit
Returns:
the import statement list of this compilation unit

setClassDeclarations

public void setClassDeclarations(ClassDeclarationList tdlst)
Sets the type declaration list of this compilation unit
Parameters:
tdlst - the type declaration list of this compilation unit

getClassDeclarations

public ClassDeclarationList getClassDeclarations()
Obtains the type declaration list of this compilation unit
Returns:
the type declaration list of this compilation unit

getPublicClass

public ClassDeclaration getPublicClass()
                                throws ParseTreeException
Obtains the public class in this compilation unit.
Returns:
the public class
Throws:
ParseTreeException - if not one public class is declared.

isOnDemandImport

public static boolean isOnDemandImport(java.lang.String import_decl)
Tests if the declared import string represents on demand importation. For example, if the specified string is java.lang.*, this returns true, and if java.lang.Object, returns false;
Parameters:
import_decl - declared importation.
Returns:
true if the string ends with ".*".

trimOnDemand

public static java.lang.String trimOnDemand(java.lang.String import_decl)
Removes ".*" at tail if it exists.
Parameters:
import_decl - declared importation.
Returns:
a string trimmed ".*" off

accept

public void accept(ParseTreeVisitor v)
            throws ParseTreeException
Description copied from interface: ParseTree
Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.

This invoke an appropriate visit() method on the accepted visitor.

Overrides:
accept in class ParseTreeObject
Following copied from interface: openjava.ptree.ParseTree
Parameters:
visitor - a visitor