use of org.mvel2.asm.Type in project mvel by mikebrock.
the class CoreConfidenceTests method testStrictModeAddAll.
public void testStrictModeAddAll() {
String str = "list.addAll( o );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("o", Object.class);
pctx.addInput("list", ArrayList.class);
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
fail("This should not compileShared, as o is not of a type Collection");
} catch (Exception e) {
}
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class DebuggerTests method testBreakpointsAcrossWith.
public void testBreakpointsAcrossWith() {
String line1 = "System.out.println( \"a1\" );\n";
String line2 = "c = new Cheese();\n";
String line3 = "with ( c ) { type = 'cheddar',\n" + " price = 10 };\n";
String line4 = "System.out.println( \"a1\" );\n";
String expr = line1 + line2 + line3 + line4;
System.out.println(expr);
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.addImport("Cheese", Cheese.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(5, count);
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class TypesAndInferenceTests method testForLoopTypeCoercion.
public void testForLoopTypeCoercion() {
ParserContext pCtx = ParserContext.create();
pCtx.setStrongTyping(true);
pCtx.addInput("$type", String.class);
pCtx.addInput("l", List.class);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$type", "pc!!");
List list = new ArrayList();
vars.put("l", list);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("for (byte bt:$type.getBytes()) {l.add( bt);}", pCtx);
MVEL.executeExpression(stmt, null, vars);
byte[] exp = "pc!!".getBytes();
for (int i = 0; i < exp.length; i++) {
assertEquals(exp[i], list.get(i));
}
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class TypesAndInferenceTests method testEgressTypeCorrect.
public void testEgressTypeCorrect() {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("type", ParserContext.create().stronglyTyped().withInput("this", Cheese.class));
assertEquals(String.class, stmt.getKnownEgressType());
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
Aggregations