alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Cobertura example source code file (NewLocalVariableMethodAdapter.java)

This example Cobertura source code file (NewLocalVariableMethodAdapter.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Cobertura tags/keywords

acc_static, acc_static, label, label, methodadapter, newlocalvariablemethodadapter, newlocalvariablemethodadapter, opcodes, string, string, type

The Cobertura NewLocalVariableMethodAdapter.java source code

/*
 * Cobertura - http://cobertura.sourceforge.net/
 *
 * Copyright (C) 2006 Jiri Mares
 *
 * 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.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;


/**
 * Expects that the visitMaxs is calculated for me .... 
 */
public class NewLocalVariableMethodAdapter extends MethodAdapter implements Opcodes
{
	protected int firstStackVariable;
	protected int addedStackWords;

	public NewLocalVariableMethodAdapter(MethodVisitor mv, int access, String desc, int addedStackWords)
	{
		super(mv);
		Type[] args = Type.getArgumentTypes(desc);
		firstStackVariable = ((ACC_STATIC & access) != 0) ? 0 : 1;
		for (int i = 0; i < args.length; i++) {
			firstStackVariable += args[i].getSize();
		}
		this.addedStackWords = addedStackWords;
	}
	
	public void visitVarInsn(int opcode, int var) 
	{
		mv.visitVarInsn(opcode, (var >= firstStackVariable) ? var + addedStackWords : var);
	}

	public void visitIincInsn(int var, int increment) {
		mv.visitIincInsn((var >= firstStackVariable) ? var + addedStackWords : var, increment);
	}

	public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
	{
		mv.visitLocalVariable(name, desc, signature, start, end, (index >= firstStackVariable) ? index + addedStackWords : index);
	}

	public int getAddedStackWords()
	{
		return addedStackWords;
	}

	public int getFirstStackVariable()
	{
		return firstStackVariable;
	}

}

Other Cobertura examples (source code examples)

Here is a short list of links related to this Cobertura NewLocalVariableMethodAdapter.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.