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);
}
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);
}
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());
}
}
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;
}
}
}
}
Aggregations