01: package org.hansel.probes;
02:
03: import org.hansel.Probe;
04: import org.hansel.ProbeData;
05: import org.objectweb.asm.MethodVisitor;
06: import org.objectweb.asm.Opcodes;
07:
08: /**
09: * 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 getFailureMessage() {
35: return "Method not covered.";
36: }
37:
38: public void insertProbeCode(MethodVisitor cv) {
39: cv.visitLdcInsn(new Integer(getID()));
40: cv.visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS,
41: "hitMethod", "(I)V");
42: }
43:
44: /**
45: * Called by the ProbeTable, when this Probe is encountered by the
46: * instrumented code.
47: */
48: public void hit() {
49: this .covered = true;
50: }
51: }
|