1 package org.apache.ojb.jdo.jdoql; 2 3 17 18 23 public class UnaryExpression extends Expression 24 { 25 public static final int OPERATOR_MINUS = 0; 26 public static final int OPERATOR_PLUS = 1; 27 public static final int OPERATOR_BITWISE_COMPLEMENT = 2; 28 public static final int OPERATOR_NOT = 3; 29 public static final int OPERATOR_CAST = 4; 30 31 32 private int _operator; 33 34 private Expression _inner; 35 36 private Type _castType; 37 38 private Class _type; 39 40 46 public UnaryExpression(int operator, Expression inner) 47 { 48 _operator = operator; 49 _inner = inner; 50 } 51 52 58 public UnaryExpression(Type castType, Expression inner) 59 { 60 _operator = OPERATOR_CAST; 61 _castType = castType; 62 _inner = inner; 63 } 64 65 70 public int getOperator() 71 { 72 return _operator; 73 } 74 75 80 public Expression getInnerExpression() 81 { 82 return _inner; 83 } 84 85 88 public void replaceChild(Expression oldChild, Expression newChild) 89 { 90 _inner.setParent(null); 91 _inner = newChild; 92 _inner.setParent(this); 93 } 94 95 101 public Type getCastType() 102 { 103 return _castType; 104 } 105 106 109 public void accept(Visitor visitor) 110 { 111 visitor.visit(this); 112 } 113 114 117 public String toString() 118 { 119 StringBuffer result = new StringBuffer (); 120 121 result.append("("); 122 switch (_operator) 123 { 124 case OPERATOR_PLUS : 125 result.append("+"); 126 break; 127 case OPERATOR_MINUS : 128 result.append("-"); 129 break; 130 case OPERATOR_BITWISE_COMPLEMENT : 131 result.append("~"); 132 break; 133 case OPERATOR_NOT : 134 result.append("!"); 135 break; 136 case OPERATOR_CAST : 137 result.append("("); 138 result.append(_castType.toString()); 139 result.append(")"); 140 break; 141 } 142 result.append(_inner.toString()); 143 result.append(")"); 144 return result.toString(); 145 } 146 147 152 public void setType(Class type) 153 { 154 _type = type; 155 } 156 157 160 public Class getType() 161 { 162 return _type; 163 } 164 } 165 | Popular Tags |