当前位置: 首页>>代码示例>>Java>>正文


Java ParserContext.setStrongTyping方法代码示例

本文整理汇总了Java中org.mvel2.ParserContext.setStrongTyping方法的典型用法代码示例。如果您正苦于以下问题:Java ParserContext.setStrongTyping方法的具体用法?Java ParserContext.setStrongTyping怎么用?Java ParserContext.setStrongTyping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mvel2.ParserContext的用法示例。


在下文中一共展示了ParserContext.setStrongTyping方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testQualifiedForLoop

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testQualifiedForLoop() {
    ParserContext pCtx = new ParserContext();
    pCtx.setStrongTyping(true);
    pCtx.addImport(Foo.class);
    pCtx.addInput("l", ArrayList.class, new Class[] { Foo.class });

    List l = new ArrayList();
    l.add(new Foo());
    l.add(new Foo());
    l.add(new Foo());

    Map vars = new HashMap();
    vars.put("l", l);

    Serializable s = MVEL.compileExpression("String s = ''; for (Foo f : l) { s += f.name }; s", pCtx);

    String r  = (String) MVEL.executeExpression(s, vars);

    assertEquals("dogdogdog", r);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:ControlFlowTests.java

示例2: testDebugSymbolsSingleStatement

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDebugSymbolsSingleStatement() {
    String ex = "System.out.println( Cheese.STILTON );";
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addImport( Cheese.class );
    try {
        ExpressionCompiler compiler = new ExpressionCompiler(ex);
        CompiledExpression expr = compiler.compile(ctx);

        // executing the following line with a MVEL.executeExpression() works fine
        // but executeDebugger() fails
        MVEL.executeDebugger( expr, null, (VariableResolverFactory)null );
    }
    catch (Throwable e) {
        e.printStackTrace();
        fail("Should not raise exception: " + e.getMessage());
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:DebuggerTests.java

示例3: testInlineWith5

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testInlineWith5() {
    OptimizerFactory.setDefaultOptimizer("ASM");

    ParserContext pCtx = new ParserContext();
    pCtx.setStrongTyping(true);

    pCtx.addInput("foo", Foo.class);

    CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile(pCtx);
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:14,代码来源:WithTests.java

示例4: testStrongTypingModeComparison

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testStrongTypingModeComparison() {
    ParserContext parserContext = new ParserContext();
    parserContext.setStrongTyping(true);
    parserContext.addInput("a", Long.class);

    CompiledExpression compiledExpression = new ExpressionCompiler("a==0").compile(parserContext);
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("a", 0l);
    MVEL.executeExpression(compiledExpression, variables);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:11,代码来源:ArithmeticTests.java

示例5: testJIRA161

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testJIRA161() {
    Serializable s = MVEL.compileExpression("1==-(-1)", ParserContext.create().stronglyTyped());
    assertEquals(1 == -(-1), MVEL.executeExpression(s));

    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    CompiledExpression compiledExpression = new ExpressionCompiler("1==-(-1)").compile(ctx);
    assertEquals(1 == -(-1), MVEL.executeExpression(compiledExpression));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:10,代码来源:ArithmeticTests.java

示例6: testShouldFail6

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testShouldFail6() {
    try {
        ParserContext pctx = new ParserContext();
        pctx.setStrongTyping(true);
        MVEL.compileExpression("new int[] {1.5}", pctx);
    }
    catch (Exception e) {
        return;
    }
    assertTrue(false);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:12,代码来源:FailureTests.java

示例7: testShouldFail7

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testShouldFail7() {
        try {
            ParserContext pctx = new ParserContext();
            pctx.setStrongTyping(true);
            MVEL.compileExpression("String x = 'foo'; int y = 2; new int[] { x, y }", pctx);
        }
        catch (Exception e) {
//            e.printStackTrace();
            return;
        }
        assertTrue(false);
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:13,代码来源:FailureTests.java

示例8: testShouldFail8

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testShouldFail8() {
    try {
        ParserContext pCtx = new ParserContext();
        pCtx.setStrongTyping(true);

        MVEL.compileExpression("for (String s : new java.util.HashMap()) { }", pCtx);
    }
    catch (Exception e) {
        //        e.printStackTrace();
        return;
    }

    assertTrue(false);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:15,代码来源:FailureTests.java

示例9: testInferLastTypeParametersFromProperty

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public final void testInferLastTypeParametersFromProperty() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);

    context.addInput("a", A.class);

    final CompiledExpression compiledExpression = new ExpressionCompiler("a.strings")
            .compile(context);

    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());

    assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
    assertTrue("No type parameters detected", null != context.getLastTypeParameters());
    assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:16,代码来源:GenericsTypeInferenceTest.java

示例10: testInferLastTypeParametersFromMethod

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public final void testInferLastTypeParametersFromMethod() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);

    context.addInput("a", A.class);

    final CompiledExpression compiledExpression = new ExpressionCompiler("a.values()")
            .compile(context);

    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());

    assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
    assertTrue("No type parameters detected", null != context.getLastTypeParameters());
    assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:16,代码来源:GenericsTypeInferenceTest.java

示例11: testInferLastTypeParametersFromPropertyMethod

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public final void testInferLastTypeParametersFromPropertyMethod() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);

    context.addInput("a", A.class);

    final CompiledExpression compiledExpression = new ExpressionCompiler("a.getFooMap()[\"key\"].someMethod()")
            .compile(context);

    final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());

    assertEquals("Expression did not evaluate correctly: ", "bar", val);
    assertNotNull("No type parameters detected", context.getLastTypeParameters());
    assertEquals("Wrong parametric type inferred", String.class, context.getLastTypeParameters()[0]);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:16,代码来源:GenericsTypeInferenceTest.java

示例12: testDeepAssignment2

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDeepAssignment2() {
    Map map = createTestMap();

    ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
    ParserContext ctx = new ParserContext();

    ctx.addInput("foo", Foo.class);
    ctx.setStrongTyping(true);

    CompiledExpression ce = compiler.compile(ctx);

    executeExpression(ce, map);

    assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:16,代码来源:MutationsTests.java

示例13: testTypeByMethod

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public final void testTypeByMethod() {
    ParserContext context = new ParserContext();
    context.setStrongTyping(true);

    context.addInput("a", A.class);

     CompiledExpression compiledExpression = new ExpressionCompiler("!a.show").compile(context);

    assertEquals(Boolean.class, compiledExpression.getKnownEgressType());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:11,代码来源:GenericsTypeInferenceTest.java


注:本文中的org.mvel2.ParserContext.setStrongTyping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。