01: /* MethodAction.java */
02: package org.quilt.cover.stmt;
03:
04: import org.apache.bcel.generic.*;
05:
06: /**
07: * <p>Process a MethodGen method before and after graph creation and
08: * manipulation. A QuiltClassLoader can have any number of such
09: * pre/post-processors. The preprocessors will be applied in order
10: * before graph generation and then the postprocessors will be
11: * applied in reverse order after graph manipulation is complete.</p>
12: *
13: * <p>If any fatal errors occur, transformers must issue a warning
14: * message on System.err and either undo any changes or set method
15: * to null.</p>
16: *
17: * @author <a href="mailto:jddixon@users.sourceforge.net">Jim Dixon</a>
18: */
19: public class MethodAction implements org.quilt.cl.MethodXformer {
20:
21: /** Coverage registry. */
22: private static StmtRegistry stmtReg;
23:
24: /** Name of processor for use in reports. */
25: private static String name_ = null;
26:
27: private ClassGen clazz_ = null;
28: private MethodGen method_ = null;
29: private InstructionList ilist_ = null;
30:
31: public MethodAction() {
32: }
33:
34: public MethodAction(StmtRegistry reg) {
35: stmtReg = reg;
36: setName(this .getClass().getName());
37: }
38:
39: private void dumpIList() {
40: ilist_ = method_.getInstructionList();
41: if (ilist_ != null) {
42: int i = 0;
43: for (InstructionHandle ih = ilist_.getStart(); ih != null; ih = ih
44: .getNext()) {
45: System.out.println(" " + (i++) + " "
46: + ih.getInstruction());
47: }
48: }
49: }
50:
51: /**
52: * Apply processing to method before graph is generated.
53: */
54: public void preGraph(ClassGen clazz, MethodGen method) {
55: clazz_ = clazz;
56: method_ = method;
57: }
58:
59: /**
60: * Process method after graph generation and manipulation is
61: * complete.
62: */
63: public void postGraph(ClassGen clazz, MethodGen method) {
64: clazz_ = clazz;
65: method_ = method;
66: }
67:
68: // XFORMER INTERFACE ////////////////////////////////////////////
69: /** Get the report name for method processor. */
70: public String getName() {
71: return name_;
72: }
73:
74: /** Assign a name to the method processor. */
75: public void setName(String name) {
76: name_ = name;
77: }
78: }
|