KickJava   Java API By Example, From Geeks To Geeks.

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


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
19 import org.aspectj.lang.reflect.MethodSignature;
20
21 class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature {
22     private Method JavaDoc method;
23     Class JavaDoc returnType;
24     
25     MethodSignatureImpl(int modifiers, String JavaDoc name, Class JavaDoc declaringType,
26         Class JavaDoc[] parameterTypes, String JavaDoc[] parameterNames, Class JavaDoc[] exceptionTypes,
27         Class JavaDoc returnType)
28     {
29         super(modifiers, name, declaringType, parameterTypes, parameterNames,
30             exceptionTypes);
31         this.returnType = returnType;
32     }
33     
34     MethodSignatureImpl(String JavaDoc stringRep) {
35         super(stringRep);
36     }
37
38     /* name is consistent with reflection API */
39     public Class JavaDoc getReturnType() {
40         if (returnType == null) returnType = extractType(6);
41         return returnType;
42     }
43     
44     protected String JavaDoc createToString(StringMaker sm) {
45         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
46         buf.append(sm.makeModifiersString(getModifiers()));
47         if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType()));
48         if (sm.includeArgs) buf.append(" ");
49         buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
50         buf.append(".");
51         buf.append(getName());
52         sm.addSignature(buf, getParameterTypes());
53         sm.addThrows(buf, getExceptionTypes());
54         return buf.toString();
55     }
56     
57     /* (non-Javadoc)
58      * @see org.aspectj.lang.reflect.MemberSignature#getAccessibleObject()
59      */

60     public Method JavaDoc getMethod() {
61         if (method == null) {
62             try {
63                 method = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes());
64             } catch (NoSuchMethodException JavaDoc nsmEx) {
65                 ; // nothing we can do, user will see null return
66
}
67         }
68         return method;
69     }
70 }
71
Popular Tags