01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.transform.inlining;
05:
06: import com.tc.asm.AnnotationVisitor;
07: import com.tc.asm.MethodVisitor;
08: import com.tc.asm.Attribute;
09:
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
22: AnnotationVisitor {
23:
24: private final AnnotationVisitor m_from;
25:
26: private final AnnotationVisitor m_to;
27:
28: public CopyAnnotationAdapter(AnnotationVisitor from,
29: AnnotationVisitor copyTo) {
30: m_from = from;
31: m_to = copyTo;
32: }
33:
34: public void visit(String name, Object value) {
35: m_from.visit(name, value);
36: m_to.visit(name, value);
37: }
38:
39: public void visitEnum(String name, String desc, String value) {
40: m_from.visitEnum(name, desc, value);
41: m_to.visitEnum(name, desc, value);
42: }
43:
44: public AnnotationVisitor visitAnnotation(String name,
45: String desc) {
46: return new CopyAnnotationAdapter(m_from.visitAnnotation(
47: name, desc), m_to.visitAnnotation(name, desc));
48: }
49:
50: public AnnotationVisitor visitArray(String name) {
51: return new CopyAnnotationAdapter(m_from.visitArray(name),
52: m_to.visitArray(name));
53: }
54:
55: public void visitEnd() {
56: m_from.visitEnd();
57: m_to.visitEnd();
58: }
59:
60: }
61:
62: /**
63: * Copy all annotations of a method
64: * //FIXME needed ?
65: */
66: public static class CopyMethodAnnotationElseNullAdapter extends
67: 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 desc,
80: boolean visible) {
81: return new CopyAnnotationAdapter(
82: AsmNullAdapter.NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER,
83: m_copyTo.visitAnnotation(desc, visible));
84: }
85:
86: public AnnotationVisitor visitParameterAnnotation(
87: int parameter, String desc, boolean visible) {
88: return new CopyAnnotationAdapter(
89: AsmNullAdapter.NullAnnotationVisitor.NULL_ANNOTATION_ADAPTER,
90: m_copyTo.visitParameterAnnotation(parameter, desc,
91: visible));
92: }
93:
94: }
95: }
|