code: private void addAttribute(Rule rule, String newAttribute, List<String> xmlLines) {
      List<Integer> linesToModify = new ArrayList<>();
      String currentRuleId = null;
      Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*");
      String expectedSubId = ((AbstractPatternRule) rule).getSubId();
      int lineCount = 0;
      int subRuleCount = 0;
      int modifyCount = 0;
      boolean inRuleGroup = false;
      for (String xmlLine : xmlLines) {
        if (xmlLine.contains("<rulegroup")) {
          subRuleCount = 0;
          inRuleGroup = true;
        } else if (xmlLine.contains("</rulegroup>")) {
          subRuleCount = 0;
          inRuleGroup = false;
        } else if ((xmlLine.contains("<rule ")||xmlLine.contains("<rule>")) && inRuleGroup) {
          subRuleCount++;
        }
        Matcher m = pattern.matcher(xmlLine);
        if (m.matches()) {
          currentRuleId = m.group(1);
        }
        if (xmlLine.contains("type=\"incorrect\"") || xmlLine.contains("type='incorrect'")) {
          if (currentRuleId != null && !currentRuleId.equals(rule.getId())) {
            lineCount++;
            continue;
          }
          if (!inRuleGroup) {
            subRuleCount = 1;
          }
          if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) {
            lineCount++;
            continue;
          }
          linesToModify.add(lineCount);
          break;
        }
        lineCount++;
      }
      for (Integer s : linesToModify) {
        String newLine = xmlLines.get(s).replaceFirst("type=[\"']incorrect[\"']", newAttribute);
        xmlLines.set(s, newLine);
        addedCorrectionsCount++;
        modifyCount++;
      }
      if (modifyCount == 0) {
        System.err.println("No line modified: " + rule + "[" + expectedSubId + "]");
      }
    }
docs: Note: this is a bad hack, we just iterate through the file's lines