Home | History | Annotate | Download | only in reflect
      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 org.mockito.cglib.reflect;
     17 
     18 import java.lang.reflect.InvocationTargetException;
     19 import java.lang.reflect.Method;
     20 
     21 public class FastMethod extends FastMember
     22 {
     23     FastMethod(FastClass fc, Method method) {
     24         super(fc, method, helper(fc, method));
     25     }
     26 
     27     private static int helper(FastClass fc, Method method) {
     28         int index = fc.getIndex(method.getName(), method.getParameterTypes());
     29         if (index < 0) {
     30             Class[] 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("Cannot find method " + method);
     36         }
     37         return index;
     38     }
     39 
     40     public Class getReturnType() {
     41         return ((Method)member).getReturnType();
     42     }
     43 
     44     public Class[] getParameterTypes() {
     45         return ((Method)member).getParameterTypes();
     46     }
     47 
     48     public Class[] getExceptionTypes() {
     49         return ((Method)member).getExceptionTypes();
     50     }
     51 
     52     public Object invoke(Object obj, Object[] args) throws InvocationTargetException {
     53         return fc.invoke(index, obj, args);
     54     }
     55 
     56     public Method getJavaMethod() {
     57         return (Method)member;
     58     }
     59 }
     60