001: package tide.bytecode.asm;
002:
003: import org.objectweb.asm.*;
004: import java.io.*;
005: import java.util.Arrays;
006:
007: /** A true empty adapter.
008: */
009: public class MethodVisitorAd implements MethodVisitor {
010: private boolean debug = false;
011:
012: public void setDebugMode(boolean is) {
013: debug = is;
014: }
015:
016: final String methodName, argumentList;
017:
018: // quick "do nothing" placeholder.
019: final static public MethodVisitorAd emptyAd = new MethodVisitorAd(
020: null, null);
021:
022: public MethodVisitorAd(String methodName, String argumentList) {
023: this .methodName = methodName;
024: this .argumentList = argumentList;
025: if (debug)
026: System.out.println("======== Start Visiting method "
027: + methodName + "(" + argumentList + ")");
028: }
029:
030: public void visitCode() {
031: if (debug)
032: System.out.println("\nVisit code of " + methodName);
033: }
034:
035: public AnnotationVisitor visitAnnotationDefault() {
036: if (debug)
037: System.out.println("visitAnnotationDefault");
038: return AnnotationVisitorAd.emptyVis;
039: }
040:
041: public AnnotationVisitor visitAnnotation(final String desc,
042: final boolean visible) {
043: if (debug)
044: System.out.println("MP:visitAnnotation desc=" + desc
045: + ", vis=" + visible);
046: return AnnotationVisitorAd.emptyVis;
047: }
048:
049: public AnnotationVisitor visitParameterAnnotation(
050: final int parameter, final String desc,
051: final boolean visible) {
052: if (debug)
053: System.out.println("MP:visitParameterAnnotation " + desc);
054: return AnnotationVisitorAd.emptyVis;
055: }
056:
057: public void visitAttribute(final Attribute attr) {
058: if (debug)
059: System.out.println("MP:visitAttribute " + attr);
060: }
061:
062: public void visitFrame(final int type, final int nLocal,
063: final Object[] local, final int nStack, final Object[] stack) {
064: if (debug)
065: System.out.println("visit frame, " + Arrays.toString(stack)
066: + ", " + Arrays.toString(local));
067: }
068:
069: public void visitInsn(final int opcode) {
070: if (debug)
071: System.out.println("visit insn");
072: }
073:
074: public void visitIntInsn(final int opcode, final int operand) {
075: if (debug)
076: System.out.println("visit intinsn " + operand);
077: }
078:
079: public void visitVarInsn(final int opcode, final int var) {
080: if (debug)
081: System.out.println("visit var " + var);
082: }
083:
084: public void visitTypeInsn(final int opcode, final String desc) {
085: if (debug)
086: System.out.println("visit type " + desc);
087: }
088:
089: public void visitFieldInsn(final int opcode, final String owner,
090: final String name, final String desc) {
091: if (debug)
092: System.out.println("visitFieldInsn " + name);
093: }
094:
095: public void visitMethodInsn(final int opcode, final String owner,
096: final String name, final String desc) {
097: // constr call: visitMethodInsn <init> ()V java/lang/StringBuilder 183
098: // meth call: visitMethodInsn append (Ljava/lang/String;)Ljava/lang/StringBuilder; java/lang/StringBuilder 182
099:
100: if (debug) {
101: System.out.println("visitMethodInsn " + name + " " + desc
102: + " " + owner + " " + opcode);
103: System.out.println(" "
104: + ASMUtils.createArgsListFromSig(desc));
105: }
106: }
107:
108: public void visitJumpInsn(final int opcode, final Label label) {
109: if (debug)
110: System.out.println("visitJumpInsn " + label + ", "
111: + label.info);
112: }
113:
114: public void visitLabel(final Label label) {
115: if (debug)
116: System.out.println("visitLabel " + label + ", "
117: + label.info);
118: }
119:
120: public void visitLdcInsn(final Object cst) {
121: if (debug)
122: System.out.println("visitLdcInsn " + cst);
123: }
124:
125: public void visitIincInsn(final int var, final int increment) {
126: if (debug)
127: System.out.println("visitIincInsn " + var + ", "
128: + increment);
129: }
130:
131: public void visitTableSwitchInsn(final int min, final int max,
132: final Label dflt, final Label labels[]) {
133: if (debug)
134: System.out.println("visitTableSwitchInsn");
135: }
136:
137: public void visitLookupSwitchInsn(final Label dflt,
138: final int keys[], final Label labels[]) {
139: if (debug)
140: System.out.println("visitLookupSwitchInsn");
141: }
142:
143: public void visitMultiANewArrayInsn(final String desc,
144: final int dims) {
145: if (debug)
146: System.out.println("visitMultiANewArrayInsn");
147: }
148:
149: public void visitTryCatchBlock(final Label start, final Label end,
150: final Label handler, final String type) {
151: if (debug)
152: System.out.println("visitTryCatchBlock");
153: }
154:
155: public void visitLocalVariable(final String name,
156: final String desc, final String signature,
157: final Label start, final Label end, final int index) {
158: if (debug)
159: System.out.println("visitLocalVariable " + name + ", "
160: + desc + ", " + signature + " [" + start + ", "
161: + end + ", " + index + "]");
162: }
163:
164: public void visitLineNumber(final int line, final Label start) {
165: if (debug)
166: System.out.println("visitLineNumber " + line);
167: }
168:
169: public void visitMaxs(final int maxStack, final int maxLocals) {
170: if (debug)
171: System.out.println("visitMaxs");
172: }
173:
174: public void visitEnd() {
175: if (debug)
176: System.out.println("Visiting method end: " + methodName
177: + "\n");
178: }
179:
180: }
|