Search in sources :

Example 1 with StaticMethodImportResolverFactory

use of org.mvel2.integration.impl.StaticMethodImportResolverFactory 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);
}
Also used : Serializable(java.io.Serializable) MethodStub(org.mvel2.util.MethodStub) StaticMethodImportResolverFactory(org.mvel2.integration.impl.StaticMethodImportResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 2 with StaticMethodImportResolverFactory

use of org.mvel2.integration.impl.StaticMethodImportResolverFactory in project mvel by mikebrock.

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()");
    StaticMethodImportResolverFactory si = new StaticMethodImportResolverFactory(ctx);
    Serializable expression = compiler.compile(ctx);
    serializationTest(expression);
    assertTrue(executeExpression(expression, si) instanceof Runtime);
}
Also used : Serializable(java.io.Serializable) MethodStub(org.mvel2.util.MethodStub) StaticMethodImportResolverFactory(org.mvel2.integration.impl.StaticMethodImportResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

Serializable (java.io.Serializable)2 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)2 StaticMethodImportResolverFactory (org.mvel2.integration.impl.StaticMethodImportResolverFactory)2 MethodStub (org.mvel2.util.MethodStub)2 ParserContext (org.mvel2.ParserContext)1