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


Java ParserContext类代码示例

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


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

示例1: shouldApplyFeeToFulfillmentGroup

import org.mvel2.ParserContext; //导入依赖的package包/类
/**
 * If the SkuFee expression is null or empty, this method will always return true
 * 
 * @param fee
 * @param fulfillmentGroup
 * @return
 */
protected boolean shouldApplyFeeToFulfillmentGroup(SkuFee fee, FulfillmentGroup fulfillmentGroup) {
    boolean appliesToFulfillmentGroup = true;
    String feeExpression = fee.getExpression();
    
    if (!StringUtils.isEmpty(feeExpression)) {
        Serializable exp = (Serializable) EXPRESSION_CACHE.get(feeExpression);
        if (exp == null) {
            ParserContext mvelContext = new ParserContext();
            mvelContext.addImport("MVEL", MVEL.class);
            mvelContext.addImport("MvelHelper", MvelHelper.class);
            exp = MVEL.compileExpression(feeExpression, mvelContext);
        
            EXPRESSION_CACHE.put(feeExpression, exp);
        }
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("fulfillmentGroup", fulfillmentGroup);
        return (Boolean)MVEL.executeExpression(feeExpression, vars);
    }
    
    return appliesToFulfillmentGroup;
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:29,代码来源:ConsolidateFulfillmentFeesActivity.java

示例2: testJIRA164f

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testJIRA164f() {
    Serializable s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());

    s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:ArithmeticTests.java

示例3: testJIRA164

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testJIRA164() {
    Serializable s = MVEL.compileExpression("1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();
    double var1 = 1d;

    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 / (var1 + var1) * var1", ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例4: testBreakpoints3

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testBreakpoints3() {
    String expr = "System.out.println( \"a1\" );\n" +
            "System.out.println( \"a2\" );\n" +
            "System.out.println( \"a3\" );\n" +
            "System.out.println( \"a4\" );\n";

    ExpressionCompiler compiler = new ExpressionCompiler(expr);

    ParserContext context = new ParserContext();
    context.addImport("System", System.class);
    context.setStrictTypeEnforcement(true);
    context.setDebugSymbols(true);
    context.setSourceFile("mysource");

    String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));

    System.out.println("output: " + s);

    int fromIndex = 0;
    int count = 0;
    while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
        count++;
    }
    assertEquals(4, count);

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:27,代码来源:DebuggerTests.java

示例5: testJIRA164b

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testJIRA164b() {
    Serializable s = MVEL.compileExpression("1 + 1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 / (var1 + var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例6: getClassReference

import org.mvel2.ParserContext; //导入依赖的package包/类
public static Class getClassReference(ParserContext ctx, TypeDescriptor tDescr) throws ClassNotFoundException {
    Class cls;
    if (ctx != null && ctx.hasImport(tDescr.className)) {
        cls = ctx.getImport(tDescr.className);
        if (tDescr.isArray()) {
            cls = findClass(null, repeatChar('[', tDescr.arraySize.length) + "L" + cls.getName() + ";", ctx);
        }
    }
    else if (ctx == null && hasContextFreeImport(tDescr.className)) {
        cls = getContextFreeImport(tDescr.className);
        if (tDescr.isArray()) {
            cls = findClass(null, repeatChar('[', tDescr.arraySize.length) + "L" + cls.getName() + ";", ctx);
        }
    }
    else {
        cls = createClass(tDescr.getClassName(), ctx);
        if (tDescr.isArray()) {
            cls = findClass(null, repeatChar('[', tDescr.arraySize.length) + "L" + cls.getName() + ";", ctx);
        }
    }

    return cls;
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:24,代码来源:TypeDescriptor.java

示例7: testBreakpoints

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testBreakpoints() {
    ExpressionCompiler compiler = new ExpressionCompiler("a = 5;\nb = 5;\n\nif (a == b) {\n\nSystem.out.println('Good');\nreturn a + b;\n}\n");
    System.out.println("-------\n" + compiler.getExpression() + "\n-------\n");

    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);

    CompiledExpression compiled = compiler.compile(ctx);

    MVELRuntime.registerBreakpoint("test.mv", 7);

    Debugger testDebugger = new Debugger() {
        public int onBreak(Frame frame) {
            System.out.println("Breakpoint [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");

            return 0;
        }
    };

    MVELRuntime.setThreadDebugger(testDebugger);

    assertEquals(10, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:25,代码来源:DebuggerTests.java

示例8: ProtoVarNode

import org.mvel2.ParserContext; //导入依赖的package包/类
public ProtoVarNode(char[] expr, int fields, Proto type, ParserContext pCtx) {
    this.egressType = Proto.ProtoInstance.class;
    this.fields = fields;

    int assignStart;
    if ((assignStart = find(super.name = expr, '=')) != -1) {
        checkNameSafety(name = createStringTrimmed(expr, 0, assignStart));

        if (((fields |= ASSIGN) & COMPILE_IMMEDIATE) != 0) {
            statement = (ExecutableStatement) subCompileExpression(stmt = subset(expr, assignStart + 1), pCtx);
        }
        else {
            stmt = subset(expr, assignStart + 1);
        }
    }
    else {
        checkNameSafety(name = new String(expr));
    }

    if ((fields & COMPILE_IMMEDIATE) != 0) {
        pCtx.addVariable(name, egressType, true);
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:24,代码来源:ProtoVarNode.java

示例9: testJIRA164d

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testJIRA164d() {
    Serializable s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例10: RegExMatch

import org.mvel2.ParserContext; //导入依赖的package包/类
public RegExMatch(char[] expr, int fields, char[] pattern, ParserContext pCtx) {
    this.name = expr;
    this.pattern = pattern;

    if ((fields & COMPILE_IMMEDIATE) != 0) {
        this.stmt = (ExecutableStatement) subCompileExpression(expr);
        if ((this.patternStmt = (ExecutableStatement)
                subCompileExpression(pattern, pCtx)) instanceof ExecutableLiteral) {

            try {
                p = compile(valueOf(patternStmt.getValue(null, null)));
            }
            catch (PatternSyntaxException e) {
                throw new CompileException("bad regular expression", e);
            }
        }
    }
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:RegExMatch.java

示例11: testDebugSymbolsWithMixedLinedEndings

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testDebugSymbolsWithMixedLinedEndings() throws Exception {
    String expr = "   System.out.println( \"a1\" );\n" +
            "   System.out.println( \"a2\" );\r\n" +
            "   System.out.println( \"a3\" );\n" +
            "   System.out.println( \"a4\" );\r\n";

    ExpressionCompiler compiler = new ExpressionCompiler(expr);

    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ctx.setDebugSymbols(true);
    ctx.setSourceFile("mysource");

    String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(ctx));

    System.out.println(s);

    int fromIndex = 0;
    int count = 0;
    while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
        count++;
    }
    assertEquals(4, count);

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:26,代码来源:DebuggerTests.java

示例12: testJIRA164c

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testJIRA164c() {
    Serializable s = MVEL.compileExpression("1 + 1 / (var1 + var1 + 2 + 3) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 / (var1 + var1 + 2 + 3) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 / (var1 + var1 + 2 + 3) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 / (var1 + var1 + 2 + 3) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例13: 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

示例14: testMVELCompilerBoth2

import org.mvel2.ParserContext; //导入依赖的package包/类
public void testMVELCompilerBoth2() {
    PropertyHandlerFactory.registerPropertyHandler(DynaBean.class, new DynaBeanPropertyHandler());

    Map<String, Object> vars = new LinkedHashMap<String, Object>();

    ParserContext parserContext = new ParserContext();
    Object compiled = MVEL.compileExpression("attr.value", parserContext);

    DynaBean dyna = new LazyDynaBean();
    dyna.set("value", "value2");
    vars.put("attr", dyna);
    assertEquals("value2", MVEL.executeExpression(compiled, null, vars));

    TestBean bean = new TestBean("value1");
    vars.put("attr", bean);
    assertEquals("value1", MVEL.executeExpression(compiled, null, vars));

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:PropertyAccessTests.java

示例15: 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


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