1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 17 import org.eclipse.core.expressions.EvaluationContext; 18 import org.eclipse.core.expressions.EvaluationResult; 19 import org.eclipse.core.expressions.Expression; 20 import org.eclipse.core.expressions.ExpressionConverter; 21 import org.eclipse.core.expressions.ExpressionTagNames; 22 23 public abstract class AbstractDescriptor { 24 25 protected IConfigurationElement fConfigurationElement; 26 protected Expression fExpression; 27 28 protected static final String ID= "id"; protected static final String OBJECT_STATE= "objectState"; protected static final String CLASS= "class"; 32 protected AbstractDescriptor(IConfigurationElement element) { 33 fConfigurationElement= element; 34 } 35 36 public String getId() { 37 return fConfigurationElement.getAttribute(ID); 38 } 39 40 public boolean matches(Object element, String variableName) throws CoreException { 41 Assert.isNotNull(element); 42 Assert.isNotNull(variableName); 43 Expression exp= getExpression(); 44 EvaluationContext evaluationContext= new EvaluationContext(null, element); 45 evaluationContext.addVariable(variableName, element); 46 if (exp.evaluate(evaluationContext) == EvaluationResult.FALSE) 47 return false; 48 return true; 49 } 50 51 public Expression getExpression() throws CoreException { 52 if (fExpression == null) 53 fExpression= createExpression(fConfigurationElement); 54 return fExpression; 55 } 56 57 public void clear() { 58 fExpression= null; 59 } 60 61 protected Expression createExpression(IConfigurationElement element) throws CoreException { 62 IConfigurationElement[] children= element.getChildren(ExpressionTagNames.ENABLEMENT); 63 if (children.length == 0) 64 return Expression.FALSE; 65 Assert.isTrue(children.length == 1); 67 return ExpressionConverter.getDefault().perform(children[0]); 68 } 69 } 70 | Popular Tags |