openjava.ptree
Class UnaryExpression

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

public class UnaryExpression
extends NonLeaf
implements Expression

The UnaryExpression class presents for an expression which consists of unary operator with one Expression.
The unary expressions are :

expr++, expr--, ++expr, --expr, ^expr, !expr, +expr or -expr

,where expr is an expression.
If the operator in the expression of the operand has week unity, this automatically produces the code in which the operand is enclosed by parenthesises.
In the case the operand is y = x and the urary operator is +, this produces the code :
     +(y = x)
 

See Also:
NonLeaf, Expression

Field Summary
static int BIT_NOT
          Post increment operator.
static int EXISTS
          Exists operator.
static int MINUS
          Post increment operator.
static int NOT
          Post increment operator.
private  int opr
          operator
private static String[] opr_string
           
static int PLUS
          Post increment operator.
static int POST_DECREMENT
          Post decrement operator.
static int POST_INCREMENT
          Post increment operator.
static int PRE_DECREMENT
          Post increment operator.
static int PRE_INCREMENT
          Pre increment operator.
 
Fields inherited from class openjava.ptree.NonLeaf
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
(package private) UnaryExpression()
           
  UnaryExpression(Expression expr, int opr)
          Allocates a new object.
  UnaryExpression(int opr, 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 operated in this expression.
 int getOperator()
          Gets the operator of this unary expression.
 OJClass getType(Environment env)
           
 boolean isPostfix()
          Tests if the operator of unary expression is a postfix operator.
 boolean isPrefix()
          Tests if the operator of unary expression is a prefix operator.
 ParseTree makeCopy()
          Makes a new copy of this nonleaf-node as a ptree-node.
 ParseTree makeRecursiveCopy()
          Makes a new copy (another object) of this nonleaf-node recursively.
 String operatorString()
           
 void setExpression(Expression expr)
          Sets the expression operated in this expression.
 void setOperator(int opr)
          Sets the operator of this unary 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, 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, 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, replace, toFlattenString, toString
 

Field Detail

POST_INCREMENT

public static final int POST_INCREMENT
Post increment operator. For example:
     i++
 

See Also:
Constant Field Values

POST_DECREMENT

public static final int POST_DECREMENT
Post decrement operator. For example:
     i--
 

See Also:
Constant Field Values

PRE_INCREMENT

public static final int PRE_INCREMENT
Pre increment operator. For example:
     ++i
 

See Also:
Constant Field Values

PRE_DECREMENT

public static final int PRE_DECREMENT
Post increment operator. For example:
     --i
 

See Also:
Constant Field Values

BIT_NOT

public static final int BIT_NOT
Post increment operator. For example:
     ~i
 

See Also:
Constant Field Values

NOT

public static final int NOT
Post increment operator. For example:
     ! c
 

See Also:
Constant Field Values

PLUS

public static final int PLUS
Post increment operator. For example:
     +i
 

See Also:
Constant Field Values

MINUS

public static final int MINUS
Post increment operator. For example:
     -i
 

See Also:
Constant Field Values

EXISTS

public static final int EXISTS
Exists operator. For example:
     exists (select from emp)
 

See Also:
Constant Field Values

opr_string

private static final String[] opr_string

opr

private int opr
operator

Constructor Detail

UnaryExpression

public UnaryExpression(int opr,
                       Expression expr)
Allocates a new object.

Parameters:
opr - the operator of this unary expression.
expr - the expression.

UnaryExpression

public UnaryExpression(Expression expr,
                       int opr)
Allocates a new object.

Parameters:
expr - the expression.
opr - the operator of this unary expression.

UnaryExpression

UnaryExpression()
Method Detail

makeRecursiveCopy

public ParseTree makeRecursiveCopy()
Description copied from interface: ParseTree
Makes a new copy (another object) of this nonleaf-node recursively. The objects contained by this object will also be copied.

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

makeCopy

public ParseTree makeCopy()
Description copied from interface: ParseTree
Makes a new copy of this nonleaf-node as a ptree-node. The objects contained by the new object are same as these contained by the original object.

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

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

getExpression

public Expression getExpression()
Gets the expression operated in this expression.

Returns:
the expression.

setExpression

public void setExpression(Expression expr)
Sets the expression operated in this expression.

Parameters:
expr - the expression to set.

getOperator

public int getOperator()
Gets the operator of this unary expression.

Returns:
the operator.
See Also:
POST_INCREMENT, POST_DECREMENT, PRE_INCREMENT, PRE_DECREMENT, BIT_NOT, NOT, PLUS, MINUS, EXISTS

setOperator

public void setOperator(int opr)
Sets the operator of this unary expression.

Parameters:
opr - the operator id to set.
See Also:
POST_INCREMENT, POST_DECREMENT, PRE_INCREMENT, PRE_DECREMENT, BIT_NOT, NOT, PLUS, MINUS, EXISTS

isPostfix

public boolean isPostfix()
Tests if the operator of unary expression is a postfix operator.

Returns:
true if the operator is postfix.

isPrefix

public boolean isPrefix()
Tests if the operator of unary expression is a prefix operator.

Returns:
true if the operator is prefix.

operatorString

public String operatorString()

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