KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.hansel.probes;
2
3 import org.hansel.Probe;
4 import org.hansel.ProbeData;
5 import org.objectweb.asm.MethodVisitor;
6 import org.objectweb.asm.Opcodes;
7
8 /**
9  * A simple Probe that is placed in the instrumented code.
10  * @author Niklas Mehner.
11  */

12 public class MethodProbe extends Probe {
13
14     /** True, if the isntrumented code has already encountered this probe. */
15     private boolean covered;
16
17     /**
18      * Create a new Probe.
19      * @param pd Data for this probe.
20      */

21     public MethodProbe(ProbeData pd) {
22         super(pd);
23         this.covered = false;
24     }
25
26     public boolean displayFailure() {
27         return coverageFailure();
28     }
29
30     public boolean coverageFailure() {
31         return !covered;
32     }
33
34     public String JavaDoc getFailureMessage() {
35         return "Method not covered.";
36     }
37
38     public void insertProbeCode(MethodVisitor cv) {
39       cv.visitLdcInsn(new Integer JavaDoc(getID()));
40       cv.visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS, "hitMethod", "(I)V");
41     }
42     
43     /**
44      * Called by the ProbeTable, when this Probe is encountered by the
45      * instrumented code.
46      */

47     public void hit() {
48         this.covered = true;
49     }
50 }
51
Popular Tags