KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > transform > inlining > AsmCopyAdapter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.transform.inlining;
5
6 import com.tc.asm.AnnotationVisitor;
7 import com.tc.asm.MethodVisitor;
8 import com.tc.asm.Attribute;
9
10 /**
11  * Adapters to handle annotation copy
12  * FIXME license EPL + FIXME field annotation + ctor annotation when all wrapped ?? [but why does it matters]
13  *
14  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
15  */

16 public class AsmCopyAdapter {
17
18   /**
19    * Copy annotation from one to another place
20    */

21   public static class CopyAnnotationAdapter implements AnnotationVisitor {
22
23     private final AnnotationVisitor m_from;
24
25     private final AnnotationVisitor m_to;
26
27     public CopyAnnotationAdapter(AnnotationVisitor from, AnnotationVisitor copyTo) {
28       m_from = from;
29       m_to = copyTo;
30     }
31
32     public void visit(String JavaDoc name, Object JavaDoc value) {
33       m_from.visit(name, value);
34       m_to.visit(name, value);
35     }
36
37     public void visitEnum(String JavaDoc name, String JavaDoc desc, String JavaDoc value) {
38       m_from.visitEnum(name, desc, value);
39       m_to.visitEnum(name, desc, value);
40     }
41
42     public AnnotationVisitor visitAnnotation(String JavaDoc name, String JavaDoc desc) {
43       return new CopyAnnotationAdapter(
44               m_from.visitAnnotation(name, desc),
45               m_to.visitAnnotation(name, desc)
46       );
47     }
48
49     public AnnotationVisitor visitArray(String JavaDoc name) {
50       return new CopyAnnotationAdapter(
51               m_from.visitArray(name),
52               m_to.visitArray(name)
53       );
54     }
55
56     public void visitEnd() {
57       m_from.visitEnd();
58       m_to.visitEnd();
59     }
60
61   }
62
63   /**
64    * Copy all annotations of a method
65    * //FIXME needed ?
66    */

67   public static class CopyMethodAnnotationElseNullAdapter extends AsmNullAdapter.NullMethodAdapter {
68
69     private final MethodVisitor m_copyTo;
70
71     public CopyMethodAnnotationElseNullAdapter(MethodVisitor copyTo) {
72       m_copyTo = copyTo;
73     }
74
75     public void visitAttribute(Attribute attr) {
76       m_copyTo.visitAttribute(attr);
77     }
78
79     public AnnotationVisitor visitAnnotation(String JavaDoc desc, boolean visible) {
80       return new CopyAnnotationAdapter(
81               AsmNullAdapter.NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER,
82               m_copyTo.visitAnnotation(desc, visible)
83       );
84     }
85
86     public AnnotationVisitor visitParameterAnnotation(int parameter, String JavaDoc desc, boolean visible) {
87       return new CopyAnnotationAdapter(
88               AsmNullAdapter.NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER,
89               m_copyTo.visitParameterAnnotation(parameter, desc, visible)
90       );
91     }
92
93   }
94 }
95
Popular Tags