MethodCoverage.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 *    Marc R. Hoffmann - initial API and implementation
   10 *    
   11 * $Id: $
   12 *******************************************************************************/
   13package org.jacoco.core.analysis;
   14
   15/**
   16 * Coverage data of a single method.
   17 * 
   18 * @author Marc R. Hoffmann
   19 * @version $Revision: $
   20 */
   21public class MethodCoverage extends CoverageNodeImpl {
   22
   23    private final String desc;
   24
   25    private final String signature;
   26
   27    /**
   28     * Creates a method coverage data object with the given parameters.
   29     * 
   30     * @param name
   31     *            name of the method
   32     * @param desc
   33     *            parameter description
   34     * @param signature
   35     *            generic signature or <code>null</code>
   36     */
   37    public MethodCoverage(final String name, final String desc,
   38            final String signature) {
   39        super(ElementType.METHOD, name, true);
   40        this.desc = desc;
   41        this.signature = signature;
   42        this.methodCounter = CounterImpl.getInstance(false);
   43    }
   44
   45    /**
   46     * Adds the given block to this method.
   47     * 
   48     * @param instructions
   49     *            number of instructions of this block
   50     * @param lines
   51     *            lines of this block
   52     * @param covered
   53     *            <code>true</code>, if this block is covered
   54     */
   55    public void addBlock(final int instructions, final int[] lines,
   56            final boolean covered) {
   57        this.lines.increment(lines, covered);
   58        this.blockCounter = this.blockCounter.increment(CounterImpl
   59                .getInstance(covered));
   60        this.instructionCounter = this.instructionCounter.increment(CounterImpl
   61                .getInstance(instructions, covered));
   62        if (covered && this.methodCounter.getCoveredCount() == 0) {
   63            this.methodCounter = CounterImpl.getInstance(true);
   64        }
   65    }
   66
   67    /**
   68     * Returns the parameter description of the method.
   69     * 
   70     * @return parameter description
   71     */
   72    public String getDesc() {
   73        return desc;
   74    }
   75
   76    /**
   77     * Returns the generic signature of the method if defined.
   78     * 
   79     * @return generic signature or <code>null</code>
   80     */
   81    public String getSignature() {
   82        return signature;
   83    }
   84
   85}