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