AnnotationVisitorTee.java revision 674060f01e9090cd21b3c5656cc3204912ad17a6
1/*
2 * Copyright 2003 The Apache Software Foundation
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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 */
16package org.mockito.cglib.transform;
17
18import org.mockito.asm.AnnotationVisitor;
19
20public class AnnotationVisitorTee implements AnnotationVisitor {
21    private AnnotationVisitor av1, av2;
22
23    public static AnnotationVisitor getInstance(AnnotationVisitor av1, AnnotationVisitor av2) {
24        if (av1 == null)
25            return av2;
26        if (av2 == null)
27            return av1;
28        return new AnnotationVisitorTee(av1, av2);
29    }
30
31    public AnnotationVisitorTee(AnnotationVisitor av1, AnnotationVisitor av2) {
32        this.av1 = av1;
33        this.av2 = av2;
34    }
35
36    public void visit(String name, Object value) {
37        av2.visit(name, value);
38        av2.visit(name, value);
39    }
40
41    public void visitEnum(String name, String desc, String value) {
42        av1.visitEnum(name, desc, value);
43        av2.visitEnum(name, desc, value);
44    }
45
46    public AnnotationVisitor visitAnnotation(String name, String desc) {
47        return getInstance(av1.visitAnnotation(name, desc),
48                           av2.visitAnnotation(name, desc));
49    }
50
51    public AnnotationVisitor visitArray(String name) {
52        return getInstance(av1.visitArray(name), av2.visitArray(name));
53    }
54
55    public void visitEnd() {
56        av1.visitEnd();
57        av2.visitEnd();
58    }
59}
60