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