Search in sources :

Example 1 with EnablementExpression

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());
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression)

Example 2 with EnablementExpression

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));
}
Also used : InstanceofExpression(org.eclipse.core.internal.expressions.InstanceofExpression) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression)

Example 3 with EnablementExpression

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));
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 4 with EnablementExpression

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());
}
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) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) TestExpression(org.eclipse.core.internal.expressions.TestExpression) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 5 with EnablementExpression

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));
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) EnablementExpression(org.eclipse.core.internal.expressions.EnablementExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)5 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)3 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)2 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)2 CoreException (org.eclipse.core.runtime.CoreException)2 Expression (org.eclipse.core.expressions.Expression)1 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)1 AndExpression (org.eclipse.core.internal.expressions.AndExpression)1 CountExpression (org.eclipse.core.internal.expressions.CountExpression)1 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)1 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)1 NotExpression (org.eclipse.core.internal.expressions.NotExpression)1 OrExpression (org.eclipse.core.internal.expressions.OrExpression)1 ResolveExpression (org.eclipse.core.internal.expressions.ResolveExpression)1 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)1 TestExpression (org.eclipse.core.internal.expressions.TestExpression)1 WithExpression (org.eclipse.core.internal.expressions.WithExpression)1