1 16 package net.sf.cglib.transform; 17 18 import org.objectweb.asm.*; 19 20 public class ClassVisitorTee implements ClassVisitor { 21 private ClassVisitor cv1, cv2; 22 23 public ClassVisitorTee(ClassVisitor cv1, ClassVisitor cv2) { 24 this.cv1 = cv1; 25 this.cv2 = cv2; 26 } 27 28 public void visit(int version, 29 int access, 30 String name, 31 String signature, 32 String superName, 33 String [] interfaces) { 34 cv1.visit(version, access, name, signature, superName, interfaces); 35 cv2.visit(version, access, name, signature, superName, interfaces); 36 } 37 38 public void visitEnd() { 39 cv1.visitEnd(); 40 cv2.visitEnd(); 41 cv1 = cv2 = null; 42 } 43 44 public void visitInnerClass(String name, String outerName, String innerName, int access) { 45 cv1.visitInnerClass(name, outerName, innerName, access); 46 cv2.visitInnerClass(name, outerName, innerName, access); 47 } 48 49 public FieldVisitor visitField(int access, 50 String name, 51 String desc, 52 String signature, 53 Object value) { 54 FieldVisitor fv1 = cv1.visitField(access, name, desc, signature, value); 55 FieldVisitor fv2 = cv2.visitField(access, name, desc, signature, value); 56 if (fv1 == null) 57 return fv2; 58 if (fv2 == null) 59 return fv1; 60 return new FieldVisitorTee(fv1, fv2); 61 } 62 63 64 public MethodVisitor visitMethod(int access, 65 String name, 66 String desc, 67 String signature, 68 String [] exceptions) { 69 MethodVisitor mv1 = cv1.visitMethod(access, name, desc, signature, exceptions); 70 MethodVisitor mv2 = cv2.visitMethod(access, name, desc, signature, exceptions); 71 if (mv1 == null) 72 return mv2; 73 if (mv2 == null) 74 return mv1; 75 return new MethodVisitorTee(mv1, mv2); 76 } 77 78 public void visitSource(String source, String debug) { 79 cv1.visitSource(source, debug); 80 cv2.visitSource(source, debug); 81 } 82 83 public void visitOuterClass(String owner, String name, String desc) { 84 cv1.visitOuterClass(owner, name, desc); 85 cv2.visitOuterClass(owner, name, desc); 86 } 87 88 public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 89 return AnnotationVisitorTee.getInstance(cv1.visitAnnotation(desc, visible), 90 cv2.visitAnnotation(desc, visible)); 91 } 92 93 public void visitAttribute(Attribute attrs) { 94 cv1.visitAttribute(attrs); 95 cv2.visitAttribute(attrs); 96 } 97 } 98 | Popular Tags |