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 SystemTestExpression extends Expression { 25 26 private String fProperty; 27 private String fExpectedValue; 28 29 private static final String ATT_PROPERTY= "property"; 31 34 private static final int HASH_INITIAL= SystemTestExpression.class.getName().hashCode(); 35 36 public SystemTestExpression(IConfigurationElement element) throws CoreException { 37 fProperty= element.getAttribute(ATT_PROPERTY); 38 Expressions.checkAttribute(ATT_PROPERTY, fProperty); 39 fExpectedValue= element.getAttribute(ATT_VALUE); 40 Expressions.checkAttribute(ATT_VALUE, fExpectedValue); 41 } 42 43 public SystemTestExpression(Element element) throws CoreException { 44 fProperty= element.getAttribute(ATT_PROPERTY); 45 Expressions.checkAttribute(ATT_PROPERTY, fProperty.length() > 0 ? fProperty : null); 46 fExpectedValue= element.getAttribute(ATT_VALUE); 47 Expressions.checkAttribute(ATT_VALUE, fExpectedValue.length() > 0 ? fExpectedValue : null); 48 } 49 50 public SystemTestExpression(String property, String expectedValue) { 51 Assert.isNotNull(property); 52 Assert.isNotNull(expectedValue); 53 fProperty= property; 54 fExpectedValue= expectedValue; 55 } 56 57 public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { 58 String str= System.getProperty(fProperty); 59 if (str == null) 60 return EvaluationResult.FALSE; 61 return EvaluationResult.valueOf(str.equals(fExpectedValue)); 62 } 63 64 public void collectExpressionInfo(ExpressionInfo info) { 65 info.markSystemPropertyAccessed(); 66 } 67 68 public boolean equals(final Object object) { 69 if (!(object instanceof SystemTestExpression)) 70 return false; 71 72 final SystemTestExpression that= (SystemTestExpression)object; 73 return this.fProperty.equals(that.fProperty) 74 && this.fExpectedValue.equals(that.fExpectedValue); 75 } 76 77 protected int computeHashCode() { 78 return HASH_INITIAL * HASH_FACTOR + fExpectedValue.hashCode() 79 * HASH_FACTOR + fProperty.hashCode(); 80 } 81 82 84 87 public String toString() { 88 return "<systemTest property=\"" + fProperty + "\" value=\"" + fExpectedValue + "\""; } 91 } 92 | Popular Tags |