Search in sources :

Example 21 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testAdaptExpressionWithNull.

/**
 * Bug 484325
 */
public void testAdaptExpressionWithNull() throws Exception {
    // it's surprisingly difficult to craft an EvaluationContext that
    // provides
    // a defaultVariable == null
    IEvaluationContext testContext = new EvaluationContext(null, new Adaptee());
    testContext.addVariable("nullCarrier", Arrays.asList((Object) null, (Object) null, (Object) null));
    WithExpression withExpression = new WithExpression("nullCarrier");
    IterateExpression iterateExpression = new IterateExpression("and");
    iterateExpression.add(new AdaptExpression("org.eclipse.core.internal.expressions.tests.NotExisting"));
    withExpression.add(iterateExpression);
    EvaluationResult result = withExpression.evaluate(testContext);
    assertTrue(result == EvaluationResult.FALSE);
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 22 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testAdaptExpressionAdaptable.

public void testAdaptExpressionAdaptable() 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 AdaptableAdaptee()));
    assertTrue(result == EvaluationResult.TRUE);
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) AdaptExpression(org.eclipse.core.internal.expressions.AdaptExpression) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 23 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testPlatformPropertyTester.

public void testPlatformPropertyTester() 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, "test3").getChildren("enablement")[0];
    Expression exp = ExpressionConverter.getDefault().perform(enable);
    EvaluationContext context = new EvaluationContext(null, Platform.class);
    assertEquals(EvaluationResult.TRUE, exp.evaluate(context));
}
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) 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 24 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionAnyNumber.

public void testCountExpressionAnyNumber() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("*");
    List<String> list = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == 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");
    // $NON-NLS-1$
    list.add("three");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 25 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testIterateExpressionWithAdapterManagerIfEmptyFalse.

public void testIterateExpressionWithAdapterManagerIfEmptyFalse() throws Exception {
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("or", "false");
    final List<String> input = new ArrayList<>();
    CollectionWrapper wrapper = new CollectionWrapper();
    wrapper.collection = input;
    EvaluationContext context = new EvaluationContext(null, wrapper);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) 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