Search in sources :

Example 41 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class WithTests method testInlineWith4.

public void testInlineWith4() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    ParserContext pCtx = new ParserContext();
    pCtx.addImport(Foo.class);
    ExpressionCompiler expr = new ExpressionCompiler("new Foo().{ name = 'bar' }", pCtx);
    CompiledExpression c = expr.compile();
    Foo f = (Foo) executeExpression(c);
    assertEquals("bar", f.getName());
    f = (Foo) executeExpression(c);
    assertEquals("bar", f.getName());
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 42 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class WithTests method testInlineWith3.

public void testInlineWith3() {
    CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}, toUC('doopy')}").compile();
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
    assertEquals("foobie", f.getBar().getName());
    assertEquals("doopy", f.register);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 43 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.

the class ArithmeticTests method testStrongTypingModeComparison.

public void testStrongTypingModeComparison() {
    ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("a", Long.class);
    CompiledExpression compiledExpression = new ExpressionCompiler("a==0", parserContext).compile();
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("a", 0l);
    MVEL.executeExpression(compiledExpression, variables);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 44 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.

the class AbstractVarAssignmentDataTypePropagatorTestCase method doAssignmentDataTypePropagationTest.

protected void doAssignmentDataTypePropagationTest(String expression) throws Exception {
    DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
    final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
    CompiledExpression compiledExpression = compileMelExpression(expression, (PrivilegedEvent) testEvent(), builder);
    PrivilegedEvent event = builder.build();
    dataTypePropagator.propagate(event, builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
    event = builder.build();
    assertThat(getVariableDataType(event), like(String.class, JSON, CUSTOM_ENCODING));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression)

Example 45 with CompiledExpression

use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.

the class AbstractVarExpressionDataTypeResolverTestCase method doVarDataTypeTest.

protected void doVarDataTypeTest(String expression) throws Exception {
    DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
    PrivilegedEvent event = setVariable((PrivilegedEvent) testEvent(), EXPRESSION_VALUE, expectedDataType);
    final ParserConfiguration parserConfiguration = MVELExpressionLanguage.createParserConfiguration(Collections.EMPTY_MAP);
    final MVELExpressionLanguageContext context = createMvelExpressionLanguageContext(event, parserConfiguration);
    CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(parserConfiguration));
    // Expression must be executed, otherwise the variable accessor is not properly configured
    MVEL.executeExpression(compiledExpression, context);
    assertThat(expressionDataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) DataType(org.mule.runtime.api.metadata.DataType) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) ParserConfiguration(org.mule.mvel2.ParserConfiguration)

Aggregations

CompiledExpression (org.mvel2.compiler.CompiledExpression)81 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)65 ParserContext (org.mvel2.ParserContext)48 HashMap (java.util.HashMap)20 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)20 Foo (org.mvel2.tests.core.res.Foo)20 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)15 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)14 DataType (org.mule.runtime.api.metadata.DataType)11 HashSet (java.util.HashSet)10 Test (org.junit.Test)9 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)9 ParserContext (org.mule.mvel2.ParserContext)8 Map (java.util.Map)6 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)6 CompileException (org.mvel2.CompileException)6 ASTNode (org.mvel2.ast.ASTNode)6 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)6