All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.coverage.reporting.lineCoverage.LineCoverageFormatter Maven / Gradle / Ivy

Go to download

JMockit Coverage is a code coverage tool with several metrics (line, path, data) capable of generating HTML reports. It is designed with ease of use in mind, avoiding the need for complex configuration. Instead, smart (but overridable) defaults are employed, such as the selection of which classes to consider for coverage, and where to find sources files for report generation.

There is a newer version: 1.23
Show newest version
/*
 * Copyright (c) 2006-2013 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.coverage.reporting.lineCoverage;

import java.util.*;

import org.jetbrains.annotations.*;

import mockit.coverage.*;
import mockit.coverage.lines.*;
import mockit.coverage.reporting.*;
import mockit.coverage.reporting.parsing.*;

final class LineCoverageFormatter
{
   @NotNull private final StringBuilder formattedLine;
   @NotNull private final LineSegmentsFormatter segmentsFormatter;
   @Nullable private final ListOfCallPoints listOfCallPoints;

   LineCoverageFormatter(boolean withCallPoints)
   {
      formattedLine = new StringBuilder(200);
      segmentsFormatter = new LineSegmentsFormatter(withCallPoints, formattedLine);
      listOfCallPoints = withCallPoints ? new ListOfCallPoints() : null;
   }

   String format(@NotNull LineParser lineParser, @NotNull PerFileLineCoverage lineCoverageData)
   {
      formattedLine.setLength(0);
      formattedLine.append("
");
      segmentsFormatter.formatSegments(lineParser, lineData);
   }

   private void formatLineWithSingleSegment(@NotNull LineParser lineParser, @NotNull LineCoverageData lineData)
   {
      formattedLine.append(lineData.isCovered() ? " covered" : " uncovered");

      List callPoints = lineData.getCallPoints();
      boolean lineWithCallPoints = listOfCallPoints != null && callPoints != null;

      if (lineWithCallPoints) {
         formattedLine.append(" cp' onclick='showHide(this)");
      }

      formattedLine.append("' id='l").append(lineParser.getNumber()).append("s0'>");
      formattedLine.append(lineParser.getInitialElement().toString()).append("
"); if (lineWithCallPoints) { listOfCallPoints.insertListOfCallPoints(callPoints); formattedLine.append(listOfCallPoints.getContents()); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy