Search in sources :

Example 11 with ExecutableStatement

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

the class WithTests method testWithAndEnumInPackageImport.

public void testWithAndEnumInPackageImport() {
    ParserConfiguration pconf = new ParserConfiguration();
    pconf.addPackageImport(MyEnum.class.getPackage().getName());
    ParserContext pCtx = new ParserContext(pconf);
    pCtx.setStrongTyping(true);
    pCtx.addInput("thing", Thing.class);
    Thing thing = new Thing("xxx");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("thing", thing);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("with( thing ) { myEnum = MyEnum.FULL_DOCUMENTATION }", pCtx);
    MVEL.executeExpression(stmt, null, vars);
    assertEquals(MyEnum.FULL_DOCUMENTATION, thing.getMyEnum());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) ParserContext(org.mvel2.ParserContext) Thing(org.mvel2.tests.core.res.Thing) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 12 with ExecutableStatement

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

the class CoreConfidenceTests method testNestedNumInMapKey.

public void testNestedNumInMapKey() {
    String str = "objectKeyMaptributes[Triangle.Foo.OBTUSE]";
    ParserConfiguration pconf = new ParserConfiguration();
    pconf.addImport("Triangle", Triangle.class);
    ParserContext pctx = new ParserContext(pconf);
    pctx.addInput("this", Person.class);
    pctx.setStrongTyping(true);
    Foo foo = new Foo();
    Person p = new Person();
    Map<Object, Foo> map = new HashMap<Object, Foo>();
    map.put(Triangle.Foo.OBTUSE, foo);
    p.setObjectKeyMaptributes(map);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    Object o = MVEL.executeExpression(stmt, p, new HashMap());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 13 with ExecutableStatement

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

the class CoreConfidenceTests method testNestedClassWithNestedGenericsOnNakedMethod.

public void testNestedClassWithNestedGenericsOnNakedMethod() {
    String str = "deliveries.size";
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.addInput("this", Triangle.class);
    pctx.setStrongTyping(true);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    assertEquals(Integer.valueOf(0), (Integer) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
    str = "deliveries.size == 0";
    stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    assertTrue((Boolean) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
    MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement)

Example 14 with ExecutableStatement

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

the class ArraysTests method testArrayLength.

public void testArrayLength() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("x", String[].class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) ParserContext(org.mvel2.ParserContext)

Example 15 with ExecutableStatement

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

the class CoreConfidenceTests method testArrayLength.

//    public void testStaticImportWithWildcard() {
//        // this isn't supported yet
//        assertEquals("hello",
//                test("import_static " + getClass().getName() + ".StaticClassWithStaticMethod.*; getString()"));
//    }
public void testArrayLength() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);
    context.addInput("x", String[].class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context);
}
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