1 11 package org.eclipse.core.internal.expressions; 12 13 import org.w3c.dom.Element ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IConfigurationElement; 18 19 import org.eclipse.core.expressions.EvaluationContext; 20 import org.eclipse.core.expressions.EvaluationResult; 21 import org.eclipse.core.expressions.ExpressionInfo; 22 import org.eclipse.core.expressions.IEvaluationContext; 23 24 public class WithExpression extends CompositeExpression { 25 26 private String fVariable; 27 private static final String ATT_VARIABLE= "variable"; 29 32 private static final int HASH_INITIAL= WithExpression.class.getName().hashCode(); 33 34 public WithExpression(IConfigurationElement configElement) throws CoreException { 35 fVariable= configElement.getAttribute(ATT_VARIABLE); 36 Expressions.checkAttribute(ATT_VARIABLE, fVariable); 37 } 38 39 public WithExpression(Element element) throws CoreException { 40 fVariable= element.getAttribute(ATT_VARIABLE); 41 Expressions.checkAttribute(ATT_VARIABLE, fVariable.length() > 0 ? fVariable : null); 42 } 43 44 public WithExpression(String variable) { 45 Assert.isNotNull(variable); 46 fVariable= variable; 47 } 48 49 public boolean equals(final Object object) { 50 if (!(object instanceof WithExpression)) 51 return false; 52 53 final WithExpression that= (WithExpression)object; 54 return this.fVariable.equals(that.fVariable) && equals(this.fExpressions, that.fExpressions); 55 } 56 57 protected int computeHashCode() { 58 return HASH_INITIAL * HASH_FACTOR + hashCode(fExpressions) 59 * HASH_FACTOR + fVariable.hashCode(); 60 } 61 62 public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { 63 Object variable= context.getVariable(fVariable); 64 if (variable == null) { 65 throw new CoreException(new ExpressionStatus( 66 ExpressionStatus.VARIABLE_NOT_DEFINED, 67 Messages.format(ExpressionMessages.WithExpression_variable_not_defined, fVariable))); 68 } 69 return evaluateAnd(new EvaluationContext(context, variable)); 70 } 71 72 public void collectExpressionInfo(ExpressionInfo info) { 73 ExpressionInfo other= new ExpressionInfo(); 74 super.collectExpressionInfo(other); 75 if (other.hasDefaultVariableAccess()) { 76 info.addVariableNameAccess(fVariable); 77 } 78 info.mergeExceptDefaultVariable(other); 79 } 80 } | Popular Tags |