use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testTwoReferences.
public void testTwoReferences() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement enable = findExtension(ces, "refTest2").getChildren("enablement")[0];
EnablementExpression probExpr = (EnablementExpression) ExpressionConverter.getDefault().perform(enable);
EvaluationContext context = new EvaluationContext(null, Collections.EMPTY_LIST);
try {
probExpr.evaluate(context);
fail("Should report error with no variable");
} catch (CoreException e) {
// correct, throw exception
}
context.addVariable("activePartId", "org.eclipse.ui.views.TasksView");
assertEquals(EvaluationResult.FALSE, probExpr.evaluate(context));
context.addVariable("activePartId", "org.eclipse.ui.views.ProblemsView");
// we still have no selection in the default variable
assertEquals(EvaluationResult.FALSE, probExpr.evaluate(context));
context = new EvaluationContext(context, Collections.singletonList(probExpr));
assertEquals(EvaluationResult.TRUE, probExpr.evaluate(context));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionEmptyOr.
public void testIterateExpressionEmptyOr() throws Exception {
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or");
List<?> input = new ArrayList<>();
EvaluationContext context = new EvaluationContext(null, input);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testAdaptExpression.
public void testAdaptExpression() throws Exception {
// $NON-NLS-1$
AdaptExpression expression = new AdaptExpression("org.eclipse.core.internal.expressions.tests.Adapter");
// $NON-NLS-1$
expression.add(new InstanceofExpression("org.eclipse.core.internal.expressions.tests.Adapter"));
EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Adaptee()));
assertTrue(result == EvaluationResult.TRUE);
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testWithExpressionUndefinedVariable.
public void testWithExpressionUndefinedVariable() throws Exception {
WithExpression expr = new WithExpression("variable");
expr.add(new EqualsExpression(new Object()));
EvaluationContext context = new EvaluationContext(null, new Object());
context.addVariable("variable", IEvaluationContext.UNDEFINED_VARIABLE);
assertEquals(EvaluationResult.FALSE, expr.evaluate(context));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testCountExpressionOneOrMore.
public void testCountExpressionOneOrMore() throws Exception {
// $NON-NLS-1$
CountExpression exp = new CountExpression("+");
List<String> list = new ArrayList<>();
EvaluationContext context = new EvaluationContext(null, list);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
list.clear();
// $NON-NLS-1$
list.add("one");
context = new EvaluationContext(null, list);
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
list.clear();
// $NON-NLS-1$
list.add("one");
// $NON-NLS-1$
list.add("two");
context = new EvaluationContext(null, list);
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
}
Aggregations