View Javadoc

1   /***************************************************************************************
2    * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package org.codehaus.aspectwerkz.transform.inlining.weaver;
9   
10  import org.objectweb.asm.Constants;
11  import org.objectweb.asm.CodeVisitor;
12  import org.objectweb.asm.Attribute;
13  import org.codehaus.aspectwerkz.transform.TransformationConstants;
14  import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotationHelper;
15  
16  import java.util.Set;
17  
18  /***
19   * A read only visitor to gather wrapper methods and proxy methods
20   * Makes use of the NullVisitors
21   *
22   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
23   */
24  public class AlreadyAddedMethodAdapter extends AsmAnnotationHelper.NullClassAdapter implements Constants, TransformationConstants {
25  
26      /***
27       * Set of "<methodName><methodDesc>" strings populated with wrapper methods, prefixed originals
28       * and ctor body wrappers to allow multiweaving support.
29       */
30      private final Set m_addedMethods;
31  
32      /***
33       * Creates a new class adapter.
34       *
35       * @param wrappers
36       */
37      public AlreadyAddedMethodAdapter(final Set wrappers) {
38          m_addedMethods = wrappers;
39      }
40  
41      /***
42       * Visits the methods.
43       *
44       * @param access
45       * @param name
46       * @param desc
47       * @param exceptions
48       * @param attrs
49       * @return
50       */
51      public CodeVisitor visitMethod(final int access,
52                                     final String name,
53                                     final String desc,
54                                     final String[] exceptions,
55                                     final Attribute attrs) {
56          if (name.startsWith(WRAPPER_METHOD_PREFIX)
57              || name.startsWith(ORIGINAL_METHOD_PREFIX)) {
58              m_addedMethods.add(getMethodKey(name, desc));
59          }
60          return super.visitMethod(access, name, desc, exceptions, attrs);
61      }
62  
63      static String getMethodKey(String name, String desc) {
64          StringBuffer sb = new StringBuffer(name);
65          return sb.append(desc).toString();
66      }
67  }