Search in sources :

Example 11 with EvaluationResult

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

the class ExpressionTests method testAdaptExpression.

public void testAdaptExpression() 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 Adaptee()));
    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 12 with EvaluationResult

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

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

the class PropertyTesterTests method testPluginActivation.

public void testPluginActivation() throws Exception {
    if (TEST_DYNAMIC_AND_ACTIVATION) {
        // $NON-NLS-1$
        Bundle bundle = Platform.getBundle("org.eclipse.core.expressions.tests.forceActivation");
        assertEquals(Bundle.STARTING, bundle.getState());
        A receiver = new A();
        TestExpression exp = new TestExpression("org.eclipse.core.expressions.tests.forceActivation", "testing", null, null, true);
        EvaluationContext context = new EvaluationContext(null, receiver);
        EvaluationResult result = exp.evaluate(context);
        assertEquals(EvaluationResult.NOT_LOADED, result);
        assertEquals(Bundle.STARTING, bundle.getState());
        // $NON-NLS-1$ //$NON-NLS-2$
        Property p = TestExpression.testGetTypeExtensionManager().getProperty(receiver, "org.eclipse.core.expressions.tests.forceActivation", "testing", false);
        assertTrue(!p.isInstantiated());
        context.setAllowPluginActivation(true);
        exp.evaluate(context);
        assertEquals(Bundle.ACTIVE, bundle.getState());
        // $NON-NLS-1$ //$NON-NLS-2$
        p = TestExpression.testGetTypeExtensionManager().getProperty(receiver, "org.eclipse.core.expressions.tests.forceActivation", "testing", false);
        assertTrue(p.isInstantiated());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TestExpression(org.eclipse.core.internal.expressions.TestExpression) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) Property(org.eclipse.core.internal.expressions.Property) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 14 with EvaluationResult

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

the class IterateExpression method evaluate.

/* (non-Javadoc)
	 * @see Expression#evaluate(IVariablePool)
	 */
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
    Object var = context.getDefaultVariable();
    if (var instanceof Collection) {
        Collection<?> col = (Collection<?>) var;
        switch(col.size()) {
            case 0:
                if (fEmptyResult == null) {
                    return fOperator == AND ? EvaluationResult.TRUE : EvaluationResult.FALSE;
                } else {
                    return fEmptyResult.booleanValue() ? EvaluationResult.TRUE : EvaluationResult.FALSE;
                }
            case 1:
                if (col instanceof List)
                    return evaluateAnd(new DefaultVariable(context, ((List<?>) col).get(0)));
            // $FALL-THROUGH$
            default:
                IteratePool iter = new IteratePool(context, col.iterator());
                EvaluationResult result = fOperator == AND ? EvaluationResult.TRUE : EvaluationResult.FALSE;
                while (iter.hasNext()) {
                    iter.next();
                    switch(fOperator) {
                        case OR:
                            result = result.or(evaluateAnd(iter));
                            if (result == EvaluationResult.TRUE)
                                return result;
                            break;
                        case AND:
                            result = result.and(evaluateAnd(iter));
                            if (result != EvaluationResult.TRUE)
                                return result;
                            break;
                    }
                }
                return result;
        }
    } else {
        IIterable<?> iterable = Expressions.getAsIIterable(var, this);
        if (iterable == null)
            return EvaluationResult.NOT_LOADED;
        int count = 0;
        IteratePool iter = new IteratePool(context, iterable.iterator());
        EvaluationResult result = fOperator == AND ? EvaluationResult.TRUE : EvaluationResult.FALSE;
        while (iter.hasNext()) {
            iter.next();
            count++;
            switch(fOperator) {
                case OR:
                    result = result.or(evaluateAnd(iter));
                    if (result == EvaluationResult.TRUE)
                        return result;
                    break;
                case AND:
                    result = result.and(evaluateAnd(iter));
                    if (result != EvaluationResult.TRUE)
                        return result;
                    break;
            }
        }
        if (count > 0) {
            return result;
        } else {
            if (fEmptyResult == null) {
                return fOperator == AND ? EvaluationResult.TRUE : EvaluationResult.FALSE;
            } else {
                return fEmptyResult.booleanValue() ? EvaluationResult.TRUE : EvaluationResult.FALSE;
            }
        }
    }
}
Also used : Collection(java.util.Collection) List(java.util.List) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Aggregations

EvaluationResult (org.eclipse.core.expressions.EvaluationResult)14 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)10 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)8 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)5 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)3 CoreException (org.eclipse.core.runtime.CoreException)3 Expression (org.eclipse.core.expressions.Expression)2 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)2 TestExpression (org.eclipse.core.internal.expressions.TestExpression)2 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CountExpression (org.eclipse.core.internal.expressions.CountExpression)1 Property (org.eclipse.core.internal.expressions.Property)1 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)1 WithExpression (org.eclipse.core.internal.expressions.WithExpression)1 IEvaluationService (org.eclipse.ui.services.IEvaluationService)1 Bundle (org.osgi.framework.Bundle)1