Example usage for java.lang.reflect Method getParameterTypes

List of usage examples for java.lang.reflect Method getParameterTypes

Introduction

In this page you can find the example usage for java.lang.reflect Method getParameterTypes.

Prototype

@Override
public Class<?>[] getParameterTypes() 

Source Link

Usage

From source file:com.github.drinkjava2.jbeanbox.springsrc.ReflectionUtils.java

/**
 * Get the unique set of declared methods on the leaf class and all superclasses. Leaf class methods are included
 * first and while traversing the superclass hierarchy any methods found with signatures matching a method already
 * included are filtered out./* w w w  . ja va 2  s.  c o  m*/
 * 
 * @param leafClass
 *            the class to introspect
 */
public static Method[] getUniqueDeclaredMethods(Class<?> leafClass) {
    final List<Method> methods = new ArrayList<Method>(32);
    doWithMethods(leafClass, new MethodCallback() {
        public void doWith(Method method) {
            boolean knownSignature = false;
            Method methodBeingOverriddenWithCovariantReturnType = null;
            for (Method existingMethod : methods) {
                if (method.getName().equals(existingMethod.getName())
                        && Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) {
                    // Is this a covariant return type situation?
                    if (existingMethod.getReturnType() != method.getReturnType()
                            && existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
                        methodBeingOverriddenWithCovariantReturnType = existingMethod;
                    } else {
                        knownSignature = true;
                    }
                    break;
                }
            }
            if (methodBeingOverriddenWithCovariantReturnType != null) {
                methods.remove(methodBeingOverriddenWithCovariantReturnType);
            }
            if (!knownSignature && !isCglibRenamedMethod(method)) {
                methods.add(method);
            }
        }
    });
    return methods.toArray(new Method[methods.size()]);
}

From source file:org.reindeer.redis.JedisCallbackFilter.java

@Override
public int accept(Method method) {
    if ("finalize".equals(method.getName()) && method.getParameterTypes().length == 0
            && method.getReturnType() == Void.TYPE) {
        return 0;
    }/*from   ww w .ja  va2  s.  c  o m*/
    return 1;
}

From source file:io.neba.spring.web.WebApplicationContextAdapterTest.java

private Object[] mockArgs(Method method) {
    return stream(method.getParameterTypes()).map(type -> {
        if (!type.isPrimitive()) {
            return null;
        }//from   w w  w . java 2  s . co  m
        if (type == boolean.class) {
            return false;
        }
        throw new AssertionError("Unable to mock type " + type + ".");
    }).toArray();
}

From source file:io.neba.spring.web.WebApplicationContextAdapterTest.java

private String signatureOf(Method m) {
    return m.getName() + "(" + StringUtils.join(m.getParameterTypes(), ", ") + ")";
}

From source file:mil.army.usace.data.dataquery.utility.DefaultConverter.java

@Override
public Object convertType(Object obj, Method method) throws ClassNotFoundException, ConversionException {
    Class methodParam = method.getParameterTypes()[0];
    if (obj == null)
        return null;
    else {//w  ww  . jav a 2 s.co m
        if (methodParam.isPrimitive()) {
            return obj;
        } else {
            return convertType(obj, methodParam);
        }
    }
}

From source file:com.haulmont.cuba.core.sys.CubaAnnotationsLoader.java

private boolean propertyBelongsTo(Field field, MetaProperty metaProperty, List<Class> systemInterfaces) {
    String getterName = "get" + StringUtils.capitalize(metaProperty.getName());

    Class<?> aClass = field.getDeclaringClass();
    //noinspection unchecked
    List<Class> allInterfaces = ClassUtils.getAllInterfaces(aClass);
    for (Class intf : allInterfaces) {
        Method[] methods = intf.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getName().equals(getterName) && method.getParameterTypes().length == 0) {
                if (systemInterfaces.contains(intf))
                    return true;
            }//from ww  w .j a va  2s. com
        }
    }
    return false;
}

From source file:es.caib.zkib.jxpath.util.ValueUtils.java

/**
 * Return an accessible method (that is, one that can be invoked via
 * reflection) that implements the specified Method.  If no such method
 * can be found, return <code>null</code>.
 *
 * @param method The method that we wish to call
 * @return Method/*from   w w w  .j ava 2  s  .c  o  m*/
 */
public static Method getAccessibleMethod(Method method) {

    // Make sure we have a method to check
    if (method == null) {
        return (null);
    }

    // If the requested method is not public we cannot call it
    if (!Modifier.isPublic(method.getModifiers())) {
        return (null);
    }

    // If the declaring class is public, we are done
    Class clazz = method.getDeclaringClass();
    if (Modifier.isPublic(clazz.getModifiers())) {
        return (method);
    }

    String name = method.getName();
    Class[] parameterTypes = method.getParameterTypes();
    while (clazz != null) {
        // Check the implemented interfaces and subinterfaces
        Method aMethod = getAccessibleMethodFromInterfaceNest(clazz, name, parameterTypes);
        if (aMethod != null) {
            return aMethod;
        }

        clazz = clazz.getSuperclass();
        if (clazz != null && Modifier.isPublic(clazz.getModifiers())) {
            try {
                return clazz.getDeclaredMethod(name, parameterTypes);
            } catch (NoSuchMethodException e) { //NOPMD
                //ignore
            }
        }
    }
    return null;
}

From source file:com.reignite.messaging.server.SpringInitializedDestination.java

@Override
public Service getService(String operation, Object[] params) {
    List<Method> methods = methodMap.get(operation);
    int paramLength = params == null ? 0 : params.length;
    Service service = null;//from   w  w w .j a  v  a 2 s .  co  m
    if (methods != null) {
        for (Method method : methods) {
            if (method.getParameterTypes().length == paramLength) {
                Class<?>[] methodTypes = method.getParameterTypes();
                int matches = 0;
                Object[] newParams = new Object[paramLength];
                for (int i = 0; i < paramLength; i++) {
                    Object param = params[i];
                    Class<?> requiredClass = methodTypes[i];
                    if (param == null || requiredClass.isAssignableFrom(param.getClass())) {
                        matches++;
                        newParams[i] = param;
                    } else {
                        param = convertParam(param, requiredClass);
                        if (param == null || requiredClass.isAssignableFrom(param.getClass())) {
                            matches++;
                            newParams[i] = param;
                        }
                    }
                }
                if (matches == paramLength) {
                    service = new RAMFService(target, method, newParams);
                    break;
                }
            }
        }
    }
    return service;
}

From source file:code.google.nfs.rpc.server.RPCServerHandler.java

public void registerProcessor(String instanceName, Object instance) {
    processors.put(instanceName, instance);
    Class<?> instanceClass = instance.getClass();
    Method[] methods = instanceClass.getMethods();
    for (Method method : methods) {
        Class<?>[] argTypes = method.getParameterTypes();
        StringBuilder methodKeyBuilder = new StringBuilder();
        methodKeyBuilder.append(instanceName).append("#");
        methodKeyBuilder.append(method.getName()).append("$");
        for (Class<?> argClass : argTypes) {
            methodKeyBuilder.append(argClass.getName()).append("_");
        }/*  w w w . java2s.  c  o  m*/
        cacheMethods.put(methodKeyBuilder.toString(), method);
    }
}

From source file:com.ivanzhangwb.interpose.core.InterposeBootStrap.java

/**
 * ?/*from   w  w w  .  j  av  a  2 s . c o  m*/
 * 
 * @param methods
 * @param i
 */
private void handleMethodAnnotation(Method method) {
    InterposeAnnotationCache.put(new MethodInfo(method.getName(), method.getParameterTypes()).toString(),
            method.getAnnotation(Interpose.class));
}