use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testMultiTypeVarDeclr2.
public void testMultiTypeVarDeclr2() {
String ex = "String a = 'foo', b = 'baz', c = 'bar'";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
compiler.compile();
assertNotNull(ctx.getVariables());
assertEquals(3, ctx.getVariables().entrySet().size());
for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
assertEquals(String.class, entry.getValue());
}
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testDataConverterStrictMode.
public void testDataConverterStrictMode() throws Exception {
OptimizerFactory.setDefaultOptimizer("ASM");
DataConversion.addConversionHandler(Date.class, new MVELDateCoercion());
ParserContext ctx = new ParserContext();
ctx.addImport("Cheese", Cheese.class);
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
Locale.setDefault(Locale.US);
Cheese expectedCheese = new Cheese();
expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c", ctx);
Cheese actualCheese = (Cheese) executeExpression(compiler.compile(), createTestMap());
assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy());
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testStrongTyping.
public void testStrongTyping() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
new ExpressionCompiler("blah", ctx).compile();
} catch (Exception e) {
// should fail
return;
}
assertTrue(false);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testStrictTypingCompilation2.
public void testStrictTypingCompilation2() throws Exception {
ParserContext ctx = new ParserContext();
// noinspection RedundantArrayCreation
ctx.addImport("getRuntime", new MethodStub(Runtime.class.getMethod("getRuntime", new Class[] {})));
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("getRuntime()", ctx);
StaticMethodImportResolverFactory si = new StaticMethodImportResolverFactory(ctx);
Serializable expression = compiler.compile();
serializationTest(expression);
assertTrue(executeExpression(expression, si) instanceof Runtime);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testSetAccessorOverloadedEqualsStrictMode2.
public void testSetAccessorOverloadedEqualsStrictMode2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.aValue = 'bar'", ctx).compile();
} catch (CompileException e) {
assertTrue(false);
}
}
Aggregations