use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class MutationsTests method testUnQualifiedStaticTyping.
public void testUnQualifiedStaticTyping() {
CompiledExpression ce = (CompiledExpression) compileExpression("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ");
assertEquals(new BigDecimal(20), testCompiledSimple("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ", new HashMap()));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL228.
public void testMVEL228() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
HashMap<String, Class> params = new HashMap<String, Class>();
params.put("helper", ScriptHelper228.class);
params.put("person", Person228.class);
ctx.setInputs(params);
String script = "helper.methodB(2);\n" + "person.getName2();";
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
} catch (Exception e) {
return;
}
fail("Should have thrown an exception");
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL234.
public void testMVEL234() {
StringBuffer buffer = new StringBuffer();
buffer.append("import java.text.SimpleDateFormat;");
buffer.append("if (\"test\".matches(\"[0-9]\")) {");
buffer.append(" return false;");
buffer.append("}else{");
buffer.append(" SimpleDateFormat sqf = new SimpleDateFormat(\"yyyyMMdd\");");
buffer.append("}");
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testDetermineEgressParametricType.
public final void testDetermineEgressParametricType() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("strings", List.class, new Class[] { String.class });
final CompiledExpression expr = new ExpressionCompiler("strings").compile(parserContext);
assertTrue(STRINGS.equals(executeExpression(expr, new A())));
final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
assertTrue(typeParameters != null);
assertTrue(String.class.equals(typeParameters[0]));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class DebuggerTests method testBreakpointsAcrossComments2.
public void testBreakpointsAcrossComments2() {
ExpressionCompiler compiler = new ExpressionCompiler(// 1
"// This is a comment\n" + // 2
"//Second comment line\n" + // 3
"//Third Comment Line\n" + // 4
"\n" + // 5
"//Test\n" + // 6
"System.out.println('4');\n" + // 7
"//System.out.println('5'); \n" + // 8
"a = 0;\n" + // 9
"b = 1;\n" + // 10
" a + b");
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
MVELRuntime.registerBreakpoint("test2.mv", 6);
MVELRuntime.registerBreakpoint("test2.mv", 8);
MVELRuntime.registerBreakpoint("test2.mv", 9);
MVELRuntime.registerBreakpoint("test2.mv", 10);
final Set<Integer> breaked = new HashSet<Integer>();
Debugger testDebugger = new Debugger() {
public int onBreak(Frame frame) {
System.out.println("Breakpoint [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
breaked.add(frame.getLineNumber());
return 0;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
assertEquals(1, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertEquals("did not break at expected lines", Make.Set.<Integer>$()._(6)._(8)._(9)._(10)._(), breaked);
}
Aggregations