コード例 #1
0
  private void collectRangeMeasures(
      SMInputCursor function,
      Map<String, CoverageMeasuresBuilder> coverageData,
      int conditions,
      int coveredConditions)
      throws XMLStreamException {
    SMInputCursor range =
        function.childElementCursor("ranges").advance().childElementCursor("range");
    CoverageMeasuresBuilder builder = null;
    String lastSourceId = "";

    while (range.getNext() != null) {
      String sourceId = range.getAttrValue("source_id");
      int startLine = Integer.parseInt(range.getAttrValue("start_line"));
      int endLine = Integer.parseInt(range.getAttrValue("end_line"));
      int covered =
          !"no".equalsIgnoreCase(range.getAttrValue("covered")) ? 1 : 0; // value: yes/no/partial

      if (!sourceId.equals(lastSourceId) || builder == null) {
        builder = coverageData.get(sourceId);
        if (builder == null) {
          builder = CoverageMeasuresBuilder.create();
          coverageData.put(sourceId, builder);
        }

        builder.setConditions(startLine - 1, conditions, coveredConditions);
        lastSourceId = sourceId;
      }

      while (startLine <= endLine) {
        builder.setHits(startLine, covered);
        startLine++;
      }
    }
  }
コード例 #2
0
  private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder)
      throws XMLStreamException {
    SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
    while (line.getNext() != null) {
      int lineId = Integer.parseInt(line.getAttrValue("number"));
      try {
        builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
      } catch (ParseException e) {
        throw new XmlParserException(e);
      }

      String isBranch = line.getAttrValue("branch");
      String text = line.getAttrValue("condition-coverage");
      if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) {
        String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/");
        builder.setConditions(
            lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0]));
      }
    }
  }
コード例 #3
0
 private static void collectFileMeasures(
     SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename)
     throws XMLStreamException {
   while (clazz.getNext() != null) {
     String fileName = clazz.getAttrValue("filename");
     CoverageMeasuresBuilder builder = builderByFilename.get(fileName);
     if (builder == null) {
       builder = CoverageMeasuresBuilder.create();
       builderByFilename.put(fileName, builder);
     }
     collectFileData(clazz, builder);
   }
 }