openjava.ptree
Class CastExpression

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

public class CastExpression
extends NonLeaf
implements Expression

The CastExpression class represents a cast expression of parse tree.
If the operator in the expression of the right operand has week unity, this automatically produces the code in which the right operand is enclosed by parenthesises.
In the case the caster is int and the right operand to be casted is p + q, this produces the code :

     (int) (p + q)
 

See Also:
NonLeaf, Expression, TypeName

Field Summary
 
Fields inherited from class openjava.ptree.NonLeaf
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
(package private) CastExpression()
           
  CastExpression(OJClass type, Expression expr)
           
  CastExpression(TypeName ts, Expression expr)
          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.
 Expression getExpression()
          Gets the expression of the operand to be casted in this expression.
 OJClass getType(Environment env)
           
 TypeName getTypeSpecifier()
          Gets the type specifier to cast in this expression.
 void setExpression(Expression expr)
          Sets the expression of the operand to be casted in this expression.
 void setTypeSpecifier(TypeName tspec)
          Sets the type specifier to cast in this expression.
 void writeCode()
          Writes the code this parse-tree presents for.
 
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.Expression
getRowType
 
Methods inherited from interface openjava.ptree.ParseTree
childrenAccept, eq, equals, getObjectID, makeCopy, makeRecursiveCopy, replace, toFlattenString, toString
 

Constructor Detail

CastExpression

public CastExpression(TypeName ts,
                      Expression expr)
Allocates a new object.

Parameters:
ts - the type specifier to cast in this expression.
expr - the expression to be casted in this expression.

CastExpression

public CastExpression(OJClass type,
                      Expression expr)

CastExpression

CastExpression()
Method Detail

writeCode

public void writeCode()
Deprecated.  

Description copied from class: NonLeaf
Writes the code this parse-tree presents for.

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

getTypeSpecifier

public TypeName getTypeSpecifier()
Gets the type specifier to cast in this expression.

Returns:
the type specifier.

setTypeSpecifier

public void setTypeSpecifier(TypeName tspec)
Sets the type specifier to cast in this expression.

Parameters:
tspec - the type specifier.

getExpression

public Expression getExpression()
Gets the expression of the operand to be casted in this expression.

Returns:
the expression.

setExpression

public void setExpression(Expression expr)
Sets the expression of the operand to be casted in this expression.

Parameters:
expr - the 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
Specified by:
accept in class ParseTreeObject
Parameters:
v - a visitor
ParseTreeException

getType

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

SourceForge.net_Logo