01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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, int access, String name,
29: String signature, String super Name, String[] interfaces) {
30: cv1.visit(version, access, name, signature, super Name,
31: interfaces);
32: cv2.visit(version, access, name, signature, super Name,
33: interfaces);
34: }
35:
36: public void visitEnd() {
37: cv1.visitEnd();
38: cv2.visitEnd();
39: cv1 = cv2 = null;
40: }
41:
42: public void visitInnerClass(String name, String outerName,
43: String innerName, int access) {
44: cv1.visitInnerClass(name, outerName, innerName, access);
45: cv2.visitInnerClass(name, outerName, innerName, access);
46: }
47:
48: public FieldVisitor visitField(int access, String name,
49: String desc, String signature, Object value) {
50: FieldVisitor fv1 = cv1.visitField(access, name, desc,
51: signature, value);
52: FieldVisitor fv2 = cv2.visitField(access, name, desc,
53: signature, value);
54: if (fv1 == null)
55: return fv2;
56: if (fv2 == null)
57: return fv1;
58: return new FieldVisitorTee(fv1, fv2);
59: }
60:
61: public MethodVisitor visitMethod(int access, String name,
62: String desc, String signature, String[] exceptions) {
63: MethodVisitor mv1 = cv1.visitMethod(access, name, desc,
64: signature, exceptions);
65: MethodVisitor mv2 = cv2.visitMethod(access, name, desc,
66: signature, exceptions);
67: if (mv1 == null)
68: return mv2;
69: if (mv2 == null)
70: return mv1;
71: return new MethodVisitorTee(mv1, mv2);
72: }
73:
74: public void visitSource(String source, String debug) {
75: cv1.visitSource(source, debug);
76: cv2.visitSource(source, debug);
77: }
78:
79: public void visitOuterClass(String owner, String name, String desc) {
80: cv1.visitOuterClass(owner, name, desc);
81: cv2.visitOuterClass(owner, name, desc);
82: }
83:
84: public AnnotationVisitor visitAnnotation(String desc,
85: boolean visible) {
86: return AnnotationVisitorTee.getInstance(cv1.visitAnnotation(
87: desc, visible), cv2.visitAnnotation(desc, visible));
88: }
89:
90: public void visitAttribute(Attribute attrs) {
91: cv1.visitAttribute(attrs);
92: cv2.visitAttribute(attrs);
93: }
94: }
|