KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > transform > inlining > weaver > AlreadyAddedMethodAdapter


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 JavaDoc;
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 JavaDoc m_addedMethods;
31
32     /**
33      * Creates a new class adapter.
34      *
35      * @param wrappers
36      */

37     public AlreadyAddedMethodAdapter(final Set JavaDoc 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 JavaDoc name,
53                                    final String JavaDoc desc,
54                                    final String JavaDoc[] 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 JavaDoc getMethodKey(String JavaDoc name, String JavaDoc desc) {
64         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(name);
65         return sb.append(desc).toString();
66     }
67 }
68
Popular Tags