// Path: cobertura/src/main/java/net/sourceforge/cobertura/Cobertura.java
// public class Cobertura {
// 	public static String TestClassAndMethodNamesMerged = "";
// }
// 
// Path: cobertura/src/main/java/net/sourceforge/cobertura/coveragedata/TestUnitInformationHolder.java
// public class TestUnitInformationHolder {
// 	private List<String> testNames;
// 	
// 	public TestUnitInformationHolder() {
// 		testNames = new ArrayList<String>();
// 	}
// 	
// 	public void appendTestUnit(String nameOfTestUnit) {
// 		testNames.add(nameOfTestUnit);
// 	}
// 	
// 	public int getNumOfExecutions() {
// 		return testNames.size();
// 	}
// 
// 	public List<String> getAndReset() {
// 		List<String> returnArray = testNames;
// 		testNames = new ArrayList<String>();
// 		return returnArray;
// 	}
// 
// 	public List<String> getTestUnitList() {
// 		return testNames;
// 	}
// }


import net.sourceforge.cobertura.Cobertura;
import net.sourceforge.cobertura.coveragedata.TestUnitInformationHolder;
import org.objectweb.asm.*;
/*
 * Cobertura - http://cobertura.sourceforge.net/
 *
 * Copyright (C) 2013 Steven Christou
 *
 * 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.pass3;



/**
 * 
 * For every single line of code we add the following:
 * 
 * Before instrumentation:
 * 1: public int foo() {
 * 2:  int x = 0;
 * 3:  x++;
 * 4:  return x;
 * 5: }
 * 
 * After instrumentation:
 * public int foo() {
 *   __cobertura_counters
 *         .get(2)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   int x = 0; 
 *   __cobertura_counters
 *         .get(3)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   x++;
 *   __cobertura_counters
 *         .get(4)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   return x;
 * }
 * 
 * In future versions it might be best to switch from the ConcurrentHashMap to a more static approach.
 *
 * @author christ66
 */
public class TestUnitCodeProvider extends AbstractCodeProvider
		implements
			CodeProvider, Opcodes {

	/**
	 * Type of the generated field, that is used to store counters
	 */
	static final String COBERTURA_COUNTERS_FIELD_TYPE = "[Lnet/sourceforge/cobertura/coveragedata/TestUnitInformationHolder;";

	/**
	 * Generates:
	 * 
	 */
	public void generateCodeThatIncrementsCoberturaCounterFromInternalVariable(
			MethodVisitor nextMethodVisitor, int lastJumpIdVariableIndex,
			String className) {
		nextMethodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
		nextMethodVisitor.visitFieldInsn(Opcodes.GETFIELD, className,
				COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE);
		nextMethodVisitor.visitVarInsn(Opcodes.ILOAD, lastJumpIdVariableIndex);
		nextMethodVisitor.visitInsn(Opcodes.DUP2);
		nextMethodVisitor.visitInsn(Opcodes.IALOAD);
		nextMethodVisitor.visitFieldInsn(Opcodes.GETSTATIC, Type
				.getInternalName(Cobertura.class),
				"TestClassAndMethodNamesMerged", "Ljava/lang/String;");
		nextMethodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type
// Path: cobertura/src/main/java/net/sourceforge/cobertura/Cobertura.java
// public class Cobertura {
// 	public static String TestClassAndMethodNamesMerged = "";
// }
// 
// Path: cobertura/src/main/java/net/sourceforge/cobertura/coveragedata/TestUnitInformationHolder.java
// public class TestUnitInformationHolder {
// 	private List<String> testNames;
// 	
// 	public TestUnitInformationHolder() {
// 		testNames = new ArrayList<String>();
// 	}
// 	
// 	public void appendTestUnit(String nameOfTestUnit) {
// 		testNames.add(nameOfTestUnit);
// 	}
// 	
// 	public int getNumOfExecutions() {
// 		return testNames.size();
// 	}
// 
// 	public List<String> getAndReset() {
// 		List<String> returnArray = testNames;
// 		testNames = new ArrayList<String>();
// 		return returnArray;
// 	}
// 
// 	public List<String> getTestUnitList() {
// 		return testNames;
// 	}
// }


// Path: cobertura/src/main/java/net/sourceforge/cobertura/instrument/pass3/TestUnitCodeProvider.java
import net.sourceforge.cobertura.Cobertura;
import net.sourceforge.cobertura.coveragedata.TestUnitInformationHolder;
import org.objectweb.asm.*;

/*
 * Cobertura - http://cobertura.sourceforge.net/
 *
 * Copyright (C) 2013 Steven Christou
 *
 * 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.pass3;



/**
 * 
 * For every single line of code we add the following:
 * 
 * Before instrumentation:
 * 1: public int foo() {
 * 2:  int x = 0;
 * 3:  x++;
 * 4:  return x;
 * 5: }
 * 
 * After instrumentation:
 * public int foo() {
 *   __cobertura_counters
 *         .get(2)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   int x = 0; 
 *   __cobertura_counters
 *         .get(3)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   x++;
 *   __cobertura_counters
 *         .get(4)
 *         .append(", " + net.sourceforge.cobertura.Cobertura.TestClassAndMethodNamesMerged);
 *   return x;
 * }
 * 
 * In future versions it might be best to switch from the ConcurrentHashMap to a more static approach.
 *
 * @author christ66
 */
public class TestUnitCodeProvider extends AbstractCodeProvider
		implements
			CodeProvider, Opcodes {

	/**
	 * Type of the generated field, that is used to store counters
	 */
	static final String COBERTURA_COUNTERS_FIELD_TYPE = "[Lnet/sourceforge/cobertura/coveragedata/TestUnitInformationHolder;";

	/**
	 * Generates:
	 * 
	 */
	public void generateCodeThatIncrementsCoberturaCounterFromInternalVariable(
			MethodVisitor nextMethodVisitor, int lastJumpIdVariableIndex,
			String className) {
		nextMethodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
		nextMethodVisitor.visitFieldInsn(Opcodes.GETFIELD, className,
				COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE);
		nextMethodVisitor.visitVarInsn(Opcodes.ILOAD, lastJumpIdVariableIndex);
		nextMethodVisitor.visitInsn(Opcodes.DUP2);
		nextMethodVisitor.visitInsn(Opcodes.IALOAD);
		nextMethodVisitor.visitFieldInsn(Opcodes.GETSTATIC, Type
				.getInternalName(Cobertura.class),
				"TestClassAndMethodNamesMerged", "Ljava/lang/String;");
		nextMethodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type
				.getInternalName(TestUnitInformationHolder.class),