PackageColumn.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.ICoverageNode;
   18import org.jacoco.core.analysis.ICoverageNode.ElementType;
   19import org.jacoco.report.ILanguageNames;
   20import org.jacoco.report.IReportVisitor;
   21import org.jacoco.report.ISourceFileLocator;
   22
   23/**
   24 * Column containing the package name
   25 * 
   26 * @author Brock Janiczak
   27 * @version $Revision: $
   28 */
   29public class PackageColumn implements IReportVisitor, ICsvColumn {
   30
   31    private final ICsvColumn parent;
   32    private final CsvReportFile reportFile;
   33    private final String packageName;
   34
   35    /**
   36     * Creates a new Package Column for the report
   37     * 
   38     * @param reportFile
   39     *            CSV Report context
   40     * @param parent
   41     *            parent element
   42     * @param node
   43     *            {@link ElementType#PACKAGE} coverage node
   44     */
   45    public PackageColumn(final CsvReportFile reportFile,
   46            final ICsvColumn parent, final ICoverageNode node) {
   47        this.reportFile = reportFile;
   48        this.parent = parent;
   49        this.packageName = node.getName();
   50    }
   51
   52    public IReportVisitor visitChild(final ICoverageNode node)
   53            throws IOException {
   54        if (node.getElementType() == ElementType.SOURCEFILE) {
   55            return CsvReportFile.NULL_VISITOR;
   56        }
   57        return new ClassColumn(reportFile, this, node);
   58    }
   59
   60    public void visitEnd(final ISourceFileLocator sourceFileLocator)
   61            throws IOException {
   62    }
   63
   64    public void writeContents(final DelimitedWriter writer) throws IOException {
   65        final ILanguageNames languageNames = reportFile.getLanguageNames();
   66        final String value = languageNames.getPackageName(packageName);
   67
   68        parent.writeContents(writer);
   69        writer.write(value);
   70    }
   71
   72}