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


Java ParserContext.setSourceFile方法代码示例

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


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

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

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

示例3: testDebugSymbolsWithWindowsLinedEndings

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDebugSymbolsWithWindowsLinedEndings() throws Exception {
    String expr = "   System.out.println( \"a1\" );\r\n" +
            "   System.out.println( \"a2\" );\r\n" +
            "   System.out.println( \"a3\" );\r\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,代码行数:25,代码来源:DebuggerTests.java

示例4: testDebugSymbolsWithUnixLinedEndings

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDebugSymbolsWithUnixLinedEndings() throws Exception {
    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 ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ctx.setDebugSymbols(true);
    ctx.setSourceFile("mysource");

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

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

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

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

示例6: testDebuggerInvoke2

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDebuggerInvoke2() {
    count = 0;

    MVELRuntime.resetDebugger();
    MVELRuntime.setThreadDebugger(new Debugger() {
        public int onBreak(Frame frame) {
            count++;
            return 0;
        }
    });

    String src = "a1=7;\na2=8;\nSystem.out.println(\"h\");\nac=23;\nde=23;\nge=23;\ngef=34;";

    ExpressionCompiler c = new ExpressionCompiler(src);
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("mysource");
    ctx.setDebugSymbols(true);
    CompiledExpression compexpr = c.compile(ctx);

    System.out.println(decompile(compexpr));

    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 1);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 2);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 3);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 4);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 5);

    VariableResolverFactory factory = new DefaultLocalVariableResolverFactory();
    MVEL.executeDebugger(compexpr, null, factory);

    System.out.println(count);
    assertEquals(5, count);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:34,代码来源:DebuggerTests.java

示例7: testBreakpoints2

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpoints2() {
    ExpressionCompiler compiler = new ExpressionCompiler("System.out.println('test the debugger');\n a = 0;");

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

    CompiledExpression compiled = compiler.compile(ctx);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:10,代码来源:DebuggerTests.java

示例8: testBreakpointsAcrossWith

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpointsAcrossWith() {
    String line1 = "System.out.println( \"a1\" );\n";
    String line2 = "c = new Cheese();\n";
    String line3 = "with ( c ) { type = 'cheddar',\n" +
            "             price = 10 };\n";
    String line4 = "System.out.println( \"a1\" );\n";
    String expr = line1 + line2 + line3 + line4;

    System.out.println(expr);

    ExpressionCompiler compiler = new ExpressionCompiler(expr);

    ParserContext context = new ParserContext();
    context.addImport("System", System.class);
    context.addImport("Cheese", Cheese.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(5, count);

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

示例9: testBreakpointsAcrossComments

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpointsAcrossComments() {
    String expression = "/** This is a comment\n" +  // 1
            " *  Second comment line\n" +        // 2
            " *  Third Comment Line\n" +         // 3
            " */\n" +                         // 4
            "System.out.println('4');\n" +   // 5
            "System.out.println('5');\n" +   // 6
            "a = 0;\n" +                     // 7
            "b = 1;\n" +                    // 8
            "a + b";                        // 9

    ExpressionCompiler compiler = new ExpressionCompiler(expression);

    System.out.println("Expression:\n------------");
    System.out.println(expression);
    System.out.println("------------");

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

    CompiledExpression compiled = compiler.compile(ctx);

    MVELRuntime.registerBreakpoint("test2.mv", 9);

    Debugger testDebugger = new Debugger() {

        public int onBreak(Frame frame) {
            System.out.println("Breakpoint Encountered [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
            System.out.println("vars:" + frame.getFactory().getKnownVariables());
            System.out.println("Resume Execution");
            return 0;
        }

    };

    MVELRuntime.setThreadDebugger(testDebugger);

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

示例10: testBreakpointsAcrossComments2

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testBreakpointsAcrossComments2() {
    ExpressionCompiler compiler = new ExpressionCompiler(
            "// This is a comment\n" +                  // 1
                    "//Second comment line\n" +         // 2
                    "//Third Comment Line\n" +          // 3
                    "\n" +                              // 4
                    "//Test\n" +                        // 5
                    "System.out.println('4');\n" +      // 6
                    "//System.out.println('5'); \n" +    // 7
                    "a = 0;\n" +                        // 8
                    "b = 1;\n" +                        // 9
                    " a + b");                          // 10


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

    CompiledExpression compiled = compiler.compile(ctx);

    MVELRuntime.registerBreakpoint("test2.mv", 6);
    MVELRuntime.registerBreakpoint("test2.mv", 8);
    MVELRuntime.registerBreakpoint("test2.mv", 9);
    MVELRuntime.registerBreakpoint("test2.mv", 10);

    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(1, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:37,代码来源:DebuggerTests.java

示例11: testDebuggerInvoke

import org.mvel2.ParserContext; //导入方法依赖的package包/类
public void testDebuggerInvoke() {
    count = 0;

    MVELRuntime.resetDebugger();
    MVELRuntime.setThreadDebugger(new Debugger() {
        public int onBreak(Frame frame) {
            if (frame.getFactory().isResolveable("a1")) {
                a1++;
            }
            if (frame.getFactory().isResolveable("a4")) {
                a4++;
                System.out.println("HEI " + frame.getLineNumber());
            }
            count++;
            return 0;
        }
    });

    String src = "a1=7;\na2=8;\na3=9;\na4=10;\na5=11;\na6=12;\na7=13;\na8=14;";
    ExpressionCompiler c = new ExpressionCompiler(src);
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("mysource");
    ctx.setDebugSymbols(true);
    CompiledExpression compexpr = c.compile(ctx);

    System.out.println(decompile(compexpr));

    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 1);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 3);
    MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 7);

    VariableResolverFactory factory = new DefaultLocalVariableResolverFactory();
    MVEL.executeDebugger(compexpr, null, factory);

    System.out.println(a1);
    System.out.println(a4);
    System.out.println(count);
    assertEquals(2, a1);
    assertEquals(1, a4);   // test passes but the breakpoint should be received by line 7, not by line 3
    assertEquals(3, count); // three breakpoints FAILS
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:42,代码来源:DebuggerTests.java


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