openjava.ptree
Class CompilationUnit

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.NonLeaf
              |
              +--openjava.ptree.CompilationUnit
All Implemented Interfaces:
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

Field Summary
 
Fields inherited from class openjava.ptree.NonLeaf
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
CompilationUnit(String e0, 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.
 ClassDeclarationList getClassDeclarations()
          Obtains the type declaration list of this compilation unit
 String[] getDeclaredImports()
          Obtains the import statement list of this compilation unit
 String getPackage()
          Obtains the package of this compilation unit
 ClassDeclaration getPublicClass()
          Obtains the public class in this compilation unit.
static boolean isOnDemandImport(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(String[] islst)
          Sets the import statement list of this compilation unit
 void setPackage(String qn)
          Sets the package of this compilation unit
static String trimOnDemand(String import_decl)
          Removes ".*" at tail if it exists.
 void writeCode()
          Overrides the writing code method
 
Methods inherited from class openjava.ptree.NonLeaf
childrenAccept, childrenAreEqual, elementAt, equals, getComment, getContents, getLength, getRowType, 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(String e0,
                       String[] e1,
                       ClassDeclarationList e2)
Allocates this object with specified parse-tree elements.

Method Detail

writeCode

public void writeCode()
Overrides the writing code method

Specified by:
writeCode in interface ParseTree
Overrides:
writeCode in class NonLeaf

setPackage

public void setPackage(String qn)
Sets the package of this compilation unit

Parameters:
qn - the qualified name indicating this package

getPackage

public String getPackage()
Obtains the package of this compilation unit

Returns:
the qualified name indicating this package

setDeclaredImports

public void setDeclaredImports(String[] islst)
Sets the import statement list of this compilation unit

Parameters:
islst - the import statement list of this compilation unit

getDeclaredImports

public 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(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 String trimOnDemand(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.

Specified by:
accept in interface ParseTree
Specified by:
accept in class ParseTreeObject
Parameters:
v - a visitor
ParseTreeException

SourceForge.net_Logo