KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > reflect > FastMethod


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20
21 public class FastMethod extends FastMember
22 {
23     FastMethod(FastClass fc, Method JavaDoc method) {
24         super(fc, method, helper(fc, method));
25     }
26
27     private static int helper(FastClass fc, Method JavaDoc method) {
28         int index = fc.getIndex(method.getName(), method.getParameterTypes());
29         if (index < 0) {
30             Class JavaDoc[] types = method.getParameterTypes();
31             System.err.println("hash=" + method.getName().hashCode() + " size=" + types.length);
32             for (int i = 0; i < types.length; i++) {
33                 System.err.println(" types[" + i + "]=" + types[i].getName());
34             }
35             throw new IllegalArgumentException JavaDoc("Cannot find method " + method);
36         }
37         return index;
38     }
39
40     public Class JavaDoc getReturnType() {
41         return ((Method JavaDoc)member).getReturnType();
42     }
43
44     public Class JavaDoc[] getParameterTypes() {
45         return ((Method JavaDoc)member).getParameterTypes();
46     }
47
48     public Class JavaDoc[] getExceptionTypes() {
49         return ((Method JavaDoc)member).getExceptionTypes();
50     }
51
52     public Object JavaDoc invoke(Object JavaDoc obj, Object JavaDoc[] args) throws InvocationTargetException JavaDoc {
53         return fc.invoke(index, obj, args);
54     }
55
56     public Method JavaDoc getJavaMethod() {
57         return (Method JavaDoc)member;
58     }
59 }
60
Popular Tags