KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > runtime > reflect > AdviceSignatureImpl


1 /* *******************************************************************
2  * Copyright (c) 1999-2001 Xerox Corporation,
3  * 2002 Palo Alto Research Center, Incorporated (PARC).
4  * All rights reserved.
5  * This program and the accompanying materials are made available
6  * under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * Xerox/PARC initial implementation
12  * ******************************************************************/

13
14
15 package org.aspectj.runtime.reflect;
16
17 import java.lang.reflect.Method JavaDoc;
18 import java.util.StringTokenizer JavaDoc;
19
20 import org.aspectj.lang.reflect.AdviceSignature;
21
22 class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
23     Class JavaDoc returnType;
24     private Method JavaDoc adviceMethod = null;
25     
26     AdviceSignatureImpl(int modifiers, String JavaDoc name, Class JavaDoc declaringType,
27         Class JavaDoc[] parameterTypes, String JavaDoc[] parameterNames, Class JavaDoc[] exceptionTypes,
28         Class JavaDoc returnType)
29     {
30         super(modifiers, name, declaringType, parameterTypes, parameterNames,
31             exceptionTypes);
32         this.returnType = returnType;
33     }
34     
35     AdviceSignatureImpl(String JavaDoc stringRep) {
36         super(stringRep);
37     }
38     /* name is consistent with reflection API
39     before and after always return Void.TYPE
40     (some around also return Void.Type) */

41     public Class JavaDoc getReturnType() {
42         if (returnType == null) returnType = extractType(6);
43         return returnType;
44     }
45
46     protected String JavaDoc createToString(StringMaker sm) {
47         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
48 // buf.append(sm.makeModifiersString(getModifiers()));
49
if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType()));
50         if (sm.includeArgs) buf.append(" ");
51         buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
52         buf.append(".");
53         buf.append(toAdviceName(getName()));
54         sm.addSignature(buf, getParameterTypes());
55         sm.addThrows(buf, getExceptionTypes());
56         return buf.toString();
57     }
58     
59     private String JavaDoc toAdviceName(String JavaDoc methodName) {
60             if (methodName.indexOf('$') == -1) return methodName;
61             StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(methodName,"$");
62             while (strTok.hasMoreTokens()) {
63                 String JavaDoc token = strTok.nextToken();
64                 if ( token.startsWith("before") ||
65                      token.startsWith("after") ||
66                      token.startsWith("around") ) return token;
67             }
68             return methodName;
69     }
70     
71     /* (non-Javadoc)
72      * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
73      */

74     public Method JavaDoc getAdvice() {
75         if (adviceMethod == null) {
76             try {
77                 adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes());
78             } catch (Exception JavaDoc ex) {
79                 ; // nothing we can do, caller will see null
80
}
81         }
82         return adviceMethod;
83     }
84 }
85
Popular Tags