Search in sources :

Example 51 with EvaluationContext

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

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

the class ExpressionTests method testIterateExpressionAndFalse.

public void testIterateExpressionAndFalse() throws Exception {
    final List<Object> result = new ArrayList<>();
    Expression myExpression = new Expression() {

        @Override
        public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
            result.add(context.getDefaultVariable());
            return EvaluationResult.FALSE;
        }
    };
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("and");
    exp.add(myExpression);
    List<String> input = new ArrayList<>();
    // $NON-NLS-1$
    input.add("one");
    // $NON-NLS-1$
    input.add("two");
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    // $NON-NLS-1$
    assertTrue(result.size() == 1 && result.get(0).equals("one"));
}
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) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 53 with EvaluationContext

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

the class ExpressionTests method testAdaptExpressionFail2.

public void testAdaptExpressionFail2() 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.NotExisting"));
    EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Adaptee()));
    assertTrue(result == EvaluationResult.FALSE);
}
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 54 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionAndTrue.

public void testIterateExpressionAndTrue() throws Exception {
    final List<Object> result = new ArrayList<>();
    Expression myExpression = new Expression() {

        @Override
        public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
            result.add(context.getDefaultVariable());
            return EvaluationResult.TRUE;
        }
    };
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("and");
    exp.add(myExpression);
    List<String> input = new ArrayList<>();
    // $NON-NLS-1$
    input.add("one");
    // $NON-NLS-1$
    input.add("two");
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    assertTrue(result.equals(input));
}
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) ArrayList(java.util.ArrayList) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 55 with EvaluationContext

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

the class ExpressionTests method testSystemProperty.

public void testSystemProperty() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$
    SystemTestExpression expression = new SystemTestExpression("os.name", System.getProperty("os.name"));
    EvaluationResult result = expression.evaluate(new EvaluationContext(null, new Object()));
    assertTrue(result == EvaluationResult.TRUE);
}
Also used : SystemTestExpression(org.eclipse.core.internal.expressions.SystemTestExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Aggregations

EvaluationContext (org.eclipse.core.expressions.EvaluationContext)71 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)56 ArrayList (java.util.ArrayList)26 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)22 CountExpression (org.eclipse.core.internal.expressions.CountExpression)14 InstanceofExpression (org.eclipse.core.internal.expressions.InstanceofExpression)13 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)12 Command (org.eclipse.core.commands.Command)11 WithExpression (org.eclipse.core.internal.expressions.WithExpression)11 ICommandService (org.eclipse.ui.commands.ICommandService)11 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)10 EqualsExpression (org.eclipse.core.internal.expressions.EqualsExpression)10 CoreException (org.eclipse.core.runtime.CoreException)10 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)9 TestExpression (org.eclipse.core.internal.expressions.TestExpression)9 IHandlerService (org.eclipse.ui.handlers.IHandlerService)9 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)8 Expression (org.eclipse.core.expressions.Expression)8 SystemTestExpression (org.eclipse.core.internal.expressions.SystemTestExpression)8 AndExpression (org.eclipse.core.internal.expressions.AndExpression)7