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.CodeVisitor;
    11  import org.objectweb.asm.Attribute;
    12  import org.codehaus.aspectwerkz.transform.TransformationConstants;
    13  import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotationHelper;
    14
    15  import java.util.Set;
    16
    17  /***
    18   * A read only visitor to gather wrapper methods and proxy methods
    19   * Makes use of the NullVisitors
    20   *
    21   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
    22   */
    23  public class AlreadyAddedMethodVisitor extends AsmAnnotationHelper.NullClassAdapter implements TransformationConstants {
    24
    25      /***
    26       * Set of "<methodName><methodDesc>" strings populated with wrapper methods, prefixed originals
    27       * and ctor body wrappers to allow multiweaving support.
    28       */
    29      private final Set m_addedMethods;
    30
    31      /***
    32       * Creates a new class adapter.
    33       *
    34       * @param wrappers
    35       */
    36      public AlreadyAddedMethodVisitor(final Set wrappers) {
    37          m_addedMethods = wrappers;
    38      }
    39
    40      /***
    41       * Visits the methods.
    42       *
    43       * @param access
    44       * @param name
    45       * @param desc
    46       * @param exceptions
    47       * @param attrs
    48       * @return
    49       */
    50      public CodeVisitor visitMethod(final int access,
    51                                     final String name,
    52                                     final String desc,
    53                                     final String[] exceptions,
    54                                     final Attribute attrs) {
    55          if (name.startsWith(WRAPPER_METHOD_PREFIX) ||
    56              name.startsWith(ORIGINAL_METHOD_PREFIX)) {
    57              //FIXME do it for ctor exe wrapper
    58              m_addedMethods.add(getMethodKey(name, desc));
    59          }
    60          return super.visitMethod(access, name, desc, exceptions, attrs);
    61      }
    62
    63      /***
    64       * Returns the key of the method.
    65       *
    66       * @param name
    67       * @param desc
    68       * @return
    69       */
    70      static String getMethodKey(final String name, final String desc) {
    71          StringBuffer sb = new StringBuffer(name);
    72          return sb.append(desc).toString();
    73      }
    74  }