13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * This file is available under and governed by the GNU General Public 27 * License version 2 only, as published by the Free Software Foundation. 28 * However, the following notice accompanied the original version of this 29 * file: 30 * 31 * ASM: a very small and fast Java bytecode manipulation framework 32 * Copyright (c) 2000-2011 INRIA, France Telecom 33 * Copyright (c) 2011 Google 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. Neither the name of the copyright holders nor the names of its 45 * contributors may be used to endorse or promote products derived from 46 * this software without specific prior written permission. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 58 * THE POSSIBILITY OF SUCH DAMAGE. 59 */ 60 package jdk.internal.org.objectweb.asm.util; 61 62 import jdk.internal.org.objectweb.asm.AnnotationVisitor; 63 import jdk.internal.org.objectweb.asm.Attribute; 64 import jdk.internal.org.objectweb.asm.Handle; 65 import jdk.internal.org.objectweb.asm.Label; 66 import jdk.internal.org.objectweb.asm.MethodVisitor; 67 import jdk.internal.org.objectweb.asm.Opcodes; 68 69 /** 70 * A {@link MethodVisitor} that prints the methods it visits with a 71 * {@link Printer}. 72 * 73 * @author Eric Bruneton 74 */ 75 public final class TraceMethodVisitor extends MethodVisitor { 76 77 public final Printer p; 78 79 public TraceMethodVisitor(final Printer p) { 80 this(null, p); 81 } 82 83 public TraceMethodVisitor(final MethodVisitor mv, final Printer p) { 84 super(Opcodes.ASM4, mv); 85 this.p = p; 86 } 87 88 @Override 89 public AnnotationVisitor visitAnnotation( 90 final String desc, 91 final boolean visible) 92 { 93 Printer p = this.p.visitMethodAnnotation(desc, visible); 94 AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc, 95 visible); 96 return new TraceAnnotationVisitor(av, p); 97 } 98 99 @Override 100 public void visitAttribute(final Attribute attr) { 101 p.visitMethodAttribute(attr); 102 super.visitAttribute(attr); 103 } 104 105 @Override 106 public AnnotationVisitor visitAnnotationDefault() { 107 Printer p = this.p.visitAnnotationDefault(); 108 AnnotationVisitor av = mv == null ? null : mv.visitAnnotationDefault(); 109 return new TraceAnnotationVisitor(av, p); 110 } 111 112 @Override 113 public AnnotationVisitor visitParameterAnnotation( 114 final int parameter, 115 final String desc, 116 final boolean visible) 117 { 118 Printer p = this.p.visitParameterAnnotation(parameter, 119 desc, 120 visible); 121 AnnotationVisitor av = mv == null 122 ? null 123 : mv.visitParameterAnnotation(parameter, desc, visible); 124 return new TraceAnnotationVisitor(av, p); 125 } 126 127 @Override 128 public void visitCode() { 129 p.visitCode(); 130 super.visitCode(); 131 } 132 133 @Override 134 public void visitFrame( 135 final int type, 136 final int nLocal, 137 final Object[] local, 138 final int nStack, 139 final Object[] stack) 140 { 141 p.visitFrame(type, nLocal, local, nStack, stack); 142 super.visitFrame(type, nLocal, local, nStack, stack); 143 } 144 145 @Override 146 public void visitInsn(final int opcode) { 147 p.visitInsn(opcode); 148 super.visitInsn(opcode); 149 } 150 151 @Override 152 public void visitIntInsn(final int opcode, final int operand) { 153 p.visitIntInsn(opcode, operand); 154 super.visitIntInsn(opcode, operand); 155 } 156 157 @Override 158 public void visitVarInsn(final int opcode, final int var) { 159 p.visitVarInsn(opcode, var); 160 super.visitVarInsn(opcode, var); 161 } 162 163 @Override 164 public void visitTypeInsn(final int opcode, final String type) { 165 p.visitTypeInsn(opcode, type); 166 super.visitTypeInsn(opcode, type); 167 } 168 169 @Override 170 public void visitFieldInsn( 171 final int opcode, 172 final String owner, 173 final String name, 174 final String desc) 175 { 176 p.visitFieldInsn(opcode, owner, name, desc); 177 super.visitFieldInsn(opcode, owner, name, desc); 178 } 179 180 @Override 181 public void visitMethodInsn( 182 final int opcode, 183 final String owner, 184 final String name, 185 final String desc) 186 { 187 p.visitMethodInsn(opcode, owner, name, desc); 188 super.visitMethodInsn(opcode, owner, name, desc); 189 } 190 191 @Override 192 public void visitInvokeDynamicInsn( 193 String name, 194 String desc, 195 Handle bsm, 196 Object... bsmArgs) 197 { 198 p.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 199 super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 200 } 201 202 @Override 203 public void visitJumpInsn(final int opcode, final Label label) { 204 p.visitJumpInsn(opcode, label); 205 super.visitJumpInsn(opcode, label); 206 } 207 208 @Override 209 public void visitLabel(final Label label) { 210 p.visitLabel(label); 211 super.visitLabel(label); 212 } 213 214 @Override 215 public void visitLdcInsn(final Object cst) { 216 p.visitLdcInsn(cst); 217 super.visitLdcInsn(cst); 218 } 219 220 @Override 221 public void visitIincInsn(final int var, final int increment) { 222 p.visitIincInsn(var, increment); 223 super.visitIincInsn(var, increment); 224 } 225 226 @Override 227 public void visitTableSwitchInsn( 228 final int min, 229 final int max, 230 final Label dflt, 231 final Label... labels) 232 { 233 p.visitTableSwitchInsn(min, max, dflt, labels); 234 super.visitTableSwitchInsn(min, max, dflt, labels); 235 } 236 237 @Override 238 public void visitLookupSwitchInsn( 239 final Label dflt, 240 final int[] keys, 241 final Label[] labels) 242 { 243 p.visitLookupSwitchInsn(dflt, keys, labels); 244 super.visitLookupSwitchInsn(dflt, keys, labels); 245 } 246 247 @Override 248 public void visitMultiANewArrayInsn(final String desc, final int dims) { 249 p.visitMultiANewArrayInsn(desc, dims); 250 super.visitMultiANewArrayInsn(desc, dims); 251 } 252 253 @Override 254 public void visitTryCatchBlock( 255 final Label start, 256 final Label end, 257 final Label handler, 258 final String type) 259 { 260 p.visitTryCatchBlock(start, end, handler, type); 261 super.visitTryCatchBlock(start, end, handler, type); 262 } 263 264 @Override 265 public void visitLocalVariable( 266 final String name, 267 final String desc, 268 final String signature, 269 final Label start, 270 final Label end, 271 final int index) 272 { 273 p.visitLocalVariable(name, desc, signature, start, end, index); 274 super.visitLocalVariable(name, desc, signature, start, end, index); 275 } 276 277 @Override 278 public void visitLineNumber(final int line, final Label start) { 279 p.visitLineNumber(line, start); 280 super.visitLineNumber(line, start); 281 } 282 283 @Override 284 public void visitMaxs(final int maxStack, final int maxLocals) { 285 p.visitMaxs(maxStack, maxLocals); 286 super.visitMaxs(maxStack, maxLocals); 287 } 288 289 @Override 290 public void visitEnd() { 291 p.visitMethodEnd(); 292 super.visitEnd(); 293 } 294 } | 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * This file is available under and governed by the GNU General Public 27 * License version 2 only, as published by the Free Software Foundation. 28 * However, the following notice accompanied the original version of this 29 * file: 30 * 31 * ASM: a very small and fast Java bytecode manipulation framework 32 * Copyright (c) 2000-2011 INRIA, France Telecom 33 * All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the copyright holders nor the names of its 44 * contributors may be used to endorse or promote products derived from 45 * this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 57 * THE POSSIBILITY OF SUCH DAMAGE. 58 */ 59 package jdk.internal.org.objectweb.asm.util; 60 61 import jdk.internal.org.objectweb.asm.AnnotationVisitor; 62 import jdk.internal.org.objectweb.asm.Attribute; 63 import jdk.internal.org.objectweb.asm.Handle; 64 import jdk.internal.org.objectweb.asm.Label; 65 import jdk.internal.org.objectweb.asm.MethodVisitor; 66 import jdk.internal.org.objectweb.asm.Opcodes; 67 import jdk.internal.org.objectweb.asm.TypePath; 68 69 /** 70 * A {@link MethodVisitor} that prints the methods it visits with a 71 * {@link Printer}. 72 * 73 * @author Eric Bruneton 74 */ 75 public final class TraceMethodVisitor extends MethodVisitor { 76 77 public final Printer p; 78 79 public TraceMethodVisitor(final Printer p) { 80 this(null, p); 81 } 82 83 public TraceMethodVisitor(final MethodVisitor mv, final Printer p) { 84 super(Opcodes.ASM5, mv); 85 this.p = p; 86 } 87 88 @Override 89 public void visitParameter(String name, int access) { 90 p.visitParameter(name, access); 91 super.visitParameter(name, access); 92 } 93 94 @Override 95 public AnnotationVisitor visitAnnotation(final String desc, 96 final boolean visible) { 97 Printer p = this.p.visitMethodAnnotation(desc, visible); 98 AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc, 99 visible); 100 return new TraceAnnotationVisitor(av, p); 101 } 102 103 @Override 104 public AnnotationVisitor visitTypeAnnotation(int typeRef, 105 TypePath typePath, String desc, boolean visible) { 106 Printer p = this.p.visitMethodTypeAnnotation(typeRef, typePath, desc, 107 visible); 108 AnnotationVisitor av = mv == null ? null : mv.visitTypeAnnotation( 109 typeRef, typePath, desc, visible); 110 return new TraceAnnotationVisitor(av, p); 111 } 112 113 @Override 114 public void visitAttribute(final Attribute attr) { 115 p.visitMethodAttribute(attr); 116 super.visitAttribute(attr); 117 } 118 119 @Override 120 public AnnotationVisitor visitAnnotationDefault() { 121 Printer p = this.p.visitAnnotationDefault(); 122 AnnotationVisitor av = mv == null ? null : mv.visitAnnotationDefault(); 123 return new TraceAnnotationVisitor(av, p); 124 } 125 126 @Override 127 public AnnotationVisitor visitParameterAnnotation(final int parameter, 128 final String desc, final boolean visible) { 129 Printer p = this.p.visitParameterAnnotation(parameter, desc, visible); 130 AnnotationVisitor av = mv == null ? null : mv.visitParameterAnnotation( 131 parameter, desc, visible); 132 return new TraceAnnotationVisitor(av, p); 133 } 134 135 @Override 136 public void visitCode() { 137 p.visitCode(); 138 super.visitCode(); 139 } 140 141 @Override 142 public void visitFrame(final int type, final int nLocal, 143 final Object[] local, final int nStack, final Object[] stack) { 144 p.visitFrame(type, nLocal, local, nStack, stack); 145 super.visitFrame(type, nLocal, local, nStack, stack); 146 } 147 148 @Override 149 public void visitInsn(final int opcode) { 150 p.visitInsn(opcode); 151 super.visitInsn(opcode); 152 } 153 154 @Override 155 public void visitIntInsn(final int opcode, final int operand) { 156 p.visitIntInsn(opcode, operand); 157 super.visitIntInsn(opcode, operand); 158 } 159 160 @Override 161 public void visitVarInsn(final int opcode, final int var) { 162 p.visitVarInsn(opcode, var); 163 super.visitVarInsn(opcode, var); 164 } 165 166 @Override 167 public void visitTypeInsn(final int opcode, final String type) { 168 p.visitTypeInsn(opcode, type); 169 super.visitTypeInsn(opcode, type); 170 } 171 172 @Override 173 public void visitFieldInsn(final int opcode, final String owner, 174 final String name, final String desc) { 175 p.visitFieldInsn(opcode, owner, name, desc); 176 super.visitFieldInsn(opcode, owner, name, desc); 177 } 178 179 @Override 180 public void visitMethodInsn(final int opcode, final String owner, 181 final String name, final String desc) { 182 p.visitMethodInsn(opcode, owner, name, desc); 183 super.visitMethodInsn(opcode, owner, name, desc); 184 } 185 186 @Override 187 public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, 188 Object... bsmArgs) { 189 p.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 190 super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); 191 } 192 193 @Override 194 public void visitJumpInsn(final int opcode, final Label label) { 195 p.visitJumpInsn(opcode, label); 196 super.visitJumpInsn(opcode, label); 197 } 198 199 @Override 200 public void visitLabel(final Label label) { 201 p.visitLabel(label); 202 super.visitLabel(label); 203 } 204 205 @Override 206 public void visitLdcInsn(final Object cst) { 207 p.visitLdcInsn(cst); 208 super.visitLdcInsn(cst); 209 } 210 211 @Override 212 public void visitIincInsn(final int var, final int increment) { 213 p.visitIincInsn(var, increment); 214 super.visitIincInsn(var, increment); 215 } 216 217 @Override 218 public void visitTableSwitchInsn(final int min, final int max, 219 final Label dflt, final Label... labels) { 220 p.visitTableSwitchInsn(min, max, dflt, labels); 221 super.visitTableSwitchInsn(min, max, dflt, labels); 222 } 223 224 @Override 225 public void visitLookupSwitchInsn(final Label dflt, final int[] keys, 226 final Label[] labels) { 227 p.visitLookupSwitchInsn(dflt, keys, labels); 228 super.visitLookupSwitchInsn(dflt, keys, labels); 229 } 230 231 @Override 232 public void visitMultiANewArrayInsn(final String desc, final int dims) { 233 p.visitMultiANewArrayInsn(desc, dims); 234 super.visitMultiANewArrayInsn(desc, dims); 235 } 236 237 @Override 238 public AnnotationVisitor visitInsnAnnotation(int typeRef, 239 TypePath typePath, String desc, boolean visible) { 240 Printer p = this.p 241 .visitInsnAnnotation(typeRef, typePath, desc, visible); 242 AnnotationVisitor av = mv == null ? null : mv.visitInsnAnnotation( 243 typeRef, typePath, desc, visible); 244 return new TraceAnnotationVisitor(av, p); 245 } 246 247 @Override 248 public void visitTryCatchBlock(final Label start, final Label end, 249 final Label handler, final String type) { 250 p.visitTryCatchBlock(start, end, handler, type); 251 super.visitTryCatchBlock(start, end, handler, type); 252 } 253 254 @Override 255 public AnnotationVisitor visitTryCatchAnnotation(int typeRef, 256 TypePath typePath, String desc, boolean visible) { 257 Printer p = this.p.visitTryCatchAnnotation(typeRef, typePath, desc, 258 visible); 259 AnnotationVisitor av = mv == null ? null : mv.visitTryCatchAnnotation( 260 typeRef, typePath, desc, visible); 261 return new TraceAnnotationVisitor(av, p); 262 } 263 264 @Override 265 public void visitLocalVariable(final String name, final String desc, 266 final String signature, final Label start, final Label end, 267 final int index) { 268 p.visitLocalVariable(name, desc, signature, start, end, index); 269 super.visitLocalVariable(name, desc, signature, start, end, index); 270 } 271 272 @Override 273 public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, 274 TypePath typePath, Label[] start, Label[] end, int[] index, 275 String desc, boolean visible) { 276 Printer p = this.p.visitLocalVariableAnnotation(typeRef, typePath, 277 start, end, index, desc, visible); 278 AnnotationVisitor av = mv == null ? null : mv 279 .visitLocalVariableAnnotation(typeRef, typePath, start, end, 280 index, desc, visible); 281 return new TraceAnnotationVisitor(av, p); 282 } 283 284 @Override 285 public void visitLineNumber(final int line, final Label start) { 286 p.visitLineNumber(line, start); 287 super.visitLineNumber(line, start); 288 } 289 290 @Override 291 public void visitMaxs(final int maxStack, final int maxLocals) { 292 p.visitMaxs(maxStack, maxLocals); 293 super.visitMaxs(maxStack, maxLocals); 294 } 295 296 @Override 297 public void visitEnd() { 298 p.visitMethodEnd(); 299 super.visitEnd(); 300 } 301 } |