Search in sources :

Example 31 with ExecutableStatement

use of org.mvel2.compiler.ExecutableStatement 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());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 32 with ExecutableStatement

use of org.mvel2.compiler.ExecutableStatement 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());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 33 with ExecutableStatement

use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.

the class TypesAndInferenceTests method testGenerics1.

public void testGenerics1() {
    String str = "addresses[0] == new Address(\"s1\") && addresses[0].street == new Address(\"s1\").street";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("this", PersonAddresses.class);
    pctx.addImport(Address.class);
    pctx.addImport(PersonAddresses.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    PersonAddresses ctx = new PersonAddresses();
    ctx.getAddresses().add(new Address("s1"));
    Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
    assertTrue(result);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 34 with ExecutableStatement

use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.

the class TypesAndInferenceTests method testEgressTypeCorrect2.

public void testEgressTypeCorrect2() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("this", SampleBean.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("( map2[ 'yyy' ] )", context);
    SampleBean s = new SampleBean();
    s.getMap2().put("yyy", 1);
    assertEquals(new Integer(1), MVEL.executeExpression(stmt, s));
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 35 with ExecutableStatement

use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.

the class TypesAndInferenceTests method testContextMethodCallsInStrongMode.

public void testContextMethodCallsInStrongMode() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("this", EchoContext.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("this.echo( 'Mac')", context);
    stmt = (ExecutableStatement) MVEL.compileExpression("echo( 'Mac')", context);
    assertEquals("Mac", MVEL.executeExpression(stmt, new EchoContext()));
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Aggregations

ExecutableStatement (org.mvel2.compiler.ExecutableStatement)25 IOException (java.io.IOException)6 ParserContext (org.mvel2.ParserContext)6 List (java.util.List)5 Map (java.util.Map)5 CompileException (org.mvel2.CompileException)4 TypeDescriptor (org.mvel2.ast.TypeDescriptor)4 ArrayList (java.util.ArrayList)3 ParserConfiguration (org.mvel2.ParserConfiguration)3 WeakHashMap (java.util.WeakHashMap)2 Union (org.mvel2.optimizers.impl.refl.nodes.Union)2 PropertyTools.getFieldOrAccessor (org.mvel2.util.PropertyTools.getFieldOrAccessor)2 PropertyTools.getFieldOrWriteAccessor (org.mvel2.util.PropertyTools.getFieldOrWriteAccessor)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Label (org.mvel2.asm.Label)1 MethodVisitor (org.mvel2.asm.MethodVisitor)1 EndOfStatement (org.mvel2.ast.EndOfStatement)1 Function (org.mvel2.ast.Function)1 Proto (org.mvel2.ast.Proto)1