use of org.eclipse.core.internal.expressions.EnablementExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testEnablementExpressionHashCode.
public void testEnablementExpressionHashCode() throws Exception {
EnablementExpression expression1 = new EnablementExpression((IConfigurationElement) null);
expression1.add(new InstanceofExpression(// $NON-NLS-1$
"org.eclipse.core.internal.expressions.tests.Adapter"));
EnablementExpression expression2 = new EnablementExpression((IConfigurationElement) null);
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());
}
use of org.eclipse.core.internal.expressions.EnablementExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testEnablementExpressionNotEqual.
public void testEnablementExpressionNotEqual() throws Exception {
EnablementExpression expression1 = new EnablementExpression((IConfigurationElement) null);
expression1.add(new InstanceofExpression(// $NON-NLS-1$
"org.eclipse.core.internal.expressions.tests.Adapter1"));
EnablementExpression expression2 = new EnablementExpression((IConfigurationElement) null);
expression2.add(new InstanceofExpression(// $NON-NLS-1$
"org.eclipse.core.internal.expressions.tests.Adapter2"));
assertTrue("These enablement expressions should not be equal", !expression1.equals(expression2));
}
use of org.eclipse.core.internal.expressions.EnablementExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testReferenceExpression.
public void testReferenceExpression() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement enable = findExtension(ces, "refTest1").getChildren("enablement")[0];
EnablementExpression probExpr = (EnablementExpression) ExpressionConverter.getDefault().perform(enable);
EvaluationContext context = new EvaluationContext(null, Collections.EMPTY_LIST);
try {
probExpr.evaluate(context);
fail("Should report error with no variable");
} catch (CoreException e) {
// correct, throw exception
}
context.addVariable("activePartId", "org.eclipse.ui.views.TasksView");
assertEquals(EvaluationResult.FALSE, probExpr.evaluate(context));
context.addVariable("activePartId", "org.eclipse.ui.views.ProblemsView");
assertEquals(EvaluationResult.TRUE, probExpr.evaluate(context));
}
use of org.eclipse.core.internal.expressions.EnablementExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testForcePluginActivation.
public void testForcePluginActivation() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement enable = findExtension(ces, "test2").getChildren("enablement")[0];
EnablementExpression exp = (EnablementExpression) ExpressionConverter.getDefault().perform(enable);
Expression[] children = exp.getChildren();
assertTrue(children.length == 3);
TestExpression test = (TestExpression) children[0];
assertTrue(test.testGetForcePluginActivation());
test = (TestExpression) children[1];
assertTrue(!test.testGetForcePluginActivation());
test = (TestExpression) children[2];
assertTrue(!test.testGetForcePluginActivation());
}
use of org.eclipse.core.internal.expressions.EnablementExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testTwoReferences.
public void testTwoReferences() throws Exception {
IExtensionRegistry registry = Platform.getExtensionRegistry();
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement[] ces = registry.getConfigurationElementsFor("org.eclipse.core.expressions.tests", "testParticipants");
// $NON-NLS-1$ //$NON-NLS-2$
IConfigurationElement enable = findExtension(ces, "refTest2").getChildren("enablement")[0];
EnablementExpression probExpr = (EnablementExpression) ExpressionConverter.getDefault().perform(enable);
EvaluationContext context = new EvaluationContext(null, Collections.EMPTY_LIST);
try {
probExpr.evaluate(context);
fail("Should report error with no variable");
} catch (CoreException e) {
// correct, throw exception
}
context.addVariable("activePartId", "org.eclipse.ui.views.TasksView");
assertEquals(EvaluationResult.FALSE, probExpr.evaluate(context));
context.addVariable("activePartId", "org.eclipse.ui.views.ProblemsView");
// we still have no selection in the default variable
assertEquals(EvaluationResult.FALSE, probExpr.evaluate(context));
context = new EvaluationContext(context, Collections.singletonList(probExpr));
assertEquals(EvaluationResult.TRUE, probExpr.evaluate(context));
}
Aggregations