Search in sources :

Example 11 with IterateExpression

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

the class ExpressionTests method testIterateExpressionHashCode.

public void testIterateExpressionHashCode() throws Exception {
    IterateExpression expression1 = new IterateExpression("and");
    expression1.add(new InstanceofExpression(// $NON-NLS-1$
    "org.eclipse.core.internal.expressions.tests.Adapter"));
    IterateExpression expression2 = new IterateExpression("and");
    expression2.add(new InstanceofExpression(// $NON-NLS-1$
    "org.eclipse.core.internal.expressions.tests.Adapter"));
    assertEquals("Equal expressions should have the same hash code", expression1.hashCode(), expression2.hashCode());
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression)

Example 12 with IterateExpression

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

the class ExpressionTests method testIterateExpressionAndMultiChildren.

public void testIterateExpressionAndMultiChildren() throws Exception {
    // Test for Bug 260522: <iterate> iterates over collection elements,
    // thereby *and*-ing all evaluated child expressions
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("and");
    exp.add(Expression.FALSE);
    exp.add(Expression.TRUE);
    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));
}
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 13 with IterateExpression

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

use of org.eclipse.core.internal.expressions.IterateExpression 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"));
}
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 15 with IterateExpression

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

the class ExpressionTests method testIterateExpressionAndTrue.

public void testIterateExpressionAndTrue() 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.TRUE;
        }
    };
    // $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.TRUE == 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)

Aggregations

IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)22 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)20 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)20 ArrayList (java.util.ArrayList)18 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)8 WithExpression (org.eclipse.core.internal.expressions.WithExpression)7 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)6 Expression (org.eclipse.core.expressions.Expression)5 AndExpression (org.eclipse.core.internal.expressions.AndExpression)5 CountExpression (org.eclipse.core.internal.expressions.CountExpression)5 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)5 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)5 NotExpression (org.eclipse.core.internal.expressions.NotExpression)5 OrExpression (org.eclipse.core.internal.expressions.OrExpression)5 ResolveExpression (org.eclipse.core.internal.expressions.ResolveExpression)5 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)5 TestExpression (org.eclipse.core.internal.expressions.TestExpression)5 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)2 AbstractCollection (java.util.AbstractCollection)1 HashSet (java.util.HashSet)1