Search in sources :

Example 11 with EvaluationContext

use of org.eclipse.core.expressions.EvaluationContext in project egit by eclipse.

the class SwitchToMenuTest method mockSelection.

private void mockSelection(ISelection selection) {
    EvaluationContext context = new EvaluationContext(null, new Object());
    context.addVariable(ISources.ACTIVE_MENU_SELECTION_NAME, selection);
    when(handlerService.getCurrentState()).thenReturn(context);
}
Also used : EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 12 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionWithAdapterManagerIfEmptyTrue.

public void testIterateExpressionWithAdapterManagerIfEmptyTrue() throws Exception {
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("or", "true");
    final List<String> input = new ArrayList<>();
    CollectionWrapper wrapper = new CollectionWrapper();
    wrapper.collection = input;
    EvaluationContext context = new EvaluationContext(null, wrapper);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 13 with EvaluationContext

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

the class ExpressionTests method testVariableResolver.

public void testVariableResolver() throws Exception {
    final Object result = new Object();
    IVariableResolver resolver = new IVariableResolver() {

        @Override
        public Object resolve(String name, Object[] args) throws CoreException {
            // $NON-NLS-1$
            assertEquals("variable", name);
            // $NON-NLS-1$
            assertEquals("arg1", args[0]);
            assertEquals(Boolean.TRUE, args[1]);
            return result;
        }
    };
    EvaluationContext context = new EvaluationContext(null, new Object(), new IVariableResolver[] { resolver });
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(result == context.resolveVariable("variable", new Object[] { "arg1", Boolean.TRUE }));
}
Also used : IVariableResolver(org.eclipse.core.expressions.IVariableResolver) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 14 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionOrFalse.

public void testIterateExpressionOrFalse() 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("or");
    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));
    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 15 with EvaluationContext

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

the class ExpressionTests method testIterateExpressionAnd_IfEmptyFalse.

public void testIterateExpressionAnd_IfEmptyFalse() throws Exception {
    // $NON-NLS-1$
    IterateExpression exp = new IterateExpression("and", "false");
    List<?> input = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, input);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) IterateExpression(org.eclipse.core.internal.expressions.IterateExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

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