ClassColumn.java

    1/*******************************************************************************
    2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
    3 * All rights reserved. This program and the accompanying materials
    4 * are made available under the terms of the Eclipse Public License v1.0
    5 * which accompanies this distribution, and is available at
    6 * http://www.eclipse.org/legal/epl-v10.html
    7 *
    8 * Contributors:
    9 *    Brock Janiczak - initial API and implementation
   10 *    
   11 * $Id: $
   12 *******************************************************************************/
   13package org.jacoco.report.csv;
   14
   15import java.io.IOException;
   16
   17import org.jacoco.core.analysis.ClassCoverage;
   18import org.jacoco.core.analysis.ICounter;
   19import org.jacoco.core.analysis.ICoverageNode;
   20import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
   21import org.jacoco.core.analysis.ICoverageNode.ElementType;
   22import org.jacoco.report.ILanguageNames;
   23import org.jacoco.report.IReportVisitor;
   24import org.jacoco.report.ISourceFileLocator;
   25
   26/**
   27 * Columns containing the following values for the class:
   28 * <ol>
   29 * <li>Class Name</li>
   30 * <li>Methods Covered</li>
   31 * <li>Methods Not Covered</li>
   32 * <li>Blocks Covered</li>
   33 * <li>Blocks Not Covered</li>
   34 * <li>Lines Covered</li>
   35 * <li>Lines Not Covered</li>
   36 * <li>Instructions Covered</li>
   37 * <li>Instructions Not Covered</li>
   38 * </ol>
   39 * 
   40 * @author Brock Janiczak
   41 * @version $Revision: $
   42 */
   43public class ClassColumn implements IReportVisitor, ICsvColumn {
   44
   45    private final ICsvColumn parent;
   46
   47    private final ClassCoverage node;
   48
   49    private final CsvReportFile reportFile;
   50
   51    /**
   52     * Creates a new Class Column for the report
   53     * 
   54     * @param reportFile
   55     *            CSV Report context
   56     * @param parent
   57     *            parent element
   58     * @param node
   59     *            {@link ElementType#CLASS} coverage node
   60     */
   61    public ClassColumn(final CsvReportFile reportFile, final ICsvColumn parent,
   62            final ClassCoverage node) {
   63        this.reportFile = reportFile;
   64        this.parent = parent;
   65        this.node = node;
   66    }
   67
   68    public IReportVisitor visitChild(final ICoverageNode node)
   69            throws IOException {
   70        return CsvReportFile.NULL_VISITOR;
   71    }
   72
   73    public void visitEnd(final ISourceFileLocator sourceFileLocator)
   74            throws IOException {
   75        final DelimitedWriter writer = reportFile.getWriter();
   76
   77        parent.writeContents(writer);
   78        this.writeContents(writer);
   79
   80    }
   81
   82    public void writeContents(final DelimitedWriter writer) throws IOException {
   83        final ILanguageNames languageNames = reportFile.getLanguageNames();
   84        final String className = languageNames.getClassName(node.getName(),
   85                node.getSignature(), node.getSuperName(), node
   86                        .getInterfaceNames());
   87        writer.write(className);
   88
   89        for (final CounterEntity entity : CsvReportFile.COUNTERS) {
   90
   91            final ICounter counter = node.getCounter(entity);
   92            writer.write(counter.getCoveredCount());
   93            writer.write(counter.getNotCoveredCount());
   94        }
   95
   96        writer.nextLine();
   97    }
   98
   99}