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