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.mirth.connect.client.core.api.util.OperationUtil.java

public static Operation getOperation(Class<?> servletInterface, Method method) {
    return getOperation(servletInterface, method.getName(), method.getParameterTypes());
}

From source file:com.netflix.hystrix.contrib.javanica.utils.AopUtils.java

/**
 * Gets parameter types of the join point.
 *
 * @param joinPoint the join point// ww  w . j  ava  2s  .  c  o  m
 * @return the parameter types for the method this object
 *         represents
 */
public static Class[] getParameterTypes(JoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    return method.getParameterTypes();
}

From source file:de.otto.jsonhome.generator.MethodHelper.java

/**
 * Discovers parameter infos of a Method.
 *
 * Debug information must not be removed from the class files, otherwise the name of the method parameters can
 * not be resolved.//from   w w  w .  ja v  a 2 s.  co  m
 *
 * @param method the Method
 * @return list of ParameterInfo in the correct ordering.
 */
public static List<ParameterInfo> getParameterInfos(final Method method) {
    final Class<?>[] parameterTypes = method.getParameterTypes();
    final Annotation[][] parameterAnnotations = parameterAnnotationsOf(method);
    final String[] parameterNames = parameterNamesOf(method);
    final List<ParameterInfo> parameterInfos = new ArrayList<ParameterInfo>();
    for (int i = 0, n = parameterNames.length; i < n; ++i) {
        parameterInfos.add(new ParameterInfo(parameterNames[i], parameterTypes[i],
                parameterAnnotations.length > i ? asList(parameterAnnotations[i])
                        : Collections.<Annotation>emptyList()));
    }
    return parameterInfos;
}

From source file:springfox.documentation.swagger.readers.parameter.ParameterAnnotationReader.java

private static Optional<Method> interfaceMethod(Class<?> iface, Method method) {
    try {/*from   w  w  w . j av a  2s  .  c  o m*/
        return Optional.of(iface.getMethod(method.getName(), method.getParameterTypes()));
    } catch (NoSuchMethodException ex) {
        return Optional.absent();
    }
}

From source file:Main.java

private static boolean isMethodArgCompatible(Method method, Class<?>... argTypes) {
    for (int i = 0; i < argTypes.length; i++) {
        if (!isCompatible(method.getParameterTypes()[i], argTypes[i])) {
            return false;
        }//w w w . ja va 2 s.  c o  m
    }
    return true;
}

From source file:com.zauberlabs.commons.mom.NaiveProperties.java

/** function that answers method arguments count */
@Constant/*from  ww  w.  j a v  a2 s  .  c  o m*/
public static AbstractPredicate<Method> argCount(final int argsCount) {
    return new AbstractPredicate<Method>() {
        @Override
        public boolean eval(final Method arg0) {
            return arg0.getParameterTypes().length == argsCount;
        }
    };
}

From source file:Main.java

public static boolean declaredEquals(Class<?> clazz) {
    for (Method declaredMethod : clazz.getDeclaredMethods()) {
        if (EQUALS_METHOD.equals(declaredMethod.getName())
                && Arrays.equals(declaredMethod.getParameterTypes(), EQUALS_PARAMETERS)) {
            return true;
        }/*from  ww w.ja  va2  s.  co  m*/
    }
    return false;
}

From source file:Main.java

public static long generateCodeOfMethod(Class<?> providerClass, Method method) {
    StringBuilder buider = new StringBuilder(method.getName());
    long classCode = providerClass.getName().hashCode();
    Class<?>[] paramTypes = method.getParameterTypes();
    for (Class<?> c : paramTypes) {
        buider.append(c.getName());//from   w ww.j  a v a  2  s.  c  om
    }
    return classCode << 32 + buider.toString().hashCode();
}

From source file:Main.java

/**
 * Convenience method for obtaining most non-null human readable properties of a JComponent. Array properties are not included.
 * <P>/*from  w w  w.  ja  va2s.  c  o m*/
 * Implementation note: The returned value is a HashMap. This is subject to change, so callers should code against the interface Map.
 * 
 * @param component
 *            the component whose proerties are to be determined
 * @return the class and value of the properties
 */
public static Map<Object, Object> getProperties(JComponent component) {
    Map<Object, Object> retVal = new HashMap<>();
    Class<?> clazz = component.getClass();
    Method[] methods = clazz.getMethods();
    Object value = null;
    for (Method method : methods) {
        if (method.getName().matches("^(is|get).*") && //$NON-NLS-1$
                method.getParameterTypes().length == 0) {
            try {
                Class<?> returnType = method.getReturnType();
                if (returnType != void.class && !returnType.getName().startsWith("[") && //$NON-NLS-1$
                        !setExclude.contains(method.getName())) {
                    String key = method.getName();
                    value = method.invoke(component);
                    if (value != null && !(value instanceof Component)) {
                        retVal.put(key, value);
                    }
                }
                // ignore exceptions that arise if the property could not be accessed
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                //no catch
            }
        }
    }
    return retVal;
}

From source file:ReflectionUtils.java

/**
 * Attempt to find a {@link Method} on the supplied class with the supplied name
 * and parameter types. Searches all superclasses up to <code>Object</code>.
 * <p>Returns <code>null</code> if no {@link Method} can be found.
 * @param clazz the class to introspect/*from  w ww  .  j  a  v  a2 s . com*/
 * @param name the name of the method
 * @param paramTypes the parameter types of the method
 * @return the Method object, or <code>null</code> if none found
 */
public static Method findMethod(Class clazz, String name, Class[] paramTypes) {

    Class searchType = clazz;
    while (!Object.class.equals(searchType) && searchType != null) {
        Method[] methods = (searchType.isInterface() ? searchType.getMethods()
                : searchType.getDeclaredMethods());
        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            if (name.equals(method.getName()) && Arrays.equals(paramTypes, method.getParameterTypes())) {
                return method;
            }
        }
        searchType = searchType.getSuperclass();
    }
    return null;
}