• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2017 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  *******************************************************************************/
12 package org.jacoco.core.internal.instr;
13 
14 import org.jacoco.core.internal.flow.ClassProbesVisitor;
15 import org.jacoco.core.internal.flow.MethodProbesVisitor;
16 import org.objectweb.asm.Opcodes;
17 
18 /**
19  * Internal class to remember the total number of probes required for a class.
20  */
21 class ProbeCounter extends ClassProbesVisitor {
22 
23 	private int count;
24 	private boolean methods;
25 
ProbeCounter()26 	ProbeCounter() {
27 		count = 0;
28 		methods = false;
29 	}
30 
31 	@Override
visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions)32 	public MethodProbesVisitor visitMethod(final int access, final String name,
33 			final String desc, final String signature, final String[] exceptions) {
34 		if (!InstrSupport.CLINIT_NAME.equals(name)
35 				&& (access & Opcodes.ACC_ABSTRACT) == 0) {
36 			methods = true;
37 		}
38 		return null;
39 	}
40 
41 	@Override
visitTotalProbeCount(final int count)42 	public void visitTotalProbeCount(final int count) {
43 		this.count = count;
44 	}
45 
getCount()46 	int getCount() {
47 		return count;
48 	}
49 
50 	/**
51 	 * @return <code>true</code> if the class has non-abstract methods other
52 	 *         than a static initializer
53 	 */
hasMethods()54 	boolean hasMethods() {
55 		return methods;
56 	}
57 
58 }
59