01: /*
02: * Copyright 2003,2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package net.sf.cglib.reflect;
17:
18: import java.lang.reflect.InvocationTargetException;
19: import java.lang.reflect.Method;
20:
21: public class FastMethod extends FastMember {
22: FastMethod(FastClass fc, Method method) {
23: super (fc, method, helper(fc, method));
24: }
25:
26: private static int helper(FastClass fc, Method method) {
27: int index = fc.getIndex(method.getName(), method
28: .getParameterTypes());
29: if (index < 0) {
30: Class[] types = method.getParameterTypes();
31: System.err.println("hash=" + method.getName().hashCode()
32: + " size=" + types.length);
33: for (int i = 0; i < types.length; i++) {
34: System.err.println(" types[" + i + "]="
35: + types[i].getName());
36: }
37: throw new IllegalArgumentException("Cannot find method "
38: + method);
39: }
40: return index;
41: }
42:
43: public Class getReturnType() {
44: return ((Method) member).getReturnType();
45: }
46:
47: public Class[] getParameterTypes() {
48: return ((Method) member).getParameterTypes();
49: }
50:
51: public Class[] getExceptionTypes() {
52: return ((Method) member).getExceptionTypes();
53: }
54:
55: public Object invoke(Object obj, Object[] args)
56: throws InvocationTargetException {
57: return fc.invoke(index, obj, args);
58: }
59:
60: public Method getJavaMethod() {
61: return (Method) member;
62: }
63: }
|