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 31 public class ReferenceExpression extends Expression { 32 33 private static DefinitionRegistry fgDefinitionRegistry= null; 36 37 private static DefinitionRegistry getDefinitionRegistry() { 38 if (fgDefinitionRegistry == null) { 39 fgDefinitionRegistry= new DefinitionRegistry(); 40 } 41 return fgDefinitionRegistry; 42 } 43 44 private static final String ATT_DEFINITION_ID= "definitionId"; 46 49 private static final int HASH_INITIAL= ReferenceExpression.class.getName().hashCode(); 50 51 private String fDefinitionId; 52 53 public ReferenceExpression(String definitionId) { 54 Assert.isNotNull(definitionId); 55 fDefinitionId= definitionId; 56 } 57 58 public ReferenceExpression(IConfigurationElement element) throws CoreException { 59 fDefinitionId= element.getAttribute(ATT_DEFINITION_ID); 60 Expressions.checkAttribute(ATT_DEFINITION_ID, fDefinitionId); 61 } 62 63 public ReferenceExpression(Element element) throws CoreException { 64 fDefinitionId= element.getAttribute(ATT_DEFINITION_ID); 65 Expressions.checkAttribute(ATT_DEFINITION_ID, fDefinitionId.length() > 0 ? fDefinitionId : null); 66 } 67 68 public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { 69 Expression expr= getDefinitionRegistry().getExpression(fDefinitionId); 70 return expr.evaluate(context); 71 } 72 73 public void collectExpressionInfo(ExpressionInfo info) { 74 Expression expr; 75 try { 76 expr= getDefinitionRegistry().getExpression(fDefinitionId); 77 } catch (CoreException e) { 78 return; 81 } 82 expr.collectExpressionInfo(info); 83 } 84 85 public boolean equals(final Object object) { 86 if (!(object instanceof ReferenceExpression)) 87 return false; 88 89 final ReferenceExpression that= (ReferenceExpression)object; 90 return this.fDefinitionId.equals(that.fDefinitionId); 91 } 92 93 protected int computeHashCode() { 94 return HASH_INITIAL * HASH_FACTOR + fDefinitionId.hashCode(); 95 } 96 } | Popular Tags |