@Test public void testDebugSymbolCount() { 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.setDebugSymbols(true); context.addImport("System", System.class); context.setStrictTypeEnforcement(true); // context.setDebugSymbols( true ); context.setSourceFile("mysource"); Serializable compiledExpression = compiler.compile(context); String s = DebugTools.decompile(compiledExpression); System.out.println("s " + s); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(4, count); }
@Test public void testMVELDebugSymbols() throws DroolsParserException { MVELDebugHandler.setDebugMode(true); try { final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5); final PackageDescr pkgDescr = parser.parse(new InputStreamReader(getClass().getResourceAsStream("mvel_rule.drl"))); // just checking there is no parsing errors assertFalse(parser.getErrors().toString(), parser.hasErrors()); InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.drools"); final RuleDescr ruleDescr = pkgDescr.getRules().get(0); final RuleBuilder builder = new RuleBuilder(); final KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg); final KnowledgeBuilderConfigurationImpl conf = pkgBuilder.getBuilderConfiguration(); DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry(); Dialect dialect = dialectRegistry.getDialect("mvel"); RuleBuildContext context = new RuleBuildContext(pkgBuilder, ruleDescr, dialectRegistry, pkg, dialect); builder.build(context); assertTrue(context.getErrors().toString(), context.getErrors().isEmpty()); final RuleImpl rule = context.getRule(); MVELConsequence mvelCons = (MVELConsequence) rule.getConsequence(); mvelCons.compile( (MVELDialectRuntimeData) pkgBuilder .getPackageRegistry(pkg.getName()) .getDialectRuntimeRegistry() .getDialectData("mvel")); String s = DebugTools.decompile(mvelCons.getCompExpr()); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(4, count); } finally { MVELDebugHandler.setDebugMode(false); } }