@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);
    }
  }
  @Override
  public KObject toKObject(final Path path) {
    KObject index = null;

    try {
      final String drl = ioService.readAllString(path);
      final DrlParser drlParser = new DrlParser();
      final PackageDescr packageDescr = drlParser.parse(true, drl);

      if (drlParser.hasErrors()) {
        final List<DroolsError> errors = drlParser.getErrors();
        logger.warn(
            ErrorMessageUtilities.makeErrorMessage(
                path, errors.toArray(new DroolsError[errors.size()])));
        return index;
      }
      if (packageDescr == null) {
        logger.warn(ErrorMessageUtilities.makeErrorMessage(path));
        return index;
      }

      final ProjectDataModelOracle dmo = getProjectDataModelOracle(path);
      final Project project = projectService.resolveProject(Paths.convert(path));
      final Package pkg = projectService.resolvePackage(Paths.convert(path));

      final DefaultIndexBuilder builder = new DefaultIndexBuilder(project, pkg);
      final PackageDescrIndexVisitor visitor =
          new PackageDescrIndexVisitor(dmo, builder, packageDescr);
      visitor.visit();

      index = KObjectUtil.toKObject(path, builder.build());

    } catch (Exception e) {
      logger.error("Unable to index '" + path.toUri().toString() + "'.", e);
    }

    return index;
  }