MethodCoverageImpl.java revision d05ad7d4bc65e91b6c6efb45687f7a850d07f02a
1/*******************************************************************************
2 * Copyright (c) 2009, 2011 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.internal.analysis;
13
14import org.jacoco.core.analysis.ICounter;
15import org.jacoco.core.analysis.IMethodCoverage;
16
17/**
18 * Implementation of {@link IMethodCoverage}.
19 *
20 * @author Marc R. Hoffmann
21 * @version $qualified.bundle.version$
22 */
23public class MethodCoverageImpl extends SourceNodeImpl implements IMethodCoverage {
24
25	private final String desc;
26
27	private final String signature;
28
29	/**
30	 * Creates a method coverage data object with the given parameters.
31	 *
32	 * @param name
33	 *            name of the method
34	 * @param desc
35	 *            parameter description
36	 * @param signature
37	 *            generic signature or <code>null</code>
38	 */
39	public MethodCoverageImpl(final String name, final String desc,
40			final String signature) {
41		super(ElementType.METHOD, name);
42		this.desc = desc;
43		this.signature = signature;
44		this.methodCounter = CounterImpl.COUNTER_1_0;
45	}
46
47	@Override
48	public void increment(final ICounter instructions, final ICounter branches,
49			final int line) {
50		super.increment(instructions, branches, line);
51		if (instructions.getCoveredCount() > 0
52				&& this.methodCounter.getCoveredCount() == 0) {
53			this.methodCounter = CounterImpl.COUNTER_0_1;
54		}
55	}
56
57	// === IMethodCoverage implementation ===
58
59	public String getDesc() {
60		return desc;
61	}
62
63	public String getSignature() {
64		return signature;
65	}
66
67}
68