01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.transform.inlining.weaver;
08:
09: import org.objectweb.asm.CodeVisitor;
10: import org.objectweb.asm.Attribute;
11: import org.codehaus.aspectwerkz.transform.TransformationConstants;
12: import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotationHelper;
13:
14: import java.util.Set;
15:
16: /**
17: * A read only visitor to gather wrapper methods and proxy methods
18: * Makes use of the NullVisitors
19: *
20: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
21: */
22: public class AlreadyAddedMethodVisitor extends
23: AsmAnnotationHelper.NullClassAdapter implements
24: 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 AlreadyAddedMethodVisitor(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, final String name,
52: final String desc, final String[] exceptions,
53: final Attribute attrs) {
54: if (name.startsWith(WRAPPER_METHOD_PREFIX)
55: || name.startsWith(ORIGINAL_METHOD_PREFIX)) {
56: //FIXME do it for ctor exe wrapper
57: m_addedMethods.add(getMethodKey(name, desc));
58: }
59: return super .visitMethod(access, name, desc, exceptions, attrs);
60: }
61:
62: /**
63: * Returns the key of the method.
64: *
65: * @param name
66: * @param desc
67: * @return
68: */
69: static String getMethodKey(final String name, final String desc) {
70: StringBuffer sb = new StringBuffer(name);
71: return sb.append(desc).toString();
72: }
73: }
|