~ubuntu-branches/ubuntu/oneiric/cobertura/oneiric

« back to all changes in this revision

Viewing changes to src/net/sourceforge/cobertura/instrument/SecondPassMethodInstrumenter.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-05-11 19:21:46 UTC
  • mfrom: (0.1.4 sid) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100511192146-j742v5jsl89ztndu
Tags: 1.9.4.1+dfsg-2
* Now Build-Depends on libservlet2.5-java and add a missing Depends
  on the same package. (Closes: #580842). 
* Simplify list of JRE dependences for cobertura and drop JRE dependences for
  libcobertura-java as Java libraries are no longer required to depend on a
  JVM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (C) 2005 Mark Doliner
5
5
 * Copyright (C) 2006 Jiri Mares
 
6
 * Copyright (C) 2010 Piotr Tabor
6
7
 *
7
8
 * Cobertura is free software; you can redistribute it and/or modify
8
9
 * it under the terms of the GNU General Public License as published
32
33
 */
33
34
public class SecondPassMethodInstrumenter extends NewLocalVariableMethodAdapter implements Opcodes
34
35
{
 
36
        private String TOUCH_COLLECTOR_CLASS="net/sourceforge/cobertura/coveragedata/TouchCollector";
 
37
        
35
38
        private int currentLine;
36
39
   
37
40
        private int currentJump;
87
90
                currentLine = line;
88
91
                currentJump = 0;
89
92
 
90
 
                instrumentGetClassData();
 
93
                instrumentOwnerClass();
91
94
 
92
95
                // Mark the current line number as covered:
93
96
                // classData.touch(line)
94
97
                mv.visitIntInsn(SIPUSH, line);
95
 
                mv.visitMethodInsn(INVOKEVIRTUAL,
96
 
                                "net/sourceforge/cobertura/coveragedata/ClassData", "touch",
97
 
                                "(I)V");
 
98
                mv.visitMethodInsn(INVOKESTATIC,
 
99
                                TOUCH_COLLECTOR_CLASS, "touch",
 
100
                                "(Ljava/lang/String;I)V");
98
101
 
99
102
                super.visitLineNumber(line, start);
100
103
        }
171
174
                        if (lastJump != null) 
172
175
                        { //this is also label after jump - we have to check the branch number whether this is the true or false branch
173
176
                                Label newLabelX = instrumentIsLastJump();
174
 
                                instrumentGetClassData();
 
177
                                instrumentOwnerClass();
175
178
                                instrumentPutLineAndBranchNumbers();
176
179
                                mv.visitInsn(BOOLEAN_FALSE);
177
180
                                instrumentInvokeTouchJump();
180
183
                                mv.visitLabel(newLabelX);
181
184
                                mv.visitVarInsn(ILOAD, myVariableIndex + 1);
182
185
                                mv.visitJumpInsn(IFLT, newLabelY);
183
 
                                instrumentGetClassData();
 
186
                                instrumentOwnerClass();
184
187
                                instrumentPutLineAndBranchNumbers();
185
188
                                mv.visitInsn(BOOLEAN_TRUE);
186
189
                                instrumentInvokeTouchJump();
287
290
                }
288
291
        }
289
292
 
290
 
        private void instrumentGetClassData()
 
293
        private void instrumentOwnerClass()
291
294
        {
292
 
                // Get an instance of ProjectData:
293
 
                // ProjectData.getGlobalProjectData()
294
 
                mv.visitMethodInsn(INVOKESTATIC,
295
 
                                "net/sourceforge/cobertura/coveragedata/ProjectData",
296
 
                                "getGlobalProjectData",
297
 
                                "()Lnet/sourceforge/cobertura/coveragedata/ProjectData;");
298
 
 
299
 
                // Get the ClassData object for this class:
300
 
                // projectData.getClassData("name.of.this.class")
 
295
                // OwnerClass is the name of the class being instrumented
301
296
                mv.visitLdcInsn(firstPass.getOwnerClass());
302
 
                mv
303
 
                        .visitMethodInsn(INVOKEVIRTUAL,
304
 
                                        "net/sourceforge/cobertura/coveragedata/ProjectData",
305
 
                                        "getOrCreateClassData",
306
 
                                        "(Ljava/lang/String;)Lnet/sourceforge/cobertura/coveragedata/ClassData;");
307
297
        }
308
298
        
309
299
        private void instrumentSwitchHit(int lineNumber, int switchNumber, int branch)
310
300
        {
311
 
                instrumentGetClassData();
 
301
                instrumentOwnerClass();
312
302
                
313
303
                //Invoke the touchSwitch(lineNumber, switchNumber, branch)
314
304
                mv.visitIntInsn(SIPUSH, lineNumber);
319
309
        
320
310
        private void instrumentJumpHit(boolean branch)
321
311
        {
322
 
                instrumentGetClassData();
 
312
                instrumentOwnerClass();
323
313
                
324
314
                //Invoke the touchJump(lineNumber, branchNumber, branch)
325
315
                instrumentPutLineAndBranchNumbers();
329
319
 
330
320
        private void instrumentInvokeTouchJump()
331
321
        {
332
 
                mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/coveragedata/ClassData", "touchJump", "(IIZ)V");
 
322
                mv.visitMethodInsn(INVOKESTATIC, TOUCH_COLLECTOR_CLASS, "touchJump", "(Ljava/lang/String;IIZ)V");
333
323
                mv.visitIntInsn(SIPUSH, -1); //is important to reset current branch, because we have to know that the branch info on stack has already been used and can't be used
334
324
                mv.visitVarInsn(ISTORE, myVariableIndex + 1);
335
325
        }
336
326
 
337
327
        private void instrumentInvokeTouchSwitch()
338
328
        {
339
 
                mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/coveragedata/ClassData", "touchSwitch", "(III)V");
 
329
                mv.visitMethodInsn(INVOKESTATIC, TOUCH_COLLECTOR_CLASS, "touchSwitch", "(Ljava/lang/String;III)V");
340
330
        }
341
331
 
342
332
        private void instrumentPutLineAndBranchNumbers()