org.mvel2.MVEL.analyze()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中org.mvel2.MVEL.analyze()方法的一些代码示例,展示了MVEL.analyze()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MVEL.analyze()方法的具体详情如下:
包路径:org.mvel2.MVEL
类名称:MVEL
方法名:analyze

MVEL.analyze介绍

暂无

代码示例

代码示例来源:origin: org.mvel/mvel2

public static Class analyze(String expression, ParserContext ctx) {
 return analyze(expression.toCharArray(), ctx);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.mvel

public static Class analyze(String expression, ParserContext ctx) {
  return analyze(expression.toCharArray(), ctx);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public static Class analyze(String expression, ParserContext ctx) {
 return analyze(expression.toCharArray(), ctx);
}

代码示例来源:origin: org.mvel/mvel2

public void testReturnTypeExtendingGeneric() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrongTyping(true);
 parserContext.addInput("this", StringConcrete.class);
 assertEquals(String.class, MVEL.analyze("foo.concat(\"bar\")", parserContext));
 assertEquals(String.class, MVEL.analyze("getFoo().concat(\"bar\")", parserContext));
}

代码示例来源:origin: org.mvel/mvel2

public void testVarArgs() throws Exception {
 ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 MVEL.analyze("String.format(\"\");", parserContext);
}

代码示例来源:origin: org.mvel/mvel2

public void testPippo() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrongTyping(true);
 assertEquals(String.class, MVEL.analyze("new String(\"b)ar\")", parserContext));
}

代码示例来源:origin: org.mvel/mvel2

public void testTypeCalculation() {
 ParserContext ctx = ParserContext.create().stronglyTyped();
 ctx.addInput("foo", Foo.class);
 Class cls = MVEL.analyze("foo.bar.testList.get(0)", ctx);
 assertTrue(Integer.class.isAssignableFrom(cls));
}

代码示例来源:origin: org.mvel/mvel2

public void testNoArgMethodInheritance() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("a", Parent.class);
 parserContext.addInput("b", Child.class);
 assertEquals(Object.class, MVEL.analyze("a.getSomething()", parserContext));
 assertEquals(String.class, MVEL.analyze("b.getSomething()", parserContext));
}

代码示例来源:origin: org.mvel/mvel2

public void testRegExWithCast() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrongTyping(true);
 parserContext.addInput("this", Foo.class);
 assertEquals(Boolean.class, MVEL.analyze("(String)bar.name ~= '[a-z].+'", parserContext));
}

代码示例来源:origin: org.mvel/mvel2

public void testUppercaseField() {
 String ex = "Field1 == \"foo\" || FIELD2 == \"bar\"";
 final ParserContext parserContext2 = new ParserContext();
 parserContext2.setStrictTypeEnforcement(true);
 parserContext2.setStrongTyping(true);
 parserContext2.addInput("this", Bean1.class);
 MVEL.analyze(ex, parserContext2);
}

代码示例来源:origin: org.mvel/mvel2

public void testUntypedClone() {
 String expression = "obj.clone();";
 ParserContext context = new ParserContext();
 context.setStrongTyping(false);
 context.setStrictTypeEnforcement(false);
 MVEL.analyze(expression, context);
 try {
  context.addInput("obj", Object.class);
  context.setStrongTyping(true);
  context.setStrictTypeEnforcement(true);
  MVEL.analyze(expression, context);
  fail("Must fail with strong typing");
 }
 catch (CompileException e) {
 }
}

代码示例来源:origin: org.mvel/mvel2

public void testParseGenericMap() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("conv", Convention.class);
 assertEquals(List.class, MVEL.analyze("conv.getComms().get(\"test\")", parserContext));
}

代码示例来源:origin: org.mvel/mvel2

private Class<?> expressionReturnType(String expr) {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("this", Bean1.class);
 MVEL.compileExpression(expr, parserContext);
 return MVEL.analyze(expr, parserContext);
}

代码示例来源:origin: org.mvel/mvel2

public void testMethodReturningPrimitiveTypeAnalysis() {
 String str = "value";
 ParserConfiguration pconf = new ParserConfiguration();
 ParserContext pctx = new ParserContext(pconf);
 pctx.addInput("this", MyObj.class);
 pctx.setStrongTyping(true);
 Class<?> returnType = MVEL.analyze(str, pctx);
 assertEquals(long.class, returnType);
}

代码示例来源:origin: org.mvel/mvel2

public void testPrimitiveNumberCoercion() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("a", int.class);
 parserContext.addInput("b", double.class);
 Class<?> clazz = MVEL.analyze("a > b", parserContext);
 assertEquals(Boolean.class, clazz);
}

代码示例来源:origin: org.mvel/mvel2

public void testGenericsWithOr() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("o", OrderLine.class);
 parserContext.addInput("p", Product.class);
 Class<?> clazz = MVEL.analyze("p.id == o.product.id || p.category == o.product.category", parserContext);
 assertEquals(Boolean.class, clazz);
}

代码示例来源:origin: org.mvel/mvel2

public void testAnalyzeTernary() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("value", String.class);
 parserContext.addInput("x", Integer.class);
 parserContext.addInput("y", Integer.class);
 parserContext.addInput("z", Integer.class);
 Class<?> clazz = MVEL.analyze("z = (value == \"ALU\" ? x : y);", parserContext);
 assertEquals(Integer.class, clazz);
}

代码示例来源:origin: org.mvel/mvel2

public void testAnalyzeWrongTernary() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("value", String.class);
 parserContext.addInput("x", Integer.class);
 parserContext.addInput("y", Integer.class);
 parserContext.addInput("z", Integer.class);
 try {
  Class<?> clazz = MVEL.analyze( "z = (value = \"ALU\" ? x : y);", parserContext );
  fail("parse of this expression should raise an error");
 } catch (Exception e) { }
}

代码示例来源:origin: org.mvel/mvel2

public void testCovariance() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("this", ImplementationA.class);
 assertEquals(int.class, MVEL.analyze("b.value", parserContext));
 assertEquals(42, MVEL.executeExpression(MVEL.compileExpression("b.value", parserContext), new ImplementationA()));
}

代码示例来源:origin: org.mvel/mvel2

public void testInvokeMethodInAbstractClass() {
 final ParserContext parserContext = new ParserContext();
 parserContext.setStrictTypeEnforcement(true);
 parserContext.setStrongTyping(true);
 parserContext.addInput("a", O1.class);
 assertEquals(String.class, MVEL.analyze("a.getObj().getValue()", parserContext));
 Map vars = new HashMap() {{ put("a", new O1()); }};
 assertEquals("value", MVEL.executeExpression(MVEL.compileExpression("a.getObj().getValue()", parserContext), vars));
}

相关文章