Search in sources :

Example 6 with WithExpression

use of org.eclipse.core.internal.expressions.WithExpression 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 7 with WithExpression

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

the class ExpressionInfoTests method testWithExpression.

public void testWithExpression() {
    WithExpression with = new WithExpression("variable");
    assertNoAccess(with.computeExpressionInfo());
    with.add(new CountExpression("10"));
    assertVariableAccess(with.computeExpressionInfo(), "variable");
}
Also used : CountExpression(org.eclipse.core.internal.expressions.CountExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression)

Aggregations

WithExpression (org.eclipse.core.internal.expressions.WithExpression)7 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)4 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)4 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)3 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)2 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)2 AbstractCollection (java.util.AbstractCollection)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)1 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)1 CountExpression (org.eclipse.core.internal.expressions.CountExpression)1 CoreException (org.eclipse.core.runtime.CoreException)1