1 30 package org.objectweb.asm.optimizer; 31 32 import org.objectweb.asm.AnnotationVisitor; 33 import org.objectweb.asm.Attribute; 34 import org.objectweb.asm.ClassAdapter; 35 import org.objectweb.asm.ClassVisitor; 36 import org.objectweb.asm.FieldVisitor; 37 import org.objectweb.asm.MethodVisitor; 38 import org.objectweb.asm.Opcodes; 39 40 46 public class ClassConstantsCollector extends ClassAdapter { 47 48 private ConstantPool cp; 49 50 public ClassConstantsCollector(final ClassVisitor cv, final ConstantPool cp) 51 { 52 super(cv); 53 this.cp = cp; 54 } 55 56 public void visit( 57 final int version, 58 final int access, 59 final String name, 60 final String signature, 61 final String superName, 62 final String [] interfaces) 63 { 64 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 65 cp.newUTF8("Deprecated"); 66 } 67 if ((access & Opcodes.ACC_SYNTHETIC) != 0) { 68 cp.newUTF8("Synthetic"); 69 } 70 cp.newClass(name); 71 if (signature != null) { 72 cp.newUTF8("Signature"); 73 cp.newUTF8(signature); 74 } 75 if (superName != null) { 76 cp.newClass(superName); 77 } 78 if (interfaces != null) { 79 for (int i = 0; i < interfaces.length; ++i) { 80 cp.newClass(interfaces[i]); 81 } 82 } 83 cv.visit(version, access, name, signature, superName, interfaces); 84 } 85 86 public void visitSource(final String source, final String debug) { 87 if (source != null) { 88 cp.newUTF8("SourceFile"); 89 cp.newUTF8(source); 90 } 91 if (debug != null) { 92 cp.newUTF8("SourceDebugExtension"); 93 } 94 cv.visitSource(source, debug); 95 } 96 97 public void visitOuterClass( 98 final String owner, 99 final String name, 100 final String desc) 101 { 102 cp.newUTF8("EnclosingMethod"); 103 cp.newClass(owner); 104 if (name != null && desc != null) { 105 cp.newNameType(name, desc); 106 } 107 cv.visitOuterClass(owner, name, desc); 108 } 109 110 public AnnotationVisitor visitAnnotation( 111 final String desc, 112 final boolean visible) 113 { 114 cp.newUTF8(desc); 115 if (visible) { 116 cp.newUTF8("RuntimeVisibleAnnotations"); 117 } else { 118 cp.newUTF8("RuntimeInvisibleAnnotations"); 119 } 120 return new AnnotationConstantsCollector(cv.visitAnnotation(desc, 121 visible), cp); 122 } 123 124 public void visitAttribute(final Attribute attr) { 125 cv.visitAttribute(attr); 127 } 128 129 public void visitInnerClass( 130 final String name, 131 final String outerName, 132 final String innerName, 133 final int access) 134 { 135 cp.newUTF8("InnerClasses"); 136 if (name != null) { 137 cp.newClass(name); 138 } 139 if (outerName != null) { 140 cp.newClass(outerName); 141 } 142 if (innerName != null) { 143 cp.newClass(innerName); 144 } 145 cv.visitInnerClass(name, outerName, innerName, access); 146 } 147 148 public FieldVisitor visitField( 149 final int access, 150 final String name, 151 final String desc, 152 final String signature, 153 final Object value) 154 { 155 if ((access & Opcodes.ACC_SYNTHETIC) != 0) { 156 cp.newUTF8("Synthetic"); 157 } 158 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 159 cp.newUTF8("Deprecated"); 160 } 161 cp.newUTF8(name); 162 cp.newUTF8(desc); 163 if (signature != null) { 164 cp.newUTF8("Signature"); 165 cp.newUTF8(signature); 166 } 167 if (value != null) { 168 cp.newConst(value); 169 } 170 return new FieldConstantsCollector(cv.visitField(access, 171 name, 172 desc, 173 signature, 174 value), cp); 175 } 176 177 public MethodVisitor visitMethod( 178 final int access, 179 final String name, 180 final String desc, 181 final String signature, 182 final String [] exceptions) 183 { 184 if ((access & Opcodes.ACC_SYNTHETIC) != 0) { 185 cp.newUTF8("Synthetic"); 186 } 187 if ((access & Opcodes.ACC_DEPRECATED) != 0) { 188 cp.newUTF8("Deprecated"); 189 } 190 cp.newUTF8(name); 191 cp.newUTF8(desc); 192 if (signature != null) { 193 cp.newUTF8("Signature"); 194 cp.newUTF8(signature); 195 } 196 if (exceptions != null) { 197 cp.newUTF8("Exceptions"); 198 for (int i = 0; i < exceptions.length; ++i) { 199 cp.newClass(exceptions[i]); 200 } 201 } 202 return new MethodConstantsCollector(cv.visitMethod(access, 203 name, 204 desc, 205 signature, 206 exceptions), cp); 207 } 208 209 public void visitEnd() { 210 cv.visitEnd(); 211 } 212 } 213 | Popular Tags |