Search in sources :

Example 61 with EvaluationContext

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

the class ExpressionTests method testAdaptExpressionFail.

public void testAdaptExpressionFail() throws Exception {
    // $NON-NLS-1$
    AdaptExpression expression = new AdaptExpression("org.eclipse.core.internal.expressions.tests.NotExisting");
    EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Adaptee()));
    assertTrue(result == EvaluationResult.FALSE);
}
Also used : 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 62 with EvaluationContext

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

the class ExpressionTests method testSubType.

public void testSubType() throws Exception {
    EvaluationContext context = new EvaluationContext(null, IEvaluationContext.UNDEFINED_VARIABLE);
    ArrayList<AbstractCollection<?>> list = new ArrayList<>();
    HashSet<?> o1 = new HashSet<>();
    EvaluationContext c1 = new EvaluationContext(null, o1);
    list.add(o1);
    ArrayList<?> o2 = new ArrayList<>();
    EvaluationContext c2 = new EvaluationContext(null, o2);
    list.add(o2);
    LinkedList<?> o3 = new LinkedList<>();
    EvaluationContext c3 = new EvaluationContext(null, o3);
    list.add(o3);
    context.addVariable("selection", list);
    WithExpression with = new WithExpression("selection");
    IterateExpression iterate = new IterateExpression("and", "false");
    with.add(iterate);
    InstanceofExpression iCollection = new InstanceofExpression("java.util.Collection");
    iterate.add(iCollection);
    InstanceofExpression iSet = new InstanceofExpression("java.util.Set");
    InstanceofExpression iList = new InstanceofExpression("java.util.List");
    assertEquals(EvaluationResult.TRUE, iSet.evaluate(c1));
    assertEquals(EvaluationResult.FALSE, iList.evaluate(c1));
    assertEquals(EvaluationResult.FALSE, iSet.evaluate(c2));
    assertEquals(EvaluationResult.TRUE, iList.evaluate(c2));
    assertEquals(EvaluationResult.FALSE, iSet.evaluate(c3));
    assertEquals(EvaluationResult.TRUE, iList.evaluate(c3));
    assertEquals(EvaluationResult.TRUE, with.evaluate(context));
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) AbstractCollection(java.util.AbstractCollection) ArrayList(java.util.ArrayList) 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) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 63 with EvaluationContext

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

the class ExpressionTests method testInstanceofTrue.

public void testInstanceofTrue() throws Exception {
    B b = new B();
    EvaluationContext context = new EvaluationContext(null, b);
    // $NON-NLS-1$
    InstanceofExpression exp = new InstanceofExpression("org.eclipse.core.internal.expressions.tests.B");
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    // $NON-NLS-1$
    exp = new InstanceofExpression("org.eclipse.core.internal.expressions.tests.A");
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    // $NON-NLS-1$
    exp = new InstanceofExpression("org.eclipse.core.internal.expressions.tests.I");
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 64 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionOr_IfEmptyTrue.

public void testIterateExpressionOr_IfEmptyTrue() throws Exception {
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("or", "true");
    List<?> input = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.TRUE == 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)

Example 65 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionEmptyAnd.

public void testIterateExpressionEmptyAnd() throws Exception {
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("and");
    List<?> input = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.TRUE == 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