use of org.eclipse.core.expressions.Expression 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.Expression in project eclipse.platform.runtime by eclipse.
the class ReferenceExpression method collectExpressionInfo.
@Override
public void collectExpressionInfo(ExpressionInfo info) {
Expression expr;
try {
expr = getDefinitionRegistry().getExpression(fDefinitionId);
} catch (CoreException e) {
// expression info can be collected.
return;
}
expr.collectExpressionInfo(info);
}
use of org.eclipse.core.expressions.Expression in project polymap4-core by Polymap4.
the class CustomAndExpression method evaluate.
public EvaluationResult evaluate(IEvaluationContext scope) {
if (fExpressions == null) {
return EvaluationResult.TRUE;
}
NavigatorPlugin.Evaluator evaluator = new NavigatorPlugin.Evaluator();
EvaluationResult result = EvaluationResult.TRUE;
for (Iterator iter = fExpressions.iterator(); iter.hasNext(); ) {
Expression expression = (Expression) iter.next();
evaluator.expression = expression;
evaluator.scope = scope;
SafeRunner.run(evaluator);
result = result.and(evaluator.result);
// that we find a false which will result in a better result.
if (result == EvaluationResult.FALSE) {
return result;
}
}
return result;
}
use of org.eclipse.core.expressions.Expression in project tdi-studio-se by Talend.
the class TalendLaunchShortcutAction method updateEnablement.
/**
* Since these actions are re-created each time the run/debug as menu is filled, the enablement of this action is
* static.
*/
private void updateEnablement() {
// IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
IWorkbenchWindow wb = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
boolean enabled = false;
if (wb != null) {
IWorkbenchPage page = wb.getActivePage();
if (page != null) {
ISelection selection = page.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
try {
// check enablement logic, if any
Expression expression = fShortcut.getShortcutEnablementExpression();
if (expression == null) {
enabled = !structuredSelection.isEmpty();
} else {
List list = structuredSelection.toList();
IEvaluationContext context = new EvaluationContext(null, list);
//$NON-NLS-1$
context.addVariable("selection", list);
enabled = fShortcut.evalEnablementExpression(context, expression);
}
} catch (CoreException e) {
}
} else {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
enabled = true;
}
}
}
}
setEnabled(enabled);
}
use of org.eclipse.core.expressions.Expression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionAndFalse.
public void testIterateExpressionAndFalse() 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("and");
exp.add(myExpression);
List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
// $NON-NLS-1$
input.add("two");
EvaluationContext context = new EvaluationContext(null, input);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
// $NON-NLS-1$
assertTrue(result.size() == 1 && result.get(0).equals("one"));
}
Aggregations