openjava.ptree
Class ConditionalExpression

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

public class ConditionalExpression
extends NonLeaf
implements Expression

The ConditionalExpression class represents a conditional expression.

Here is an example:

     (i == 1) ? 3 : 4
 

This consists of a conditional part, true case part, and false case part. Each part of them is an expression.
If the operator in the expression of the operands has weak unity, this automatically produces the code in which the operands are enclosed by parenthesises.
In the case the conditional part is f = f(), the true case part is "red" and the false case part is str = "blue" this produces the code :
     (f = f()) ? "red" : (str = "blue")
 

See Also:
Expression

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) ConditionalExpression()
           
  ConditionalExpression(Expression condition, Expression truecase, Expression falsecase)
          Allocates a new conditional expression 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 getCondition()
          Gets the conditional part of this conditional expression.
 Expression getFalseCase()
          Gets the false case part of this.
 Expression getTrueCase()
          Gets the true case part of this conditional expression.
 OJClass getType(Environment env)
           
 void setCondition(Expression expr)
          Sets the conditional part of this conditional expression.
 void setFalseCase(Expression expr)
          Sets the false case part of this.
 void setTrueCase(Expression expr)
          Sets the true case part of this conditional 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

ConditionalExpression

public ConditionalExpression(Expression condition,
                             Expression truecase,
                             Expression falsecase)
Allocates a new conditional expression object.

Parameters:
condition - the conditional part of this expression.
truecase - the expression to be evaluated when conditional part is true.
falsecase - the expression to be evaluated when conditional part is false.

ConditionalExpression

ConditionalExpression()
Method Detail

writeCode

public void writeCode()
Description copied from class: NonLeaf
Writes the code this parse-tree presents for.

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

getCondition

public Expression getCondition()
Gets the conditional part of this conditional expression.

Returns:
the expression of this conditional part.

setCondition

public void setCondition(Expression expr)
Sets the conditional part of this conditional expression.

Parameters:
expr - the expression to set as this conditional part.

getTrueCase

public Expression getTrueCase()
Gets the true case part of this conditional expression.

Returns:
the expression of this true case part.

setTrueCase

public void setTrueCase(Expression expr)
Sets the true case part of this conditional expression.

Parameters:
expr - the expression to set as this true part.

getFalseCase

public Expression getFalseCase()
Gets the false case part of this.

Returns:
the expression of this false case part.

setFalseCase

public void setFalseCase(Expression expr)
Sets the false case part of this.

Parameters:
expr - the expression to set as this false part.

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