Search in sources :

Example 31 with EvaluationContext

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));
}
Also used : AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 32 with EvaluationContext

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));
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression)

Example 33 with EvaluationContext

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));
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) AndExpression(org.eclipse.core.internal.expressions.AndExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) ResolveExpression(org.eclipse.core.internal.expressions.ResolveExpression) OrExpression(org.eclipse.core.internal.expressions.OrExpression) Expression(org.eclipse.core.expressions.Expression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) NotExpression(org.eclipse.core.internal.expressions.NotExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 34 with EvaluationContext

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);
}
Also used : TestExpression(org.eclipse.core.internal.expressions.TestExpression) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 35 with EvaluationContext

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;
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) Iterator(java.util.Iterator) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Aggregations

EvaluationContext (org.eclipse.core.expressions.EvaluationContext)71 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)56 ArrayList (java.util.ArrayList)26 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)22 CountExpression (org.eclipse.core.internal.expressions.CountExpression)14 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)13 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)12 Command (org.eclipse.core.commands.Command)11 WithExpression (org.eclipse.core.internal.expressions.WithExpression)11 ICommandService (org.eclipse.ui.commands.ICommandService)11 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)10 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)10 CoreException (org.eclipse.core.runtime.CoreException)10 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)9 TestExpression (org.eclipse.core.internal.expressions.TestExpression)9 IHandlerService (org.eclipse.ui.handlers.IHandlerService)9 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)8 Expression (org.eclipse.core.expressions.Expression)8 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)8 AndExpression (org.eclipse.core.internal.expressions.AndExpression)7