KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hansel > probes > BinaryBranchProbe


1 package org.hansel.probes;
2
3
4 import org.hansel.ProbeData;
5
6 import org.objectweb.asm.MethodVisitor;
7 import org.objectweb.asm.Opcodes;
8 import org.objectweb.asm.tree.analysis.AnalyzerException;
9
10 /**
11  * A probe for a comparing conditional branch. For decision coverage both possible
12  * conditions for the branch have to be encountered.
13  *
14  * @author Niklas Mehner.
15  */

16 public class BinaryBranchProbe extends BranchProbe {
17     private IntComparator cmp;
18
19     public BinaryBranchProbe(ProbeData pd,
20                              IntComparator cmp) throws AnalyzerException {
21         super(pd,
22               cmp.createStackEntry(pd.getStackEntry(1),
23                                    pd.getStackEntry(0)));
24         this.cmp = cmp;
25     }
26
27     public void hit(int n, int m) {
28         cover(cmp.compare(n, m));
29     }
30
31     public void insertProbeCode(MethodVisitor cv) {
32         cv.visitInsn(Opcodes.DUP2);
33         cv.visitLdcInsn(new Integer JavaDoc(getID()));
34         cv.visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS, "hitBranch",
35         "(III)V");
36      }
37 }
38
Popular Tags