1 11 package org.eclipse.core.internal.expressions; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 19 import org.eclipse.core.expressions.EvaluationResult; 20 import org.eclipse.core.expressions.Expression; 21 import org.eclipse.core.expressions.ExpressionInfo; 22 import org.eclipse.core.expressions.IEvaluationContext; 23 24 public abstract class CompositeExpression extends Expression { 25 26 private static final Expression[] EMPTY_ARRAY = new Expression[0]; 27 28 31 private static final int HASH_INITIAL= CompositeExpression.class.getName().hashCode(); 32 33 protected List fExpressions; 34 35 public void add(Expression expression) { 36 if (fExpressions == null) 37 fExpressions= new ArrayList (2); 38 fExpressions.add(expression); 39 } 40 41 public Expression[] getChildren() { 42 if (fExpressions == null) 43 return EMPTY_ARRAY; 44 return (Expression[])fExpressions.toArray(new Expression[fExpressions.size()]); 45 } 46 47 protected EvaluationResult evaluateAnd(IEvaluationContext scope) throws CoreException { 48 if (fExpressions == null) 49 return EvaluationResult.TRUE; 50 EvaluationResult result= EvaluationResult.TRUE; 51 for (Iterator iter= fExpressions.iterator(); iter.hasNext();) { 52 Expression expression= (Expression)iter.next(); 53 result= result.and(expression.evaluate(scope)); 54 if (result == EvaluationResult.FALSE) 57 return result; 58 } 59 return result; 60 } 61 62 protected EvaluationResult evaluateOr(IEvaluationContext scope) throws CoreException { 63 if (fExpressions == null) 64 return EvaluationResult.TRUE; 65 EvaluationResult result= EvaluationResult.FALSE; 66 for (Iterator iter= fExpressions.iterator(); iter.hasNext();) { 67 Expression expression= (Expression)iter.next(); 68 result= result.or(expression.evaluate(scope)); 69 if (result == EvaluationResult.TRUE) 70 return result; 71 } 72 return result; 73 } 74 75 public void collectExpressionInfo(ExpressionInfo info) { 76 if (fExpressions == null) 77 return; 78 for (Iterator iter= fExpressions.iterator(); iter.hasNext();) { 79 Expression expression= (Expression)iter.next(); 80 expression.collectExpressionInfo(info); 81 } 82 } 83 84 protected int computeHashCode() { 85 return HASH_INITIAL * HASH_FACTOR + hashCode(fExpressions); 86 } 87 } 88 | Popular Tags |