All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cobertura.instrument.ContextMethodAwareMethodAdapter Maven / Gradle / Ivy

Go to download

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.

The newest version!
/*
 * Cobertura - http://cobertura.sourceforge.net/
 *
 * Copyright (C) 2011 Piotr Tabor
 *
 * Note: This file is dual licensed under the GPL and the Apache
 * Source License (so that it can be used from both the main
 * Cobertura classes and the ant tasks).
 *
 * Cobertura is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * Cobertura is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cobertura; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

package net.sourceforge.cobertura.instrument;

import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Abstract implementation of {@link MethodVisitor} that:
 * 
    *
  • provides information about {@link #className},{@link #methodName} and {@link #methodSignature} of method currently being instrumented/analyzed
  • *
  • Assign line identifiers (see {@link AbstractFindTouchPointsClassInstrumenter#lineIdGenerator} to every LINENUMBER asm instruction found
  • *
* * @author ptab */ public abstract class ContextMethodAwareMethodAdapter extends MethodVisitor { protected final String className; protected final String methodName; protected final String methodSignature; /** * What was the last lineId assigned. We can read this field to know which line (by identifier) we are currently analyzing */ protected int lastLineId; /** * Generator that assigns unique (in scope of single class) identifiers to every LINENUMBER asm derective. *

*

We will use this 'generator' to provide this identifiers. Remember to acquire identifiers using {@link AtomicInteger#incrementAndGet()} (not {@link AtomicInteger#getAndIncrement()}!!!)

*/ protected final AtomicInteger lineIdGenerator; public ContextMethodAwareMethodAdapter(MethodVisitor mv, String className, String methodName, String methodSignature, AtomicInteger lineIdGenerator) { super(Opcodes.ASM4, mv); this.className = className; this.methodName = methodName; this.methodSignature = methodSignature; lastLineId = 0; this.lineIdGenerator = lineIdGenerator; } @Override public void visitLineNumber(int number, Label label) { lastLineId = lineIdGenerator.incrementAndGet(); super.visitLineNumber(number, label); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy