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 ResolveExpression extends CompositeExpression { 25 26 private String fVariable; 27 private Object [] fArgs; 28 29 private static final String ATT_VARIABLE= "variable"; private static final String ATT_ARGS= "args"; 32 35 private static final int HASH_INITIAL= ResolveExpression.class.getName().hashCode(); 36 37 public ResolveExpression(IConfigurationElement configElement) throws CoreException { 38 fVariable= configElement.getAttribute(ATT_VARIABLE); 39 Expressions.checkAttribute(ATT_VARIABLE, fVariable); 40 fArgs= Expressions.getArguments(configElement, ATT_ARGS); 41 } 42 43 public ResolveExpression(Element element) throws CoreException { 44 fVariable= element.getAttribute(ATT_VARIABLE); 45 Expressions.checkAttribute(ATT_VARIABLE, fVariable.length() > 0 ? fVariable : null); 46 fArgs= Expressions.getArguments(element, ATT_ARGS); 47 } 48 49 public ResolveExpression(String variable, Object [] args) { 50 Assert.isNotNull(variable); 51 fVariable= variable; 52 fArgs= args; 53 } 54 55 public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { 56 Object variable= context.resolveVariable(fVariable, fArgs); 57 if (variable == null) { 58 throw new CoreException(new ExpressionStatus( 59 ExpressionStatus.VARIABLE_NOT_DEFINED, 60 Messages.format(ExpressionMessages.ResolveExpression_variable_not_defined, fVariable))); 61 } 62 return evaluateAnd(new EvaluationContext(context, variable)); 63 } 64 65 public void collectExpressionInfo(ExpressionInfo info) { 66 ExpressionInfo other= new ExpressionInfo(); 67 super.collectExpressionInfo(other); 68 if (other.hasDefaultVariableAccess()) { 69 info.addVariableNameAccess(fVariable); 70 } 71 info.mergeExceptDefaultVariable(other); 72 } 73 74 public boolean equals(final Object object) { 75 if (!(object instanceof ResolveExpression)) 76 return false; 77 78 final ResolveExpression that= (ResolveExpression)object; 79 return this.fVariable.equals(that.fVariable) 80 && equals(this.fArgs, that.fArgs) 81 && equals(this.fExpressions, that.fExpressions); 82 } 83 84 protected int computeHashCode() { 85 return HASH_INITIAL * HASH_FACTOR + hashCode(fExpressions) 86 * HASH_FACTOR + hashCode(fArgs) 87 * HASH_FACTOR + fVariable.hashCode(); 88 } 89 } 90 | Popular Tags |