1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. Oracle designates this 7 * particular file as subject to the "Classpath" exception as provided 8 * by Oracle in the LICENSE file that accompanied this code. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 java.io.PrintWriter; 62 import java.util.ArrayList; 63 import java.util.List; 64 65 import jdk.internal.org.objectweb.asm.Attribute; 66 import jdk.internal.org.objectweb.asm.Handle; 67 import jdk.internal.org.objectweb.asm.Label; 68 import jdk.internal.org.objectweb.asm.Opcodes; 69 import jdk.internal.org.objectweb.asm.TypePath; 70 71 /** 72 * An abstract converter from visit events to text. 73 * 74 * @author Eric Bruneton 75 */ 76 public abstract class Printer { 77 78 /** 79 * The names of the Java Virtual Machine opcodes. 80 */ 81 public static final String[] OPCODES; 82 83 /** 84 * The names of the for <code>operand</code> parameter values of the 85 * {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIntInsn} method when 86 * <code>opcode</code> is <code>NEWARRAY</code>. 87 */ 88 public static final String[] TYPES; 89 90 /** 91 * The names of the <code>tag</code> field values for 92 * {@link jdk.internal.org.objectweb.asm.Handle}. 93 */ 94 public static final String[] HANDLE_TAG; 95 96 static { 97 String s = "NOP,ACONST_NULL,ICONST_M1,ICONST_0,ICONST_1,ICONST_2," 98 + "ICONST_3,ICONST_4,ICONST_5,LCONST_0,LCONST_1,FCONST_0," 99 + "FCONST_1,FCONST_2,DCONST_0,DCONST_1,BIPUSH,SIPUSH,LDC,,," 100 + "ILOAD,LLOAD,FLOAD,DLOAD,ALOAD,,,,,,,,,,,,,,,,,,,,,IALOAD," 101 + "LALOAD,FALOAD,DALOAD,AALOAD,BALOAD,CALOAD,SALOAD,ISTORE," 102 + "LSTORE,FSTORE,DSTORE,ASTORE,,,,,,,,,,,,,,,,,,,,,IASTORE," 103 + "LASTORE,FASTORE,DASTORE,AASTORE,BASTORE,CASTORE,SASTORE,POP," 104 + "POP2,DUP,DUP_X1,DUP_X2,DUP2,DUP2_X1,DUP2_X2,SWAP,IADD,LADD," 105 + "FADD,DADD,ISUB,LSUB,FSUB,DSUB,IMUL,LMUL,FMUL,DMUL,IDIV,LDIV," 106 + "FDIV,DDIV,IREM,LREM,FREM,DREM,INEG,LNEG,FNEG,DNEG,ISHL,LSHL," 107 + "ISHR,LSHR,IUSHR,LUSHR,IAND,LAND,IOR,LOR,IXOR,LXOR,IINC,I2L," 108 + "I2F,I2D,L2I,L2F,L2D,F2I,F2L,F2D,D2I,D2L,D2F,I2B,I2C,I2S,LCMP," 109 + "FCMPL,FCMPG,DCMPL,DCMPG,IFEQ,IFNE,IFLT,IFGE,IFGT,IFLE," 110 + "IF_ICMPEQ,IF_ICMPNE,IF_ICMPLT,IF_ICMPGE,IF_ICMPGT,IF_ICMPLE," 111 + "IF_ACMPEQ,IF_ACMPNE,GOTO,JSR,RET,TABLESWITCH,LOOKUPSWITCH," 112 + "IRETURN,LRETURN,FRETURN,DRETURN,ARETURN,RETURN,GETSTATIC," 113 + "PUTSTATIC,GETFIELD,PUTFIELD,INVOKEVIRTUAL,INVOKESPECIAL," 114 + "INVOKESTATIC,INVOKEINTERFACE,INVOKEDYNAMIC,NEW,NEWARRAY," 115 + "ANEWARRAY,ARRAYLENGTH,ATHROW,CHECKCAST,INSTANCEOF," 116 + "MONITORENTER,MONITOREXIT,,MULTIANEWARRAY,IFNULL,IFNONNULL,"; 117 OPCODES = new String[200]; 118 int i = 0; 119 int j = 0; 120 int l; 121 while ((l = s.indexOf(',', j)) > 0) { 122 OPCODES[i++] = j + 1 == l ? null : s.substring(j, l); 123 j = l + 1; 124 } 125 126 s = "T_BOOLEAN,T_CHAR,T_FLOAT,T_DOUBLE,T_BYTE,T_SHORT,T_INT,T_LONG,"; 127 TYPES = new String[12]; 128 j = 0; 129 i = 4; 130 while ((l = s.indexOf(',', j)) > 0) { 131 TYPES[i++] = s.substring(j, l); 132 j = l + 1; 133 } 134 135 s = "H_GETFIELD,H_GETSTATIC,H_PUTFIELD,H_PUTSTATIC," 136 + "H_INVOKEVIRTUAL,H_INVOKESTATIC,H_INVOKESPECIAL," 137 + "H_NEWINVOKESPECIAL,H_INVOKEINTERFACE,"; 138 HANDLE_TAG = new String[10]; 139 j = 0; 140 i = 1; 141 while ((l = s.indexOf(',', j)) > 0) { 142 HANDLE_TAG[i++] = s.substring(j, l); 143 j = l + 1; 144 } 145 } 146 147 /** 148 * The ASM API version implemented by this class. The value of this field 149 * must be one of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. 150 */ 151 protected final int api; 152 153 /** 154 * A buffer that can be used to create strings. 155 */ 156 protected final StringBuffer buf; 157 158 /** 159 * The text to be printed. Since the code of methods is not necessarily 160 * visited in sequential order, one method after the other, but can be 161 * interlaced (some instructions from method one, then some instructions 162 * from method two, then some instructions from method one again...), it is 163 * not possible to print the visited instructions directly to a sequential 164 * stream. A class is therefore printed in a two steps process: a string 165 * tree is constructed during the visit, and printed to a sequential stream 166 * at the end of the visit. This string tree is stored in this field, as a 167 * string list that can contain other string lists, which can themselves 168 * contain other string lists, and so on. 169 */ 170 public final List<Object> text; 171 172 /** 173 * Constructs a new {@link Printer}. 174 * 175 * @param api 176 * the ASM API version implemented by this printer. Must be one 177 * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. 178 */ 179 protected Printer(final int api) { 180 this.api = api; 181 this.buf = new StringBuffer(); 182 this.text = new ArrayList<Object>(); 183 } 184 185 /** 186 * Class header. 187 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visit}. 188 * 189 * @param version 190 * the class version. 191 * @param access 192 * the class's access flags (see {@link Opcodes}). This parameter 193 * also indicates if the class is deprecated. 194 * @param name 195 * the internal name of the class (see 196 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 197 * @param signature 198 * the signature of this class. May be <tt>null</tt> if the class 199 * is not a generic one, and does not extend or implement generic 200 * classes or interfaces. 201 * @param superName 202 * the internal of name of the super class (see 203 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 204 * For interfaces, the super class is {@link Object}. May be 205 * <tt>null</tt>, but only for the {@link Object} class. 206 * @param interfaces 207 * the internal names of the class's interfaces (see 208 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 209 * May be <tt>null</tt>. 210 */ 211 public abstract void visit(final int version, final int access, 212 final String name, final String signature, final String superName, 213 final String[] interfaces); 214 215 /** 216 * Class source. 217 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitSource}. 218 * 219 * @param source 220 * the name of the source file from which the class was compiled. 221 * May be <tt>null</tt>. 222 * @param debug 223 * additional debug information to compute the correspondance 224 * between source and compiled elements of the class. May be 225 * <tt>null</tt>. 226 */ 227 public abstract void visitSource(final String source, final String debug); 228 229 230 /** 231 * Module. 232 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitModule(String, int)}. 233 * 234 * @param name 235 * module name. 236 * @param access 237 * module flags, among {@code ACC_OPEN}, {@code ACC_SYNTHETIC} 238 * and {@code ACC_MANDATED}. 239 * @param version 240 * module version or null. 241 * @return 242 */ 243 public Printer visitModule(String name, int access, String version) { 244 throw new RuntimeException("Must be overriden"); 245 } 246 247 /** 248 * Class outer class. 249 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitOuterClass}. 250 * 251 * Visits the enclosing class of the class. This method must be called only 252 * if the class has an enclosing class. 253 * 254 * @param owner 255 * internal name of the enclosing class of the class. 256 * @param name 257 * the name of the method that contains the class, or 258 * <tt>null</tt> if the class is not enclosed in a method of its 259 * enclosing class. 260 * @param desc 261 * the descriptor of the method that contains the class, or 262 * <tt>null</tt> if the class is not enclosed in a method of its 263 * enclosing class. 264 */ 265 public abstract void visitOuterClass(final String owner, final String name, 266 final String desc); 267 268 /** 269 * Class annotation. 270 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitAnnotation}. 271 * 272 * @param desc 273 * the class descriptor of the annotation class. 274 * @param visible 275 * <tt>true</tt> if the annotation is visible at runtime. 276 * @return the printer 277 */ 278 public abstract Printer visitClassAnnotation(final String desc, 279 final boolean visible); 280 281 /** 282 * Class type annotation. 283 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitTypeAnnotation}. 284 * 285 * @param typeRef 286 * a reference to the annotated type. The sort of this type 287 * reference must be 288 * {@link jdk.internal.org.objectweb.asm.TypeReference#CLASS_TYPE_PARAMETER CLASS_TYPE_PARAMETER}, 289 * {@link jdk.internal.org.objectweb.asm.TypeReference#CLASS_TYPE_PARAMETER_BOUND CLASS_TYPE_PARAMETER_BOUND} 290 * or {@link jdk.internal.org.objectweb.asm.TypeReference#CLASS_EXTENDS CLASS_EXTENDS}. 291 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 292 * @param typePath 293 * the path to the annotated type argument, wildcard bound, array 294 * element type, or static inner type within 'typeRef'. May be 295 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 296 * @param desc 297 * the class descriptor of the annotation class. 298 * @param visible 299 * <tt>true</tt> if the annotation is visible at runtime. 300 * @return the printer 301 */ 302 public Printer visitClassTypeAnnotation(final int typeRef, 303 final TypePath typePath, final String desc, final boolean visible) { 304 throw new RuntimeException("Must be overriden"); 305 } 306 307 /** 308 * Class attribute. 309 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitAttribute}. 310 * 311 * @param attr 312 * an attribute. 313 */ 314 public abstract void visitClassAttribute(final Attribute attr); 315 316 /** 317 * Class inner name. 318 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitInnerClass}. 319 * 320 * @param name 321 * the internal name of an inner class (see 322 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 323 * @param outerName 324 * the internal name of the class to which the inner class 325 * belongs (see {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 326 * May be <tt>null</tt> for not member classes. 327 * @param innerName 328 * the (simple) name of the inner class inside its enclosing 329 * class. May be <tt>null</tt> for anonymous inner classes. 330 * @param access 331 * the access flags of the inner class as originally declared in 332 * the enclosing class. 333 */ 334 public abstract void visitInnerClass(final String name, 335 final String outerName, final String innerName, final int access); 336 337 /** 338 * Class field. 339 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitField}. 340 * 341 * @param access 342 * the field's access flags (see {@link Opcodes}). This parameter 343 * also indicates if the field is synthetic and/or deprecated. 344 * @param name 345 * the field's name. 346 * @param desc 347 * the field's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 348 * @param signature 349 * the field's signature. May be <tt>null</tt> if the field's 350 * type does not use generic types. 351 * @param value 352 * the field's initial value. This parameter, which may be 353 * <tt>null</tt> if the field does not have an initial value, 354 * must be an {@link Integer}, a {@link Float}, a {@link Long}, a 355 * {@link Double} or a {@link String} (for <tt>int</tt>, 356 * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields 357 * respectively). <i>This parameter is only used for static 358 * fields</i>. Its value is ignored for non static fields, which 359 * must be initialized through bytecode instructions in 360 * constructors or methods. 361 * @return the printer 362 */ 363 public abstract Printer visitField(final int access, final String name, 364 final String desc, final String signature, final Object value); 365 366 /** 367 * Class method. 368 * See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitMethod}. 369 * 370 * @param access 371 * the method's access flags (see {@link Opcodes}). This 372 * parameter also indicates if the method is synthetic and/or 373 * deprecated. 374 * @param name 375 * the method's name. 376 * @param desc 377 * the method's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 378 * @param signature 379 * the method's signature. May be <tt>null</tt> if the method 380 * parameters, return type and exceptions do not use generic 381 * types. 382 * @param exceptions 383 * the internal names of the method's exception classes (see 384 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). May be 385 * <tt>null</tt>. 386 * @return the printer 387 */ 388 public abstract Printer visitMethod(final int access, final String name, 389 final String desc, final String signature, final String[] exceptions); 390 391 /** 392 * Class end. See {@link jdk.internal.org.objectweb.asm.ClassVisitor#visitEnd}. 393 */ 394 public abstract void visitClassEnd(); 395 396 // ------------------------------------------------------------------------ 397 // Module 398 // ------------------------------------------------------------------------ 399 400 public void visitMainClass(String mainClass) { 401 throw new RuntimeException("Must be overriden"); 402 } 403 404 public void visitPackage(String packaze) { 405 throw new RuntimeException("Must be overriden"); 406 } 407 408 public void visitRequire(String module, int access, String version) { 409 throw new RuntimeException("Must be overriden"); 410 } 411 412 public void visitExport(String packaze, int access, String... modules) { 413 throw new RuntimeException("Must be overriden"); 414 } 415 416 public void visitOpen(String packaze, int access, String... modules) { 417 throw new RuntimeException("Must be overriden"); 418 } 419 420 public void visitUse(String service) { 421 throw new RuntimeException("Must be overriden"); 422 } 423 424 public void visitProvide(String service, String... providers) { 425 throw new RuntimeException("Must be overriden"); 426 } 427 428 /** 429 * Module end. See {@link jdk.internal.org.objectweb.asm.ModuleVisitor#visitEnd}. 430 */ 431 public void visitModuleEnd() { 432 throw new RuntimeException("Must be overriden"); 433 } 434 435 // ------------------------------------------------------------------------ 436 // Annotations 437 // ------------------------------------------------------------------------ 438 439 /** 440 * Annotation value. 441 * See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visit}. 442 * 443 * @param name 444 * the value name. 445 * @param value 446 * the actual value, whose type must be {@link Byte}, 447 * {@link Boolean}, {@link Character}, {@link Short}, 448 * {@link Integer} , {@link Long}, {@link Float}, {@link Double}, 449 * {@link String} or {@link jdk.internal.org.objectweb.asm.Type} 450 * or OBJECT or ARRAY sort. 451 * This value can also be an array of byte, boolean, short, char, int, 452 * long, float or double values (this is equivalent to using 453 * {@link #visitArray visitArray} and visiting each array element 454 * in turn, but is more convenient). 455 */ 456 public abstract void visit(final String name, final Object value); 457 458 /** 459 * Annotation enum value. 460 * See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitEnum}. 461 * 462 * Visits an enumeration value of the annotation. 463 * 464 * @param name 465 * the value name. 466 * @param desc 467 * the class descriptor of the enumeration class. 468 * @param value 469 * the actual enumeration value. 470 */ 471 public abstract void visitEnum(final String name, final String desc, 472 final String value); 473 474 /** 475 * Nested annotation value. 476 * See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitAnnotation}. 477 * 478 * @param name 479 * the value name. 480 * @param desc 481 * the class descriptor of the nested annotation class. 482 * @return the printer 483 */ 484 public abstract Printer visitAnnotation(final String name, final String desc); 485 486 /** 487 * Annotation array value. 488 * See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitArray}. 489 * 490 * Visits an array value of the annotation. Note that arrays of primitive 491 * types (such as byte, boolean, short, char, int, long, float or double) 492 * can be passed as value to {@link #visit visit}. This is what 493 * {@link jdk.internal.org.objectweb.asm.ClassReader} does. 494 * 495 * @param name 496 * the value name. 497 * @return the printer 498 */ 499 public abstract Printer visitArray(final String name); 500 501 /** 502 * Annotation end. See {@link jdk.internal.org.objectweb.asm.AnnotationVisitor#visitEnd}. 503 */ 504 public abstract void visitAnnotationEnd(); 505 506 // ------------------------------------------------------------------------ 507 // Fields 508 // ------------------------------------------------------------------------ 509 510 /** 511 * Field annotation. 512 * See {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitAnnotation}. 513 * 514 * @param desc 515 * the class descriptor of the annotation class. 516 * @param visible 517 * <tt>true</tt> if the annotation is visible at runtime. 518 * @return the printer 519 */ 520 public abstract Printer visitFieldAnnotation(final String desc, 521 final boolean visible); 522 523 /** 524 * Field type annotation. 525 * See {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitTypeAnnotation}. 526 * 527 * @param typeRef 528 * a reference to the annotated type. The sort of this type 529 * reference must be {@link jdk.internal.org.objectweb.asm.TypeReference#FIELD FIELD}. 530 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 531 * @param typePath 532 * the path to the annotated type argument, wildcard bound, array 533 * element type, or static inner type within 'typeRef'. May be 534 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 535 * @param desc 536 * the class descriptor of the annotation class. 537 * @param visible 538 * <tt>true</tt> if the annotation is visible at runtime. 539 * @return the printer 540 */ 541 public Printer visitFieldTypeAnnotation(final int typeRef, 542 final TypePath typePath, final String desc, final boolean visible) { 543 throw new RuntimeException("Must be overriden"); 544 } 545 546 /** 547 * Field attribute. 548 * See {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitAttribute}. 549 * 550 * @param attr 551 * an attribute. 552 */ 553 public abstract void visitFieldAttribute(final Attribute attr); 554 555 /** 556 * Field end. 557 * See {@link jdk.internal.org.objectweb.asm.FieldVisitor#visitEnd}. 558 */ 559 public abstract void visitFieldEnd(); 560 561 // ------------------------------------------------------------------------ 562 // Methods 563 // ------------------------------------------------------------------------ 564 565 /** 566 * Method parameter. 567 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitParameter(String, int)}. 568 * 569 * @param name 570 * parameter name or null if none is provided. 571 * @param access 572 * the parameter's access flags, only <tt>ACC_FINAL</tt>, 573 * <tt>ACC_SYNTHETIC</tt> or/and <tt>ACC_MANDATED</tt> are 574 * allowed (see {@link Opcodes}). 575 */ 576 public void visitParameter(String name, int access) { 577 throw new RuntimeException("Must be overriden"); 578 } 579 580 /** 581 * Method default annotation. 582 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAnnotationDefault}. 583 * 584 * @return the printer 585 */ 586 public abstract Printer visitAnnotationDefault(); 587 588 /** 589 * Method annotation. 590 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAnnotation}. 591 * 592 * @param desc 593 * the class descriptor of the annotation class. 594 * @param visible 595 * <tt>true</tt> if the annotation is visible at runtime. 596 * @return the printer 597 */ 598 public abstract Printer visitMethodAnnotation(final String desc, 599 final boolean visible); 600 601 /** 602 * Method type annotation. 603 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTypeAnnotation}. 604 * 605 * @param typeRef 606 * a reference to the annotated type. The sort of this type 607 * reference must be {@link jdk.internal.org.objectweb.asm.TypeReference#FIELD FIELD}. 608 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 609 * @param typePath 610 * the path to the annotated type argument, wildcard bound, array 611 * element type, or static inner type within 'typeRef'. May be 612 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 613 * @param desc 614 * the class descriptor of the annotation class. 615 * @param visible 616 * <tt>true</tt> if the annotation is visible at runtime. 617 * @return the printer 618 */ 619 public Printer visitMethodTypeAnnotation(final int typeRef, 620 final TypePath typePath, final String desc, final boolean visible) { 621 throw new RuntimeException("Must be overriden"); 622 } 623 624 /** 625 * Method parameter annotation. 626 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitParameterAnnotation}. 627 * 628 * @param parameter 629 * the parameter index. 630 * @param desc 631 * the class descriptor of the annotation class. 632 * @param visible 633 * <tt>true</tt> if the annotation is visible at runtime. 634 * @return the printer 635 */ 636 public abstract Printer visitParameterAnnotation(final int parameter, 637 final String desc, final boolean visible); 638 639 /** 640 * Method attribute. 641 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitAttribute}. 642 * 643 * @param attr 644 * an attribute. 645 */ 646 public abstract void visitMethodAttribute(final Attribute attr); 647 648 /** 649 * Method start. 650 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitCode}. 651 */ 652 public abstract void visitCode(); 653 654 /** 655 * Method stack frame. 656 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitFrame}. 657 * 658 * Visits the current state of the local variables and operand stack 659 * elements. This method must(*) be called <i>just before</i> any 660 * instruction <b>i</b> that follows an unconditional branch instruction 661 * such as GOTO or THROW, that is the target of a jump instruction, or that 662 * starts an exception handler block. The visited types must describe the 663 * values of the local variables and of the operand stack elements <i>just 664 * before</i> <b>i</b> is executed.<br> 665 * <br> 666 * (*) this is mandatory only for classes whose version is greater than or 667 * equal to {@link Opcodes#V1_6 V1_6}. <br> 668 * <br> 669 * The frames of a method must be given either in expanded form, or in 670 * compressed form (all frames must use the same format, i.e. you must not 671 * mix expanded and compressed frames within a single method): 672 * <ul> 673 * <li>In expanded form, all frames must have the F_NEW type.</li> 674 * <li>In compressed form, frames are basically "deltas" from the state of 675 * the previous frame: 676 * <ul> 677 * <li>{@link Opcodes#F_SAME} representing frame with exactly the same 678 * locals as the previous frame and with the empty stack.</li> 679 * <li>{@link Opcodes#F_SAME1} representing frame with exactly the same 680 * locals as the previous frame and with single value on the stack ( 681 * <code>nStack</code> is 1 and <code>stack[0]</code> contains value for the 682 * type of the stack item).</li> 683 * <li>{@link Opcodes#F_APPEND} representing frame with current locals are 684 * the same as the locals in the previous frame, except that additional 685 * locals are defined (<code>nLocal</code> is 1, 2 or 3 and 686 * <code>local</code> elements contains values representing added types).</li> 687 * <li>{@link Opcodes#F_CHOP} representing frame with current locals are the 688 * same as the locals in the previous frame, except that the last 1-3 locals 689 * are absent and with the empty stack (<code>nLocals</code> is 1, 2 or 3).</li> 690 * <li>{@link Opcodes#F_FULL} representing complete frame data.</li> 691 * </ul> 692 * </li> 693 * </ul> 694 * <br> 695 * In both cases the first frame, corresponding to the method's parameters 696 * and access flags, is implicit and must not be visited. Also, it is 697 * illegal to visit two or more frames for the same code location (i.e., at 698 * least one instruction must be visited between two calls to visitFrame). 699 * 700 * @param type 701 * the type of this stack map frame. Must be 702 * {@link Opcodes#F_NEW} for expanded frames, or 703 * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND}, 704 * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or 705 * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for 706 * compressed frames. 707 * @param nLocal 708 * the number of local variables in the visited frame. 709 * @param local 710 * the local variable types in this frame. This array must not be 711 * modified. Primitive types are represented by 712 * {@link Opcodes#TOP}, {@link Opcodes#INTEGER}, 713 * {@link Opcodes#FLOAT}, {@link Opcodes#LONG}, 714 * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or 715 * {@link Opcodes#UNINITIALIZED_THIS} (long and double are 716 * represented by a single element). Reference types are 717 * represented by String objects (representing internal names), 718 * and uninitialized types by Label objects (this label 719 * designates the NEW instruction that created this uninitialized 720 * value). 721 * @param nStack 722 * the number of operand stack elements in the visited frame. 723 * @param stack 724 * the operand stack types in this frame. This array must not be 725 * modified. Its content has the same format as the "local" 726 * array. 727 * @throws IllegalStateException 728 * if a frame is visited just after another one, without any 729 * instruction between the two (unless this frame is a 730 * Opcodes#F_SAME frame, in which case it is silently ignored). 731 */ 732 public abstract void visitFrame(final int type, final int nLocal, 733 final Object[] local, final int nStack, final Object[] stack); 734 735 /** 736 * Method instruction. 737 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInsn} 738 * 739 * @param opcode 740 * the opcode of the instruction to be visited. This opcode is 741 * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, 742 * ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, 743 * FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, 744 * LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, 745 * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, 746 * SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, 747 * DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, 748 * IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, 749 * FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, 750 * IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, 751 * L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, 752 * LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN, 753 * DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, 754 * or MONITOREXIT. 755 */ 756 public abstract void visitInsn(final int opcode); 757 758 /** 759 * Method instruction. 760 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIntInsn}. 761 * 762 * @param opcode 763 * the opcode of the instruction to be visited. This opcode is 764 * either BIPUSH, SIPUSH or NEWARRAY. 765 * @param operand 766 * the operand of the instruction to be visited.<br> 767 * When opcode is BIPUSH, operand value should be between 768 * Byte.MIN_VALUE and Byte.MAX_VALUE.<br> 769 * When opcode is SIPUSH, operand value should be between 770 * Short.MIN_VALUE and Short.MAX_VALUE.<br> 771 * When opcode is NEWARRAY, operand value should be one of 772 * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR}, 773 * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE}, 774 * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT}, 775 * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}. 776 */ 777 public abstract void visitIntInsn(final int opcode, final int operand); 778 779 /** 780 * Method instruction. 781 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitVarInsn}. 782 * 783 * @param opcode 784 * the opcode of the local variable instruction to be visited. 785 * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, 786 * ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET. 787 * @param var 788 * the operand of the instruction to be visited. This operand is 789 * the index of a local variable. 790 */ 791 public abstract void visitVarInsn(final int opcode, final int var); 792 793 /** 794 * Method instruction. 795 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTypeInsn}. 796 * 797 /** 798 * Visits a type instruction. A type instruction is an instruction that 799 * takes the internal name of a class as parameter. 800 * 801 * @param opcode 802 * the opcode of the type instruction to be visited. This opcode 803 * is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. 804 * @param type 805 * the operand of the instruction to be visited. This operand 806 * must be the internal name of an object or array class (see 807 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 808 */ 809 public abstract void visitTypeInsn(final int opcode, final String type); 810 811 /** 812 * Method instruction. 813 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitFieldInsn}. 814 * 815 * @param opcode 816 * the opcode of the type instruction to be visited. This opcode 817 * is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD. 818 * @param owner 819 * the internal name of the field's owner class (see 820 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 821 * @param name 822 * the field's name. 823 * @param desc 824 * the field's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 825 */ 826 public abstract void visitFieldInsn(final int opcode, final String owner, 827 final String name, final String desc); 828 829 /** 830 * Method instruction. 831 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMethodInsn}. 832 * 833 * @param opcode 834 * the opcode of the type instruction to be visited. This opcode 835 * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or 836 * INVOKEINTERFACE. 837 * @param owner 838 * the internal name of the method's owner class (see 839 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 840 * @param name 841 * the method's name. 842 * @param desc 843 * the method's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 844 */ 845 @Deprecated 846 public void visitMethodInsn(final int opcode, final String owner, 847 final String name, final String desc) { 848 if (api >= Opcodes.ASM5) { 849 boolean itf = opcode == Opcodes.INVOKEINTERFACE; 850 visitMethodInsn(opcode, owner, name, desc, itf); 851 return; 852 } 853 throw new RuntimeException("Must be overriden"); 854 } 855 856 /** 857 * Method instruction. 858 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMethodInsn}. 859 * 860 * @param opcode 861 * the opcode of the type instruction to be visited. This opcode 862 * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or 863 * INVOKEINTERFACE. 864 * @param owner 865 * the internal name of the method's owner class (see 866 * {@link jdk.internal.org.objectweb.asm.Type#getInternalName() getInternalName}). 867 * @param name 868 * the method's name. 869 * @param desc 870 * the method's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 871 * @param itf 872 * if the method's owner class is an interface. 873 */ 874 public void visitMethodInsn(final int opcode, final String owner, 875 final String name, final String desc, final boolean itf) { 876 if (api < Opcodes.ASM5) { 877 if (itf != (opcode == Opcodes.INVOKEINTERFACE)) { 878 throw new IllegalArgumentException( 879 "INVOKESPECIAL/STATIC on interfaces require ASM 5"); 880 } 881 visitMethodInsn(opcode, owner, name, desc); 882 return; 883 } 884 throw new RuntimeException("Must be overriden"); 885 } 886 887 /** 888 * Method instruction. 889 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn}. 890 * 891 * Visits an invokedynamic instruction. 892 * 893 * @param name 894 * the method's name. 895 * @param desc 896 * the method's descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 897 * @param bsm 898 * the bootstrap method. 899 * @param bsmArgs 900 * the bootstrap method constant arguments. Each argument must be 901 * an {@link Integer}, {@link Float}, {@link Long}, 902 * {@link Double}, {@link String}, {@link jdk.internal.org.objectweb.asm.Type} or {@link Handle} 903 * value. This method is allowed to modify the content of the 904 * array so a caller should expect that this array may change. 905 */ 906 public abstract void visitInvokeDynamicInsn(String name, String desc, 907 Handle bsm, Object... bsmArgs); 908 909 /** 910 * Method jump instruction. 911 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitJumpInsn}. 912 * 913 * @param opcode 914 * the opcode of the type instruction to be visited. This opcode 915 * is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, 916 * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, 917 * IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. 918 * @param label 919 * the operand of the instruction to be visited. This operand is 920 * a label that designates the instruction to which the jump 921 * instruction may jump. 922 */ 923 public abstract void visitJumpInsn(final int opcode, final Label label); 924 925 /** 926 * Method label. 927 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLabel}. 928 * 929 * @param label 930 * a {@link Label Label} object. 931 */ 932 public abstract void visitLabel(final Label label); 933 934 /** 935 * Method instruction. 936 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLdcInsn}. 937 * 938 * Visits a LDC instruction. Note that new constant types may be added in 939 * future versions of the Java Virtual Machine. To easily detect new 940 * constant types, implementations of this method should check for 941 * unexpected constant types, like this: 942 * 943 * <pre> 944 * if (cst instanceof Integer) { 945 * // ... 946 * } else if (cst instanceof Float) { 947 * // ... 948 * } else if (cst instanceof Long) { 949 * // ... 950 * } else if (cst instanceof Double) { 951 * // ... 952 * } else if (cst instanceof String) { 953 * // ... 954 * } else if (cst instanceof Type) { 955 * int sort = ((Type) cst).getSort(); 956 * if (sort == Type.OBJECT) { 957 * // ... 958 * } else if (sort == Type.ARRAY) { 959 * // ... 960 * } else if (sort == Type.METHOD) { 961 * // ... 962 * } else { 963 * // throw an exception 964 * } 965 * } else if (cst instanceof Handle) { 966 * // ... 967 * } else { 968 * // throw an exception 969 * } 970 * </pre> 971 * 972 * @param cst 973 * the constant to be loaded on the stack. This parameter must be 974 * a non null {@link Integer}, a {@link Float}, a {@link Long}, a 975 * {@link Double}, a {@link String}, a {@link jdk.internal.org.objectweb.asm.Type} 976 * of OBJECT or ARRAY sort for <tt>.class</tt> constants, for classes whose 977 * version is 49.0, a {@link jdk.internal.org.objectweb.asm.Type} of METHOD sort or a 978 * {@link Handle} for MethodType and MethodHandle constants, for 979 * classes whose version is 51.0. 980 */ 981 public abstract void visitLdcInsn(final Object cst); 982 983 /** 984 * Method instruction. 985 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitIincInsn}. 986 * 987 * @param var 988 * index of the local variable to be incremented. 989 * @param increment 990 * amount to increment the local variable by. 991 */ 992 public abstract void visitIincInsn(final int var, final int increment); 993 994 /** 995 * Method instruction. 996 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTableSwitchInsn}. 997 * 998 * @param min 999 * the minimum key value. 1000 * @param max 1001 * the maximum key value. 1002 * @param dflt 1003 * beginning of the default handler block. 1004 * @param labels 1005 * beginnings of the handler blocks. <tt>labels[i]</tt> is the 1006 * beginning of the handler block for the <tt>min + i</tt> key. 1007 */ 1008 public abstract void visitTableSwitchInsn(final int min, final int max, 1009 final Label dflt, final Label... labels); 1010 1011 /** 1012 * Method instruction. 1013 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn}. 1014 * 1015 * @param dflt 1016 * beginning of the default handler block. 1017 * @param keys 1018 * the values of the keys. 1019 * @param labels 1020 * beginnings of the handler blocks. <tt>labels[i]</tt> is the 1021 * beginning of the handler block for the <tt>keys[i]</tt> key. 1022 */ 1023 public abstract void visitLookupSwitchInsn(final Label dflt, 1024 final int[] keys, final Label[] labels); 1025 1026 /** 1027 * Method instruction. 1028 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn}. 1029 * 1030 * @param desc 1031 * an array type descriptor (see {@link jdk.internal.org.objectweb.asm.Type Type}). 1032 * @param dims 1033 * number of dimensions of the array to allocate. 1034 */ 1035 public abstract void visitMultiANewArrayInsn(final String desc, 1036 final int dims); 1037 1038 /** 1039 * Instruction type annotation. 1040 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitInsnAnnotation}. 1041 * 1042 * @param typeRef 1043 * a reference to the annotated type. The sort of this type 1044 * reference must be {@link jdk.internal.org.objectweb.asm.TypeReference#INSTANCEOF INSTANCEOF}, 1045 * {@link jdk.internal.org.objectweb.asm.TypeReference#NEW NEW}, 1046 * {@link jdk.internal.org.objectweb.asm.TypeReference#CONSTRUCTOR_REFERENCE CONSTRUCTOR_REFERENCE}, 1047 * {@link jdk.internal.org.objectweb.asm.TypeReference#METHOD_REFERENCE METHOD_REFERENCE}, 1048 * {@link jdk.internal.org.objectweb.asm.TypeReference#CAST CAST}, 1049 * {@link jdk.internal.org.objectweb.asm.TypeReference#CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT}, 1050 * {@link jdk.internal.org.objectweb.asm.TypeReference#METHOD_INVOCATION_TYPE_ARGUMENT METHOD_INVOCATION_TYPE_ARGUMENT}, 1051 * {@link jdk.internal.org.objectweb.asm.TypeReference#CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT}, 1052 * or {@link jdk.internal.org.objectweb.asm.TypeReference#METHOD_REFERENCE_TYPE_ARGUMENT METHOD_REFERENCE_TYPE_ARGUMENT}. 1053 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 1054 * @param typePath 1055 * the path to the annotated type argument, wildcard bound, array 1056 * element type, or static inner type within 'typeRef'. May be 1057 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 1058 * @param desc 1059 * the class descriptor of the annotation class. 1060 * @param visible 1061 * <tt>true</tt> if the annotation is visible at runtime. 1062 * @return the printer 1063 */ 1064 public Printer visitInsnAnnotation(final int typeRef, 1065 final TypePath typePath, final String desc, final boolean visible) { 1066 throw new RuntimeException("Must be overriden"); 1067 } 1068 1069 /** 1070 * Method exception handler. 1071 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchBlock}. 1072 * 1073 * @param start 1074 * beginning of the exception handler's scope (inclusive). 1075 * @param end 1076 * end of the exception handler's scope (exclusive). 1077 * @param handler 1078 * beginning of the exception handler's code. 1079 * @param type 1080 * internal name of the type of exceptions handled by the 1081 * handler, or <tt>null</tt> to catch any exceptions (for 1082 * "finally" blocks). 1083 * @throws IllegalArgumentException 1084 * if one of the labels has already been visited by this visitor 1085 * (by the {@link #visitLabel visitLabel} method). 1086 */ 1087 public abstract void visitTryCatchBlock(final Label start, final Label end, 1088 final Label handler, final String type); 1089 1090 /** 1091 * Try catch block type annotation. 1092 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchAnnotation}. 1093 * 1094 * @param typeRef 1095 * a reference to the annotated type. The sort of this type 1096 * reference must be {@link jdk.internal.org.objectweb.asm.TypeReference#EXCEPTION_PARAMETER 1097 * EXCEPTION_PARAMETER}. 1098 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 1099 * @param typePath 1100 * the path to the annotated type argument, wildcard bound, array 1101 * element type, or static inner type within 'typeRef'. May be 1102 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 1103 * @param desc 1104 * the class descriptor of the annotation class. 1105 * @param visible 1106 * <tt>true</tt> if the annotation is visible at runtime. 1107 * @return the printer 1108 */ 1109 public Printer visitTryCatchAnnotation(final int typeRef, 1110 final TypePath typePath, final String desc, final boolean visible) { 1111 throw new RuntimeException("Must be overriden"); 1112 } 1113 1114 /** 1115 * Method debug info. 1116 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLocalVariable}. 1117 * 1118 * @param name 1119 * the name of a local variable. 1120 * @param desc 1121 * the type descriptor of this local variable. 1122 * @param signature 1123 * the type signature of this local variable. May be 1124 * <tt>null</tt> if the local variable type does not use generic 1125 * types. 1126 * @param start 1127 * the first instruction corresponding to the scope of this local 1128 * variable (inclusive). 1129 * @param end 1130 * the last instruction corresponding to the scope of this local 1131 * variable (exclusive). 1132 * @param index 1133 * the local variable's index. 1134 * @throws IllegalArgumentException 1135 * if one of the labels has not already been visited by this 1136 * visitor (by the {@link #visitLabel visitLabel} method). 1137 */ 1138 public abstract void visitLocalVariable(final String name, 1139 final String desc, final String signature, final Label start, 1140 final Label end, final int index); 1141 1142 /** 1143 * Local variable type annotation. 1144 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitTryCatchAnnotation}. 1145 * 1146 * @param typeRef 1147 * a reference to the annotated type. The sort of this type 1148 * reference must be {@link jdk.internal.org.objectweb.asm.TypeReference#LOCAL_VARIABLE 1149 * LOCAL_VARIABLE} or {@link jdk.internal.org.objectweb.asm.TypeReference#RESOURCE_VARIABLE 1150 * RESOURCE_VARIABLE}. 1151 * See {@link jdk.internal.org.objectweb.asm.TypeReference}. 1152 * @param typePath 1153 * the path to the annotated type argument, wildcard bound, array 1154 * element type, or static inner type within 'typeRef'. May be 1155 * <tt>null</tt> if the annotation targets 'typeRef' as a whole. 1156 * @param start 1157 * the fist instructions corresponding to the continuous ranges 1158 * that make the scope of this local variable (inclusive). 1159 * @param end 1160 * the last instructions corresponding to the continuous ranges 1161 * that make the scope of this local variable (exclusive). This 1162 * array must have the same size as the 'start' array. 1163 * @param index 1164 * the local variable's index in each range. This array must have 1165 * the same size as the 'start' array. 1166 * @param desc 1167 * the class descriptor of the annotation class. 1168 * @param visible 1169 * <tt>true</tt> if the annotation is visible at runtime. 1170 * @return the printer 1171 */ 1172 public Printer visitLocalVariableAnnotation(final int typeRef, 1173 final TypePath typePath, final Label[] start, final Label[] end, 1174 final int[] index, final String desc, final boolean visible) { 1175 throw new RuntimeException("Must be overriden"); 1176 } 1177 1178 /** 1179 * Method debug info. 1180 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitLineNumber}. 1181 * 1182 * @param line 1183 * a line number. This number refers to the source file from 1184 * which the class was compiled. 1185 * @param start 1186 * the first instruction corresponding to this line number. 1187 * @throws IllegalArgumentException 1188 * if <tt>start</tt> has not already been visited by this 1189 * visitor (by the {@link #visitLabel visitLabel} method). 1190 */ 1191 public abstract void visitLineNumber(final int line, final Label start); 1192 1193 /** 1194 * Method max stack and max locals. 1195 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitMaxs}. 1196 * 1197 * @param maxStack 1198 * maximum stack size of the method. 1199 * @param maxLocals 1200 * maximum number of local variables for the method. 1201 */ 1202 public abstract void visitMaxs(final int maxStack, final int maxLocals); 1203 1204 /** 1205 * Method end. 1206 * See {@link jdk.internal.org.objectweb.asm.MethodVisitor#visitEnd}. 1207 */ 1208 public abstract void visitMethodEnd(); 1209 1210 /** 1211 * Returns the text constructed by this visitor. 1212 * 1213 * @return the text constructed by this visitor. 1214 */ 1215 public List<Object> getText() { 1216 return text; 1217 } 1218 1219 /** 1220 * Prints the text constructed by this visitor. 1221 * 1222 * @param pw 1223 * the print writer to be used. 1224 */ 1225 public void print(final PrintWriter pw) { 1226 printList(pw, text); 1227 } 1228 1229 /** 1230 * Appends a quoted string to a given buffer. 1231 * 1232 * @param buf 1233 * the buffer where the string must be added. 1234 * @param s 1235 * the string to be added. 1236 */ 1237 public static void appendString(final StringBuffer buf, final String s) { 1238 buf.append('\"'); 1239 for (int i = 0; i < s.length(); ++i) { 1240 char c = s.charAt(i); 1241 if (c == '\n') { 1242 buf.append("\\n"); 1243 } else if (c == '\r') { 1244 buf.append("\\r"); 1245 } else if (c == '\\') { 1246 buf.append("\\\\"); 1247 } else if (c == '"') { 1248 buf.append("\\\""); 1249 } else if (c < 0x20 || c > 0x7f) { 1250 buf.append("\\u"); 1251 if (c < 0x10) { 1252 buf.append("000"); 1253 } else if (c < 0x100) { 1254 buf.append("00"); 1255 } else if (c < 0x1000) { 1256 buf.append('0'); 1257 } 1258 buf.append(Integer.toString(c, 16)); 1259 } else { 1260 buf.append(c); 1261 } 1262 } 1263 buf.append('\"'); 1264 } 1265 1266 /** 1267 * Prints the given string tree. 1268 * 1269 * @param pw 1270 * the writer to be used to print the tree. 1271 * @param l 1272 * a string tree, i.e., a string list that can contain other 1273 * string lists, and so on recursively. 1274 */ 1275 static void printList(final PrintWriter pw, final List<?> l) { 1276 for (int i = 0; i < l.size(); ++i) { 1277 Object o = l.get(i); 1278 if (o instanceof List) { 1279 printList(pw, (List<?>) o); 1280 } else { 1281 pw.print(o.toString()); 1282 } 1283 } 1284 } 1285 }