openjava.ptree
Class Literal

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.Leaf
              |
              +--openjava.ptree.Literal
All Implemented Interfaces:
java.lang.Cloneable, Expression, ParseTree, VariableInitializer

public class Literal
extends Leaf
implements Expression

The Literal class represents a literal.

See Also:
Leaf, Expression

Field Summary
static int BOOLEAN
           
static int CHARACTER
           
static int DOUBLE
           
static int FLOAT
           
protected  int id
           
static int INTEGER
           
static int LONG
           
static int NULL
           
static int STRING
           
 
Fields inherited from class openjava.ptree.Leaf
charBegin, line
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
Literal(int id, java.lang.String str)
          Allocates a new object.
 
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.
static Literal constantEmptyString()
           
static Literal constantFalse()
           
static Literal constantNull()
           
static Literal constantOne()
           
static Literal constantTrue()
           
static Literal constantZero()
           
 int getLiteralType()
           
 OJClass getType(Environment env)
           
static Literal makeLiteral(boolean b)
          Makes a new object of Literal class from the boolean.
static Literal makeLiteral(java.lang.Boolean b)
           
static Literal makeLiteral(char c)
          Makes a new object of Literal class from the character.
static Literal makeLiteral(java.lang.Character c)
           
static Literal makeLiteral(double num)
          Makes a new object of Literal class from the number.
static Literal makeLiteral(java.lang.Double d)
           
static Literal makeLiteral(float num)
          Makes a new object of Literal class from the number.
static Literal makeLiteral(java.lang.Float f)
           
static Literal makeLiteral(int num)
          Makes a new object of Literal class from the number.
static Literal makeLiteral(java.lang.Integer n)
           
static Literal makeLiteral(long num)
          Makes a new object of Literal class from the number.
static Literal makeLiteral(java.lang.Long n)
           
static Literal makeLiteral(java.lang.String str)
          Makes a new object of Literal class from the string.
 
Methods inherited from class openjava.ptree.Leaf
childrenAccept, equals, equals, getTokenID, makeCopy, makeRecursiveCopy, replaceChildWith, toString, writeCode
 
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
childrenAccept, eq, equals, getObjectID, makeCopy, makeRecursiveCopy, replace, toFlattenString, toString, writeCode
 

Field Detail

BOOLEAN

public static final int BOOLEAN
See Also:
getLiteralType()

INTEGER

public static final int INTEGER

LONG

public static final int LONG

FLOAT

public static final int FLOAT

DOUBLE

public static final int DOUBLE

CHARACTER

public static final int CHARACTER

STRING

public static final int STRING

NULL

public static final int NULL

id

protected int id
Constructor Detail

Literal

public Literal(int id,
               java.lang.String str)
Allocates a new object. If you want to make String literal like "test", call this constructor in the form :
     new Literal( Literal.STRING, "\"test\"" )
 

or use makeLiteral() static method.
Parameters:
id - the id number of the literal.
str - the literal as a String.
See Also:
makeLiteral(String)
Method Detail

makeLiteral

public static Literal makeLiteral(java.lang.String str)
Makes a new object of Literal class from the string.
Parameters:
str - the string.

makeLiteral

public static Literal makeLiteral(boolean b)
Makes a new object of Literal class from the boolean.
Parameters:
b - the boolean.

makeLiteral

public static Literal makeLiteral(java.lang.Boolean b)

makeLiteral

public static Literal makeLiteral(char c)
Makes a new object of Literal class from the character.
Parameters:
c - the character.

makeLiteral

public static Literal makeLiteral(java.lang.Character c)

makeLiteral

public static Literal makeLiteral(int num)
Makes a new object of Literal class from the number.
Parameters:
num - the number.

makeLiteral

public static Literal makeLiteral(java.lang.Integer n)

makeLiteral

public static Literal makeLiteral(long num)
Makes a new object of Literal class from the number.
Parameters:
num - the number.

makeLiteral

public static Literal makeLiteral(java.lang.Long n)

makeLiteral

public static Literal makeLiteral(float num)
Makes a new object of Literal class from the number.
Parameters:
num - the number.

makeLiteral

public static Literal makeLiteral(java.lang.Float f)

makeLiteral

public static Literal makeLiteral(double num)
Makes a new object of Literal class from the number.
Parameters:
num - the number.

makeLiteral

public static Literal makeLiteral(java.lang.Double d)

getLiteralType

public int getLiteralType()

constantTrue

public static Literal constantTrue()

constantFalse

public static Literal constantFalse()

constantNull

public static Literal constantNull()

constantEmptyString

public static Literal constantEmptyString()

constantZero

public static Literal constantZero()

constantOne

public static Literal constantOne()

getType

public OJClass getType(Environment env)
                throws java.lang.Exception
Specified by:
getType in interface Expression

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
Overrides:
accept in class Leaf
Following copied from interface: openjava.ptree.ParseTree
Parameters:
visitor - a visitor