use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionWithAdapterManager.
public void testIterateExpressionWithAdapterManager() throws Exception {
final List<Object> result = new ArrayList<>();
Expression myExpression = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
result.add(context.getDefaultVariable());
return EvaluationResult.FALSE;
}
};
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or");
exp.add(myExpression);
final List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
// $NON-NLS-1$
input.add("two");
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.collection = input;
EvaluationContext context = new EvaluationContext(null, wrapper);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
assertTrue(result.equals(input));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testEqualsExpression.
public void testEqualsExpression() throws Exception {
// $NON-NLS-1$
EqualsExpression exp = new EqualsExpression("name");
// $NON-NLS-1$
EvaluationContext context = new EvaluationContext(null, "name");
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
exp = new EqualsExpression(Boolean.TRUE);
context = new EvaluationContext(null, Boolean.TRUE);
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
// $NON-NLS-1$
exp = new EqualsExpression("name");
context = new EvaluationContext(null, Boolean.TRUE);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testDefinitionExpression.
public void testDefinitionExpression() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions", "definitions");
IConfigurationElement expr = findExtension(ces, "org.eclipse.core.expressions.tests.activeProblemsView");
assertNotNull(expr);
Expression probExpr = ExpressionConverter.getDefault().perform(expr.getChildren()[0]);
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");
assertEquals(EvaluationResult.TRUE, probExpr.evaluate(context));
}
use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.
the class PropertyTesterTests method testPlatformTester.
public void testPlatformTester() throws Exception {
TestExpression exp = new TestExpression("org.eclipse.core.runtime", "bundleState", new Object[] { "org.eclipse.core.expressions" }, "ACTIVE", false);
EvaluationContext context = new EvaluationContext(null, Platform.class);
EvaluationResult result = exp.evaluate(context);
assertEquals(EvaluationResult.TRUE, result);
}
use of org.eclipse.core.expressions.EvaluationContext in project polymap4-core by Polymap4.
the class CommonWizardDescriptor method isEnabledFor.
/**
* Determine if this content extension is enabled for the given selection.
* The content extension is enabled for the selection if and only if it is
* enabled for each element in the selection.
*
* @param aStructuredSelection
* The selection from the viewer
* @return True if and only if the extension is enabled for each element in
* the selection.
*/
public boolean isEnabledFor(IStructuredSelection aStructuredSelection) {
if (enablement == null) {
return false;
}
IEvaluationContext context = null;
IEvaluationContext parentContext = NavigatorPlugin.getApplicationContext();
Iterator elements = aStructuredSelection.iterator();
while (elements.hasNext()) {
context = new EvaluationContext(parentContext, elements.next());
context.setAllowPluginActivation(true);
if (NavigatorPlugin.safeEvaluate(enablement, context) == EvaluationResult.FALSE) {
return false;
}
}
return true;
}
Aggregations