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.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 class EqualsExpression extends Expression { 25 28 private static final int HASH_INITIAL= EqualsExpression.class.getName().hashCode(); 29 30 private Object fExpectedValue; 31 32 public EqualsExpression(Object expectedValue) { 33 Assert.isNotNull(expectedValue); 34 fExpectedValue= expectedValue; 35 } 36 37 public EqualsExpression(IConfigurationElement element) throws CoreException { 38 String value= element.getAttribute(ATT_VALUE); 39 Expressions.checkAttribute(ATT_VALUE, value); 40 fExpectedValue= Expressions.convertArgument(value); 41 } 42 43 public EqualsExpression(Element element) throws CoreException { 44 String value= element.getAttribute(ATT_VALUE); 45 Expressions.checkAttribute(ATT_VALUE, value.length() > 0 ? value : null); 46 fExpectedValue= Expressions.convertArgument(value); 47 } 48 49 public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { 50 Object element= context.getDefaultVariable(); 51 return EvaluationResult.valueOf(element.equals(fExpectedValue)); 52 } 53 54 public void collectExpressionInfo(ExpressionInfo info) { 55 info.markDefaultVariableAccessed(); 56 } 57 58 public boolean equals(final Object object) { 59 if (!(object instanceof EqualsExpression)) 60 return false; 61 62 final EqualsExpression that= (EqualsExpression)object; 63 return this.fExpectedValue.equals(that.fExpectedValue); 64 } 65 66 protected int computeHashCode() { 67 return HASH_INITIAL * HASH_FACTOR + fExpectedValue.hashCode(); 68 } 69 } 70 | Popular Tags |