Java Reflection Method Get from Object getMethodDescriptor(Object instance, String methodName, Class aClass, Class... parameters)

Here you can find the source of getMethodDescriptor(Object instance, String methodName, Class aClass, Class... parameters)

Description

get Method Descriptor

License

Open Source License

Declaration

public static Method getMethodDescriptor(Object instance, String methodName, Class<? extends Object> aClass,
            Class<?>... parameters) throws NoSuchMethodException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Red Hat, Inc./*from w  w w  . java2 s . com*/
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import java.lang.reflect.Method;

public class Main {
    public static Method getMethodDescriptor(Object instance, String methodName, Class<? extends Object> aClass,
            Class<?>... parameters) throws NoSuchMethodException {
        notNull(instance, "instance");
        Method method = aClass.getDeclaredMethod(methodName, parameters);
        method.setAccessible(true);
        return method;
    }

    public static <T> T notNull(T value, String message) {
        if (value == null) {
            throw new IllegalArgumentException(message);
        }
        return value;
    }

    public static Method getDeclaredMethod(Class<?> aClass, String name) throws NoSuchMethodException {
        try {
            return aClass.getDeclaredMethod(name);
        } catch (NoSuchMethodException e) {
            Class<?> superclass = aClass.getSuperclass();
            if (aClass == Object.class || superclass == null) {
                throw e;
            } else {
                return getDeclaredMethod(superclass, name);
            }
        }
    }
}

Related

  1. getMethod(Object target, String signature)
  2. getMethod(String methodName, Object instance)
  3. getMethodAnnotatedWith(final Class type, final Class annotation, String fieldName, Object fieldValue)
  4. getMethodByName(Object target, String methodName)
  5. getMethodConfigByAnnotaton(Object instance, Class declaringClass, Class annotationType, Class type)
  6. getMethodFirstParamType(final String methodName, final Object o)
  7. getMethodIfAny(final Object instance, final String name, final Class[] params)
  8. getMethodIgnoreCaseWithNoParams(Object o, String p)
  9. getMethodInHolder(String methodName, Object holder)