1 /******************************************************************************* 2 * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 * This program and the accompanying materials are made available under 4 * the terms of the Eclipse Public License 2.0 which is available at 5 * http://www.eclipse.org/legal/epl-2.0 6 * 7 * SPDX-License-Identifier: EPL-2.0 8 * 9 * Contributors: 10 * Marc R. Hoffmann - initial API and implementation 11 * 12 *******************************************************************************/ 13 package org.jacoco.core.internal.instr; 14 15 import org.jacoco.core.internal.flow.ClassProbesVisitor; 16 import org.jacoco.core.internal.flow.MethodProbesVisitor; 17 import org.objectweb.asm.Opcodes; 18 19 /** 20 * Internal class to remember the total number of probes required for a class. 21 */ 22 class ProbeCounter extends ClassProbesVisitor { 23 24 private int count; 25 private boolean methods; 26 ProbeCounter()27 ProbeCounter() { 28 count = 0; 29 methods = false; 30 } 31 32 @Override visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions)33 public MethodProbesVisitor visitMethod(final int access, final String name, 34 final String desc, final String signature, 35 final String[] exceptions) { 36 if (!InstrSupport.CLINIT_NAME.equals(name) 37 && (access & Opcodes.ACC_ABSTRACT) == 0) { 38 methods = true; 39 } 40 return null; 41 } 42 43 @Override visitTotalProbeCount(final int count)44 public void visitTotalProbeCount(final int count) { 45 this.count = count; 46 } 47 getCount()48 int getCount() { 49 return count; 50 } 51 52 /** 53 * @return <code>true</code> if the class has non-abstract methods other 54 * than a static initializer 55 */ hasMethods()56 boolean hasMethods() { 57 return methods; 58 } 59 60 } 61