PackageNode.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.xml;
   14
   15import java.io.IOException;
   16
   17import org.jacoco.core.analysis.ClassCoverage;
   18import org.jacoco.core.analysis.ICoverageNode;
   19import org.jacoco.core.analysis.ICoverageNode.ElementType;
   20import org.jacoco.report.IReportVisitor;
   21import org.jacoco.report.ISourceFileLocator;
   22
   23/**
   24 * Wrapper for an {@link XMLElement} that contains package coverage data
   25 * 
   26 * @author Brock Janiczak
   27 * @version $Revision: $
   28 */
   29public class PackageNode extends NodeWithCoverage {
   30
   31    /**
   32     * Creates a new Package coverage element under the supplied group element
   33     * 
   34     * @param parent
   35     *            Parent element that will own this class element
   36     * @param packageNode
   37     *            Package coverage node
   38     * @throws IOException
   39     *             IO Error creating the element
   40     */
   41    public PackageNode(final GroupNode parent, final ICoverageNode packageNode)
   42            throws IOException {
   43        super(parent, "package", packageNode);
   44    }
   45
   46    public IReportVisitor visitChild(final ICoverageNode node)
   47            throws IOException {
   48        if (node.getElementType() == ElementType.CLASS) {
   49            return new ClassNode(this, (ClassCoverage) node);
   50        } else if (node.getElementType() == ElementType.SOURCEFILE) {
   51            return new IReportVisitor() {
   52
   53                public void visitEnd(final ISourceFileLocator sourceFileLocator)
   54                        throws IOException {
   55                }
   56
   57                public IReportVisitor visitChild(final ICoverageNode node)
   58                        throws IOException {
   59                    return this;
   60                }
   61            };
   62        }
   63        return null;
   64    }
   65
   66}