CsvPackageHandler.java

    1/*******************************************************************************
    2 * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
    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 static java.lang.String.format;
   16
   17import java.io.IOException;
   18
   19import org.jacoco.core.analysis.ClassCoverage;
   20import org.jacoco.core.analysis.ICoverageNode;
   21import org.jacoco.core.analysis.ICoverageNode.ElementType;
   22import org.jacoco.report.IReportVisitor;
   23import org.jacoco.report.ISourceFileLocator;
   24
   25/**
   26 * Report visitor that handles coverage information for packages.
   27 * 
   28 * @author Brock Janiczak
   29 * @version $Revision: $
   30 */
   31class CsvPackageHandler implements IReportVisitor {
   32
   33    private final ClassRowWriter writer;
   34
   35    private final String groupName;
   36
   37    private final String packageName;
   38
   39    public CsvPackageHandler(final ClassRowWriter writer,
   40            final String groupName, final String packageName) {
   41        this.writer = writer;
   42        this.groupName = groupName;
   43        this.packageName = packageName;
   44    }
   45
   46    public IReportVisitor visitChild(final ICoverageNode node)
   47            throws IOException {
   48        final ElementType type = node.getElementType();
   49        switch (type) {
   50        case CLASS:
   51            final ClassCoverage classNode = (ClassCoverage) node;
   52            writer.writeRow(groupName, packageName, classNode);
   53            return IReportVisitor.NOP;
   54        case SOURCEFILE:
   55            return IReportVisitor.NOP;
   56        }
   57        throw new IllegalStateException(format("Unexpected child node %s.",
   58                type));
   59    }
   60
   61    public void visitEnd(final ISourceFileLocator sourceFileLocator) {
   62    }
   63
   64}