use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class MvelDataTypeResolver method resolve.
/**
* Resolves expression data type
*
* @param value result of evaluating the expression on the given message
* @param event event under evaluation
* @param serializedExpression expression
* @return the data type corresponding to the given expression if there is an expression resolver able to resolved it. A default
* data type for the value if the expression was not resolved.
*/
public DataType resolve(Object value, PrivilegedEvent event, Serializable serializedExpression) {
DataType result = null;
if (serializedExpression instanceof CompiledExpression) {
CompiledExpression compiledExpression = (CompiledExpression) serializedExpression;
for (ExpressionDataTypeResolver resolver : resolvers) {
result = resolver.resolve(event, compiledExpression);
if (result != null) {
break;
}
}
}
if (result == null) {
Class<?> type = value == null ? Object.class : value.getClass();
result = DataType.fromType(type);
}
return result;
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedSessionProperty.
@Test
public void propagatesDataTypeForInlinedSessionProperty() throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent event = (PrivilegedEvent) testEvent();
event.getSession().setProperty("foo", "bar");
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getSession().getPropertyDataType("foo"), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class PropertyExpressionDataTypeResolverTestCase method returnsInlineFlowVarDataType.
@Test
public void returnsInlineFlowVarDataType() throws Exception {
final String expression = "foo";
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(TEST_MESSAGE)).addVariable("foo", EXPRESSION_VALUE, expectedDataType).build();
assertThat(expressionDataTypeResolver.resolve(testEvent, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class CoreConfidenceTests method testArray2.
public void testArray2() {
String ex = " TestHelper.method(1, {\"a\", \"b\"});\n" + " TestHelper.method(2, {new String(\"a\"), new String(\"b\")});\n" + " TestHelper.method(3, {new Fooz(\"a\"), new Fooz(\"b\")});";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport(TestHelper.class);
ctx.addImport(Fooz.class);
ExpressionCompiler compiler = new ExpressionCompiler(ex);
OptimizerFactory.setDefaultOptimizer("ASM");
CompiledExpression expr = compiler.compile(ctx);
executeExpression(expr);
OptimizerFactory.setDefaultOptimizer("reflective");
expr = compiler.compile(ctx);
executeExpression(expr);
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class CoreConfidenceTests method testSetAccessorOverloadedEqualsStrictMode.
public void testSetAccessorOverloadedEqualsStrictMode() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.bar = 0").compile(ctx);
} catch (CompileException e) {
// should fail.
e.printStackTrace();
return;
}
assertTrue(false);
}
Aggregations