1 package net.sf.saxon.expr; 2 import net.sf.saxon.om.NamePool; 3 import net.sf.saxon.trans.DynamicError; 4 import net.sf.saxon.trans.XPathException; 5 import net.sf.saxon.type.ItemType; 6 import net.sf.saxon.value.Value; 7 8 import java.io.PrintStream ; 9 import java.util.Iterator ; 10 11 14 15 public abstract class UnaryExpression extends ComputedExpression { 16 17 protected Expression operand; 18 19 public UnaryExpression(Expression p0) { 20 operand = p0; 21 Container parent = (p0 instanceof ComputedExpression ? ((ComputedExpression)p0).getParentExpression() : null); 22 adoptChildExpression(p0); 23 setParentExpression(parent); 24 } 25 26 public Expression getBaseExpression() { 27 return operand; 28 } 29 30 34 35 public Expression simplify(StaticContext env) throws XPathException { 36 operand = operand.simplify(env); 37 return this; 38 } 39 40 44 45 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 46 operand = operand.typeCheck(env, contextItemType); 47 try { 49 if (operand instanceof Value) { 50 return ExpressionTool.eagerEvaluate(this, null); 51 } 52 } catch (DynamicError err) { 53 } 56 return this; 57 } 58 59 76 77 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 78 operand = operand.optimize(opt, env, contextItemType); 79 try { 81 if (operand instanceof Value) { 82 return ExpressionTool.eagerEvaluate(this, null); 83 } 84 } catch (DynamicError err) { 85 } 88 return this; 89 } 90 91 92 95 96 public Expression promote(PromotionOffer offer) throws XPathException { 97 Expression exp = offer.accept(this); 98 if (exp != null) { 99 return exp; 100 } else { 101 operand = doPromotion(operand, offer); 102 return this; 103 } 104 } 105 106 109 110 public Iterator iterateSubExpressions() { 111 return new MonoIterator(operand); 112 } 113 114 119 120 public int computeSpecialProperties() { 121 return operand.getSpecialProperties(); 122 } 123 124 127 128 public int computeCardinality() { 129 return operand.getCardinality(); 130 } 131 132 138 139 public ItemType getItemType() { 140 return operand.getItemType(); 141 } 142 143 146 147 public boolean equals(Object other) { 148 return this.getClass().equals(other.getClass()) && 149 this.operand.equals(((UnaryExpression)other).operand); 150 } 151 152 156 157 public int hashCode() { 158 return ("UnaryExpression " + getClass()).hashCode() ^ operand.hashCode(); 159 } 160 161 164 165 public void display(int level, NamePool pool, PrintStream out) { 166 out.println(ExpressionTool.indent(level) + displayOperator(pool)); 167 operand.display(level+1, pool, out); 168 } 169 170 174 175 protected abstract String displayOperator(NamePool pool); 176 177 } 178 179 | Popular Tags |