1 30 package org.objectweb.asm.tree; 31 32 import org.objectweb.asm.Attribute; 33 import org.objectweb.asm.ClassVisitor; 34 import org.objectweb.asm.MethodVisitor; 35 import org.objectweb.asm.FieldVisitor; 36 37 import java.util.List ; 38 import java.util.ArrayList ; 39 import java.util.Arrays ; 40 41 46 public class ClassNode extends MemberNode implements ClassVisitor { 47 48 51 public int version; 52 53 57 public int access; 58 59 63 public String name; 64 65 68 public String signature; 69 70 76 public String superName; 77 78 83 public final List interfaces; 84 85 89 public String sourceFile; 90 91 95 public String sourceDebug; 96 97 101 public String outerClass; 102 103 107 public String outerMethod; 108 109 113 public String outerMethodDesc; 114 115 121 public final List innerClasses; 122 123 129 public final List fields; 130 131 137 public final List methods; 138 139 142 public ClassNode() { 143 this.interfaces = new ArrayList (); 144 this.innerClasses = new ArrayList (); 145 this.fields = new ArrayList (); 146 this.methods = new ArrayList (); 147 } 148 149 153 public void visit( 154 final int version, 155 final int access, 156 final String name, 157 final String signature, 158 final String superName, 159 final String [] interfaces) 160 { 161 this.version = version; 162 this.access = access; 163 this.name = name; 164 this.signature = signature; 165 this.superName = superName; 166 if (interfaces != null) { 167 this.interfaces.addAll(Arrays.asList(interfaces)); 168 } 169 } 170 171 public void visitSource(final String file, final String debug) { 172 sourceFile = file; 173 sourceDebug = debug; 174 } 175 176 public void visitOuterClass( 177 final String owner, 178 final String name, 179 final String desc) 180 { 181 outerClass = owner; 182 outerMethod = name; 183 outerMethodDesc = desc; 184 } 185 186 public void visitInnerClass( 187 final String name, 188 final String outerName, 189 final String innerName, 190 final int access) 191 { 192 InnerClassNode icn = new InnerClassNode(name, 193 outerName, 194 innerName, 195 access); 196 innerClasses.add(icn); 197 } 198 199 public FieldVisitor visitField( 200 final int access, 201 final String name, 202 final String desc, 203 final String signature, 204 final Object value) 205 { 206 FieldNode fn = new FieldNode(access, name, desc, signature, value); 207 fields.add(fn); 208 return fn; 209 } 210 211 public MethodVisitor visitMethod( 212 final int access, 213 final String name, 214 final String desc, 215 final String signature, 216 final String [] exceptions) 217 { 218 MethodNode mn = new MethodNode(access, 219 name, 220 desc, 221 signature, 222 exceptions); 223 methods.add(mn); 224 return mn; 225 } 226 227 public void visitEnd() { 228 } 229 230 234 239 public void accept(final ClassVisitor cv) { 240 String [] interfaces = new String [this.interfaces.size()]; 242 this.interfaces.toArray(interfaces); 243 cv.visit(version, access, name, signature, superName, interfaces); 244 if (sourceFile != null || sourceDebug != null) { 246 cv.visitSource(sourceFile, sourceDebug); 247 } 248 if (outerClass != null) { 250 cv.visitOuterClass(outerClass, outerMethod, outerMethodDesc); 251 } 252 int i, n; 254 n = visibleAnnotations == null ? 0 : visibleAnnotations.size(); 255 for (i = 0; i < n; ++i) { 256 AnnotationNode an = (AnnotationNode) visibleAnnotations.get(i); 257 an.accept(cv.visitAnnotation(an.desc, true)); 258 } 259 n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size(); 260 for (i = 0; i < n; ++i) { 261 AnnotationNode an = (AnnotationNode) invisibleAnnotations.get(i); 262 an.accept(cv.visitAnnotation(an.desc, false)); 263 } 264 n = attrs == null ? 0 : attrs.size(); 265 for (i = 0; i < n; ++i) { 266 cv.visitAttribute((Attribute) attrs.get(i)); 267 } 268 for (i = 0; i < innerClasses.size(); ++i) { 270 ((InnerClassNode) innerClasses.get(i)).accept(cv); 271 } 272 for (i = 0; i < fields.size(); ++i) { 274 ((FieldNode) fields.get(i)).accept(cv); 275 } 276 for (i = 0; i < methods.size(); ++i) { 278 ((MethodNode) methods.get(i)).accept(cv); 279 } 280 cv.visitEnd(); 282 } 283 } 284 | Popular Tags |