/* * InstanceofExpression.java 1.0 * * * Jun 20, 1997 by mich * Oct 10, 1997 by mich * * @see io.devnulllabs.openjava.ptree.ParseTree * @version 1.0 last updated: Oct 10, 1997 * @author Michiaki Tatsubori */ package io.devnulllabs.openjava.ptree; import io.devnulllabs.openjava.mop.Environment; import io.devnulllabs.openjava.mop.OJClass; import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor; /** * The InstanceofExpression represents * the expression like : *
 *     obj instanceof Object
 * 

* If the operator in the expression of the left operand has week unity, * this automatically produces the code in which the left operand * is enclosed by parenthesises. *
* In the case the left is obj = obj2 and * the right is String, * this produces the code : *
 *     (obj = obj2) instanceof String
 * 

* * @see io.devnulllabs.openjava.ptree.Expression * @see io.devnulllabs.openjava.ptree.TypeName */ public class InstanceofExpression extends NonLeaf implements Expression { /** * Allocates a new object. * * @param lexp the expression to test. * @param tspec the typespecifier. */ public InstanceofExpression(Expression lexp, TypeName tspec) { super(); set(lexp, tspec); } InstanceofExpression() { super(); } private final boolean needsLeftPar(Expression lexpr) { if (lexpr instanceof AssignmentExpression || lexpr instanceof ConditionalExpression) { return true; } /* this is too strict for + */ if (lexpr instanceof BinaryExpression) { return true; } return false; } /** * Gets the expression of the left operand to be tested * in this expression. * * @return the left expression. */ public Expression getExpression() { return (Expression) elementAt(0); } /** * Sets the expression of the left operand to be tested * in this expression. * * @param lexpr the left expression to set. */ public void setLeft(Expression lexpr) { setElementAt(lexpr, 0); } /** * Gets the type specifier of the right operand to be tested * in this expression. * * @return the type specifier. */ public TypeName getTypeSpecifier() { return (TypeName) elementAt(1); } /** * Sets the type specifier of the right operand to be tested * in this expression. * * @param tspec the type specifier to set. */ public void setTypeSpecifier(TypeName tspec) { setElementAt(tspec, 1); } public OJClass getType(Environment env) throws Exception { return OJClass.forClass(boolean.class); } public void accept(ParseTreeVisitor v) throws ParseTreeException { v.visit(this); } }