本文整理汇总了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);
}
示例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());
}
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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]));
}
示例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]));
}
示例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]);
}
示例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);
}
示例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());
}