ClassNode.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.MethodCoverage;
   20import org.jacoco.core.analysis.ICoverageNode.CounterEntity;
   21import org.jacoco.report.IReportVisitor;
   22
   23/**
   24 * Wrapper for an {@link XMLElement} that contains class coverage data
   25 * 
   26 * @author Brock Janiczak
   27 * @version $Revision: $
   28 */
   29public class ClassNode extends NodeWithCoverage {
   30    private static final CounterEntity[] CLASS_COUNTERS = {
   31            CounterEntity.METHOD, CounterEntity.BLOCK, CounterEntity.LINE,
   32            CounterEntity.INSTRUCTION, };
   33
   34    /**
   35     * Creates a new Class coverage element for the supplied package and class
   36     * coverage node
   37     * 
   38     * @param parent
   39     *            Parent element that will own this class element
   40     * @param classNode
   41     *            Class coverage node
   42     * @throws IOException
   43     *             IO Error creating the element
   44     */
   45    public ClassNode(final PackageNode parent, final ClassCoverage classNode)
   46            throws IOException {
   47        super(parent, "class", classNode);
   48        if (classNode.getSignature() != null) {
   49            this.attr("signature", classNode.getSignature());
   50        }
   51        if (classNode.getSuperName() != null) {
   52            this.attr("superclass", classNode.getSuperName());
   53        }
   54        if (classNode.getInterfaceNames() != null) {
   55            boolean first = true;
   56            final StringBuilder builder = new StringBuilder();
   57            for (final String iface : classNode.getInterfaceNames()) {
   58                if (first) {
   59                    first = false;
   60                } else {
   61                    builder.append(' ');
   62                }
   63                builder.append(iface);
   64            }
   65            this.attr("interfaces", builder.toString());
   66        }
   67    }
   68
   69    public IReportVisitor visitChild(final ICoverageNode node)
   70            throws IOException {
   71        return new MethodNode(this, (MethodCoverage) node);
   72    }
   73
   74    @Override
   75    protected CounterEntity[] getCounterEntities() {
   76        return CLASS_COUNTERS;
   77    }
   78
   79}