openjava.ptree
Class Leaf

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.Leaf
All Implemented Interfaces:
Cloneable, ParseTree
Direct Known Subclasses:
Literal, SelfAccess, Variable

public class Leaf
extends ParseTreeObject
implements ParseTree

The Leaf class is a token-node in the parse tree of OpenJava. Any object of this class or subclasses must be immutable.

See Also:
ParseTree, NonLeaf

Field Summary
 int charBegin
          charBegin is the number of the character at which this token is.
 int line
          line is the number of the line at which this token is.
private  String textString
          textString is the text of this token.
private  int tokenID
          tokenID is the identifer number of this token
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
Leaf(int term_num, String str)
          Allocates a new leaf(token) with its text.
Leaf(int term_num, String str, int line, int charBegin)
          Allocates a new leaf(token) with its text and where this is.
Leaf(String str)
          Allocates a new leaf(token) with its text.
 
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.
 void childrenAccept(ParseTreeVisitor visitor)
          Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.
 boolean equals(ParseTree p)
          Tests if the specified ptree-node equals to this leaf-node.
 boolean equals(String str)
          Tests if the specified string equals to this leaf-node's text.
 OJClass getRowType(Environment env)
           
 int getTokenID()
          Returns the identifer-number of this token.
 ParseTree makeCopy()
          Makes a new copy of this leaf-node.
 ParseTree makeRecursiveCopy()
          Makes a new copy of this leaf-node.
protected  void replaceChildWith(ParseTree dist, ParseTree replacement)
           
 String toString()
          Overrides to return its text as the string of this instance.
 void writeCode()
          Writes the code of this token.
 
Methods inherited from class openjava.ptree.ParseTreeObject
clone, eq, eq, equal, flushPrintWriter, getDebugFlag, getNest, getObjectID, getParent, getPrintWriter, getTab, hashCode, lastObjectID, popNest, popPrintWriter, pushNest, pushPrintWriter, replace, setDebugFlag, setDebugLevel, setNest, setParent, setPrintStream, setTab, toFlattenString, 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, replace, toFlattenString
 

Field Detail

textString

private String textString
textString is the text of this token.


tokenID

private int tokenID
tokenID is the identifer number of this token


line

public int line
line is the number of the line at which this token is.


charBegin

public int charBegin
charBegin is the number of the character at which this token is.

Constructor Detail

Leaf

public Leaf(String str)
Allocates a new leaf(token) with its text.

Parameters:
str - its text.

Leaf

public Leaf(int term_num,
            String str)
Allocates a new leaf(token) with its text.

Parameters:
term_num - dummy parameter.
str - its text.

Leaf

public Leaf(int term_num,
            String str,
            int line,
            int charBegin)
Allocates a new leaf(token) with its text and where this is.

Parameters:
term_num - dummy parameter.
str - its text.
Method Detail

replaceChildWith

protected void replaceChildWith(ParseTree dist,
                                ParseTree replacement)
                         throws ParseTreeException
Specified by:
replaceChildWith in class ParseTreeObject
ParseTreeException

toString

public String toString()
Overrides to return its text as the string of this instance.

Specified by:
toString in interface ParseTree
Overrides:
toString in class ParseTreeObject
Returns:
the text of this token.

makeRecursiveCopy

public ParseTree makeRecursiveCopy()
Makes a new copy of this leaf-node. This method equals to makeCopy().

Specified by:
makeRecursiveCopy in interface ParseTree
Specified by:
makeRecursiveCopy in class ParseTreeObject
Returns:
the copy of this nonleaf-node as a ptree-node.

makeCopy

public ParseTree makeCopy()
Makes a new copy of this leaf-node.

Specified by:
makeCopy in interface ParseTree
Overrides:
makeCopy in class ParseTreeObject
Returns:
the copy of this nonleaf-node as a ptree-node.

equals

public boolean equals(ParseTree p)
Tests if the specified ptree-node equals to this leaf-node.

Specified by:
equals in interface ParseTree
Specified by:
equals in class ParseTreeObject
Parameters:
p - the ptree-node to be tested.
Returns:
true if p equals to this leaf-node

equals

public boolean equals(String str)
Tests if the specified string equals to this leaf-node's text.

Returns:
true if p equals to this leaf-node

getTokenID

public int getTokenID()
Returns the identifer-number of this token.

Returns:
the identifer-number of this token.

writeCode

public void writeCode()
Writes the code of this token.

Specified by:
writeCode in interface ParseTree
Specified by:
writeCode in class ParseTreeObject
Returns:
always true.

childrenAccept

public void childrenAccept(ParseTreeVisitor visitor)
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 each child ParseTree object with this visitor.

Specified by:
childrenAccept in interface ParseTree
Specified by:
childrenAccept in class ParseTreeObject
Parameters:
visitor - a visitor

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

getRowType

public OJClass getRowType(Environment env)
                   throws Exception
Exception

SourceForge.net_Logo