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

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

/*
 * Copyright (c) 2006 JMockit developers
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.coverage.reporting.lineCoverage;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import java.util.List;

import mockit.coverage.CallPoint;
import mockit.coverage.lines.LineCoverageData;
import mockit.coverage.lines.PerFileLineCoverage;
import mockit.coverage.reporting.ListOfCallPoints;
import mockit.coverage.reporting.parsing.LineParser;

final class LineCoverageFormatter {
    @NonNull
    private final StringBuilder formattedLine;
    @NonNull
    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(@NonNull LineParser lineParser, @NonNull PerFileLineCoverage lineCoverageData) {
        formattedLine.setLength(0);
        formattedLine.append("
");
        segmentsFormatter.formatSegments(lineParser, lineData);
    }

    private void formatLineWithSingleSegment(@NonNull LineParser lineParser, @NonNull LineCoverageData lineData) {
        formattedLine.append(lineData.isCovered() ? " cvd" : " uncvd");

        List callPoints = lineData.getCallPoints();

        if (listOfCallPoints != null && callPoints != null) {
            formattedLine.append(" cp' onclick='sh(this)");
        }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy