1 11 12 package org.eclipse.ui.internal.services; 13 14 import org.eclipse.core.expressions.EvaluationResult; 15 import org.eclipse.core.expressions.Expression; 16 import org.eclipse.core.expressions.IEvaluationContext; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.ui.ISources; 19 20 29 public abstract class EvaluationResultCache implements IEvaluationResultCache { 30 31 35 private EvaluationResult evaluationResult = null; 36 37 41 private final Expression expression; 42 43 46 private final int sourcePriority; 47 48 57 protected EvaluationResultCache(final Expression expression) { 58 this.expression = expression; 59 this.sourcePriority = SourcePriorityNameMapping 60 .computeSourcePriority(expression); 61 } 62 63 public final void clearResult() { 64 evaluationResult = null; 65 } 66 67 public final boolean evaluate(final IEvaluationContext context) { 68 if (expression == null) { 69 return true; 70 } 71 72 if (evaluationResult == null) { 73 try { 74 evaluationResult = expression.evaluate(context); 75 } catch (final CoreException e) { 76 82 evaluationResult = EvaluationResult.FALSE; 83 return false; 84 } 85 } 86 87 return evaluationResult == EvaluationResult.TRUE; 88 } 89 90 public final Expression getExpression() { 91 return expression; 92 } 93 94 public final int getSourcePriority() { 95 return sourcePriority; 96 } 97 98 public final void setResult(final boolean result) { 99 if (result) { 100 evaluationResult = EvaluationResult.TRUE; 101 } else { 102 evaluationResult = EvaluationResult.FALSE; 103 } 104 } 105 } 106 | Popular Tags |