Coverage Report - net.sourceforge.cobertura.instrument.NewLocalVariableMethodAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
NewLocalVariableMethodAdapter
93%
14/15
90%
9/10
1.167
 
 1  
 /*
 2  
  * Cobertura - http://cobertura.sourceforge.net/
 3  
  *
 4  
  * Copyright (C) 2006 Jiri Mares
 5  
  *
 6  
  * Cobertura is free software; you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published
 8  
  * by the Free Software Foundation; either version 2 of the License,
 9  
  * or (at your option) any later version.
 10  
  *
 11  
  * Cobertura is distributed in the hope that it will be useful, but
 12  
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14  
  * General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with Cobertura; if not, write to the Free Software
 18  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 19  
  * USA
 20  
  */
 21  
 
 22  
 package net.sourceforge.cobertura.instrument;
 23  
 
 24  
 import org.objectweb.asm.Label;
 25  
 import org.objectweb.asm.MethodAdapter;
 26  
 import org.objectweb.asm.MethodVisitor;
 27  
 import org.objectweb.asm.Opcodes;
 28  
 import org.objectweb.asm.Type;
 29  
 
 30  
 
 31  
 /**
 32  
  * Expects that the visitMaxs is calculated for me .... 
 33  
  */
 34  
 public class NewLocalVariableMethodAdapter extends MethodAdapter implements Opcodes
 35  
 {
 36  
         protected int firstStackVariable;
 37  
         protected int addedStackWords;
 38  
 
 39  
         public NewLocalVariableMethodAdapter(MethodVisitor mv, int access, String desc, int addedStackWords)
 40  
         {
 41  35
                 super(mv);
 42  35
                 Type[] args = Type.getArgumentTypes(desc);
 43  35
                 firstStackVariable = ((ACC_STATIC & access) != 0) ? 0 : 1;
 44  45
                 for (int i = 0; i < args.length; i++) {
 45  10
                         firstStackVariable += args[i].getSize();
 46  
                 }
 47  35
                 this.addedStackWords = addedStackWords;
 48  35
         }
 49  
         
 50  
         public void visitVarInsn(int opcode, int var) 
 51  
         {
 52  66
                 mv.visitVarInsn(opcode, (var >= firstStackVariable) ? var + addedStackWords : var);
 53  66
         }
 54  
 
 55  
         public void visitIincInsn(int var, int increment) {
 56  1
                 mv.visitIincInsn((var >= firstStackVariable) ? var + addedStackWords : var, increment);
 57  1
         }
 58  
 
 59  
         public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
 60  
         {
 61  52
                 mv.visitLocalVariable(name, desc, signature, start, end, (index >= firstStackVariable) ? index + addedStackWords : index);
 62  52
         }
 63  
 
 64  
         public int getAddedStackWords()
 65  
         {
 66  0
                 return addedStackWords;
 67  
         }
 68  
 
 69  
         public int getFirstStackVariable()
 70  
         {
 71  35
                 return firstStackVariable;
 72  
         }
 73  
 
 74  
 }