KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > transform > inlining > weaver > AlreadyAddedMethodVisitor


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.weaver;
5
6 import java.util.Set JavaDoc;
7
8 import com.tc.asm.MethodVisitor;
9
10 import com.tc.aspectwerkz.transform.TransformationConstants;
11 import com.tc.aspectwerkz.transform.inlining.AsmNullAdapter;
12
13 /**
14  * A read only visitor to gather wrapper methods and proxy methods
15  * Makes use of the NullVisitors
16  *
17  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
18  */

19 public class AlreadyAddedMethodVisitor extends AsmNullAdapter.NullClassAdapter implements TransformationConstants {
20
21   /**
22    * Set of "<methodName><methodDesc>" strings populated with wrapper methods, prefixed originals
23    * and ctor body wrappers to allow multiweaving support.
24    */

25   private final Set JavaDoc m_addedMethods;
26
27   /**
28    * Creates a new class adapter.
29    *
30    * @param wrappers
31    */

32   public AlreadyAddedMethodVisitor(final Set JavaDoc wrappers) {
33     m_addedMethods = wrappers;
34   }
35
36   /**
37    * Visits the methods.
38    *
39    * @param access
40    * @param name
41    * @param desc
42    * @param signature
43    * @param exceptions
44    * @return
45    */

46   public MethodVisitor visitMethod(final int access,
47                                    final String JavaDoc name,
48                                    final String JavaDoc desc,
49                                    final String JavaDoc signature,
50                                    final String JavaDoc[] exceptions) {
51     if (name.startsWith(WRAPPER_METHOD_PREFIX) ||
52             name.startsWith(ORIGINAL_METHOD_PREFIX)) {
53       m_addedMethods.add(getMethodKey(name, desc));
54     }
55     return super.visitMethod(access, name, desc, signature, exceptions);
56   }
57
58   /**
59    * Returns the key of the method.
60    *
61    * @param name
62    * @param desc
63    * @return
64    */

65   static String JavaDoc getMethodKey(final String JavaDoc name, final String JavaDoc desc) {
66     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(name);
67     return sb.append(desc).toString();
68   }
69 }
70
Popular Tags