1 30 package org.objectweb.asm.optimizer; 31 32 import org.objectweb.asm.AnnotationVisitor; 33 import org.objectweb.asm.Label; 34 import org.objectweb.asm.MethodAdapter; 35 import org.objectweb.asm.MethodVisitor; 36 import org.objectweb.asm.Opcodes; 37 38 44 public class MethodConstantsCollector extends MethodAdapter { 45 46 private ConstantPool cp; 47 48 public MethodConstantsCollector( 49 final MethodVisitor mv, 50 final ConstantPool cp) 51 { 52 super(mv); 53 this.cp = cp; 54 } 55 56 public AnnotationVisitor visitAnnotationDefault() { 57 cp.newUTF8("AnnotationDefault"); 58 return new AnnotationConstantsCollector(mv.visitAnnotationDefault(), cp); 59 } 60 61 public AnnotationVisitor visitAnnotation( 62 final String desc, 63 final boolean visible) 64 { 65 cp.newUTF8(desc); 66 if (visible) { 67 cp.newUTF8("RuntimeVisibleAnnotations"); 68 } else { 69 cp.newUTF8("RuntimeInvisibleAnnotations"); 70 } 71 return new AnnotationConstantsCollector(mv.visitAnnotation(desc, 72 visible), cp); 73 } 74 75 public AnnotationVisitor visitParameterAnnotation( 76 final int parameter, 77 final String desc, 78 final boolean visible) 79 { 80 cp.newUTF8(desc); 81 if (visible) { 82 cp.newUTF8("RuntimeVisibleParameterAnnotations"); 83 } else { 84 cp.newUTF8("RuntimeInvisibleParameterAnnotations"); 85 } 86 return new AnnotationConstantsCollector(mv.visitParameterAnnotation(parameter, 87 desc, 88 visible), 89 cp); 90 } 91 92 public void visitTypeInsn(final int opcode, final String desc) { 93 cp.newClass(desc); 94 mv.visitTypeInsn(opcode, desc); 95 } 96 97 public void visitFieldInsn( 98 final int opcode, 99 final String owner, 100 final String name, 101 final String desc) 102 { 103 cp.newField(owner, name, desc); 104 mv.visitFieldInsn(opcode, owner, name, desc); 105 } 106 107 public void visitMethodInsn( 108 final int opcode, 109 final String owner, 110 final String name, 111 final String desc) 112 { 113 boolean itf = opcode == Opcodes.INVOKEINTERFACE; 114 cp.newMethod(owner, name, desc, itf); 115 mv.visitMethodInsn(opcode, owner, name, desc); 116 } 117 118 public void visitLdcInsn(final Object cst) { 119 cp.newConst(cst); 120 mv.visitLdcInsn(cst); 121 } 122 123 public void visitMultiANewArrayInsn(final String desc, final int dims) { 124 cp.newClass(desc); 125 mv.visitMultiANewArrayInsn(desc, dims); 126 } 127 128 public void visitTryCatchBlock( 129 final Label start, 130 final Label end, 131 final Label handler, 132 final String type) 133 { 134 if (type != null) { 135 cp.newClass(type); 136 } 137 mv.visitTryCatchBlock(start, end, handler, type); 138 } 139 140 public void visitLocalVariable( 141 final String name, 142 final String desc, 143 final String signature, 144 final Label start, 145 final Label end, 146 final int index) 147 { 148 if (signature != null) { 149 cp.newUTF8("LocalVariableTypeTable"); 150 cp.newUTF8(name); 151 cp.newUTF8(signature); 152 } 153 cp.newUTF8("LocalVariableTable"); 154 cp.newUTF8(name); 155 cp.newUTF8(desc); 156 mv.visitLocalVariable(name, desc, signature, start, end, index); 157 } 158 159 public void visitLineNumber(final int line, final Label start) { 160 cp.newUTF8("LineNumberTable"); 161 mv.visitLineNumber(line, start); 162 } 163 164 public void visitMaxs(final int maxStack, final int maxLocals) { 165 cp.newUTF8("Code"); 166 mv.visitMaxs(maxStack, maxLocals); 167 } 168 } 169 | Popular Tags |