Search in sources :

Example 1 with WithExpression

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

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

the class ExpressionTests method testWithExpressionHashCode.

public void testWithExpressionHashCode() throws Exception {
    WithExpression expression1 = new WithExpression("variable");
    expression1.add(new InstanceofExpression(// $NON-NLS-1$
    "org.eclipse.core.internal.expressions.tests.Adapter"));
    WithExpression expression2 = new WithExpression("variable");
    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) WithExpression(org.eclipse.core.internal.expressions.WithExpression)

Example 3 with WithExpression

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

the class ExpressionTests method testWithExpressionNoVariable.

public void testWithExpressionNoVariable() throws Exception {
    WithExpression expr = new WithExpression("variable");
    expr.add(new EqualsExpression(new Object()));
    EvaluationContext context = new EvaluationContext(null, new Object());
    try {
        expr.evaluate(context);
        fail("Should throw exceptoin");
    } catch (CoreException e) {
    // this is success
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) WithExpression(org.eclipse.core.internal.expressions.WithExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression)

Example 4 with WithExpression

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

the class ExpressionTests method testWithExpressionNotEqual.

public void testWithExpressionNotEqual() throws Exception {
    WithExpression expression1 = new WithExpression("variable1");
    expression1.add(new InstanceofExpression(// $NON-NLS-1$
    "org.eclipse.core.internal.expressions.tests.Adapter1"));
    WithExpression expression2 = new WithExpression("variable2");
    expression2.add(new InstanceofExpression(// $NON-NLS-1$
    "org.eclipse.core.internal.expressions.tests.Adapter2"));
    assertTrue("These with expressions should not be equal", !expression1.equals(expression2));
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) WithExpression(org.eclipse.core.internal.expressions.WithExpression)

Example 5 with WithExpression

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

the class ExpressionTests method testWithExpressionUndefinedVariable.

public void testWithExpressionUndefinedVariable() throws Exception {
    WithExpression expr = new WithExpression("variable");
    expr.add(new EqualsExpression(new Object()));
    EvaluationContext context = new EvaluationContext(null, new Object());
    context.addVariable("variable", IEvaluationContext.UNDEFINED_VARIABLE);
    assertEquals(EvaluationResult.FALSE, expr.evaluate(context));
}
Also used : IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) WithExpression(org.eclipse.core.internal.expressions.WithExpression) EqualsExpression(org.eclipse.core.internal.expressions.EqualsExpression)

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