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.nominanuda.hyperapi.HyperApiWsSkelton.java

protected Object[] createArgs(DataObject uriParams, HttpEntity entity, Class<?> api2, Method method)
        throws IOException {
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    Class<?>[] parameterTypes = method.getParameterTypes();
    Object[] args = new Object[parameterTypes.length];
    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> parameterType = parameterTypes[i];
        Annotation[] annotations = parameterAnnotations[i];
        AnnotatedType p = new AnnotatedType(parameterType, annotations);
        boolean annotationFound = false;
        for (Annotation annotation : annotations) {
            if (annotation instanceof PathParam) {
                annotationFound = true;/*ww w  . java2s . c  o m*/
                String s = (String) uriParams.getPathSafe(((PathParam) annotation).value());
                args[i] = cast(s, parameterType);
                break;
            } else if (annotation instanceof QueryParam) {
                annotationFound = true;
                String s = (String) uriParams.getPathSafe(((QueryParam) annotation).value());
                args[i] = cast(s, parameterType);
                break;
            }
        }
        if (!annotationFound) {
            Object dataEntity = entity == null ? null : decodeEntity(entity, p);
            args[i] = dataEntity;
        }
    }
    return args;
}

From source file:cn.wanghaomiao.xpath.core.XpathEvaluator.java

public XpathEvaluator() {
    emFuncs = new HashMap<String, Method>();
    axisFuncs = new HashMap<String, Method>();
    for (Method m : Functions.class.getDeclaredMethods()) {
        emFuncs.put(renderFuncKey(m.getName(), m.getParameterTypes()), m);
    }/*ww w. j  a v  a 2s.  co m*/
    for (Method m : AxisSelector.class.getDeclaredMethods()) {
        axisFuncs.put(renderFuncKey(m.getName(), m.getParameterTypes()), m);
    }
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Find method.//from w ww.ja v a 2s. c  om
 *
 * @param bean the bean
 * @param clazz the clazz
 * @param method the method
 * @param args the args
 * @return null if method cannot be found
 */
public static Method findMethod(Object bean, Class<?> clazz, String method, Object... args) {
    nextMethod: for (Method m : clazz.getDeclaredMethods()) {
        if (m.getName().equals(method) == false) {
            continue;
        }
        Class<?>[] argClazzes = m.getParameterTypes();
        if (argClazzes.length != args.length) {
            continue;
        }
        for (int i = 0; i < args.length; ++i) {
            Object a = args[i];
            Class<?> ac = argClazzes[i];
            if (a != null && ac.isAssignableFrom(a.getClass()) == false) {
                continue nextMethod;
            }
        }
        return m;
    }
    if (clazz != Object.class && clazz.getSuperclass() != null) {
        return findMethod(bean, clazz.getSuperclass(), method, args);
    }
    return null;
}

From source file:com.all.app.BeanStatisticsWriter.java

private List<CSVColumn> auto(Object object) {
    List<CSVColumn> columns = new ArrayList<CSVColumn>();
    Method[] declaredMethods = object.getClass().getDeclaredMethods();
    for (Method method : declaredMethods) {
        boolean noArguments = method.getParameterTypes().length == 0;
        boolean isVoid = method.getReturnType().equals(void.class);
        boolean isPublic = (method.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC;
        boolean isNotStatic = (method.getModifiers() & Modifier.STATIC) != Modifier.STATIC;
        boolean isGetter = method.getName().startsWith("get");
        if (isGetter && noArguments && isPublic && isNotStatic && !isVoid) {
            columns.add(new CSVColumnMethodReflected(method.getName(), method.getName()));
        }//  w  w  w  . j a  va  2  s.c om
    }
    return columns;
}

From source file:candr.yoclip.option.OptionSetter.java

/**
 * Initializes the method descriptor to create an association between the bean setter {@code Method} and the {@code Option}
 * annotation./*  w  ww  .  j  a  v  a2s  .  c o  m*/
 *
 * @param option The annotation associated with the bean setter method.
 * @param setter The bean setter method annotated with {@code Option}.
 * @throws OptionsBadNameException       if one of the option {@link Option#name() name} is empty or the option does not have at
 *                                       least one name.
 * @throws UnsupportedOperationException if the setter method requires more than one parameter.
 */
public OptionSetter(final Option option, final Method setter) {

    super(setter);

    final Class<?>[] parameterTypes = setter.getParameterTypes();
    if (1 != parameterTypes.length) {
        throw new UnsupportedOperationException(setter.toGenericString() + " must have 1 parameter.");
    }

    for (final String name : option.name()) {
        if (StringUtils.isEmpty(name)) {
            throw new OptionsBadNameException(setter.getName() + " has an option name that is empty.");
        }
    }
    if (option.name().length == 0) {
        throw new OptionsBadNameException("Options must have at least one name.");
    }

    this.option = option;
}

From source file:com.inmobi.grill.server.EventServiceImpl.java

@SuppressWarnings("unchecked")
protected final Class<? extends GrillEvent> getListenerType(GrillEventListener listener) {
    for (Method m : listener.getClass().getMethods()) {
        if (GrillEventListener.HANDLER_METHOD_NAME.equals(m.getName())) {
            // Found handler method
            return (Class<? extends GrillEvent>) m.getParameterTypes()[0];
        }//ww w .  j  ava  2  s .  com
    }
    return null;
}

From source file:org.neovera.jdiablo.environment.SpringEnvironment.java

private void setValue(PropertyDescriptor pd, Object target, String value) {
    Method writeMethod = pd.getWriteMethod();
    if (writeMethod == null) {
        throw new RuntimeException("No write method found for property " + pd.getName());
    }//w w  w  .  ja va  2  s. c  om
    try {
        if (writeMethod.getParameterTypes()[0].equals(Boolean.class)
                || "boolean".equals(writeMethod.getParameterTypes()[0].getName())) {
            writeMethod.invoke(target, value == null ? false : "true".equals(value));
        } else if (writeMethod.getParameterTypes()[0].equals(Integer.class)
                || "int".equals(writeMethod.getParameterTypes()[0].getName())) {
            writeMethod.invoke(target, value == null ? 0 : Integer.parseInt(value));
        } else if (writeMethod.getParameterTypes()[0].equals(Long.class)
                || "long".equals(writeMethod.getParameterTypes()[0].getName())) {
            writeMethod.invoke(target, value == null ? 0 : Long.parseLong(value));
        } else if (writeMethod.getParameterTypes()[0].equals(BigDecimal.class)) {
            writeMethod.invoke(target, value == null ? null : new BigDecimal(value));
        } else if (writeMethod.getParameterTypes()[0].equals(String.class)) {
            writeMethod.invoke(target, value);
        } else if (writeMethod.getParameterTypes()[0].isArray()
                && writeMethod.getParameterTypes()[0].getName().contains(String.class.getName())) {
            writeMethod.invoke(target, (Object[]) value.split(","));
        } else {
            throw new RuntimeException("Could not resolve parameter type for " + writeMethod.toString());
        }
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.haulmont.cuba.gui.xml.DeclarativeColumnGenerator.java

protected Method findGeneratorMethod(Class cls, String methodName) {
    Method exactMethod = MethodUtils.getAccessibleMethod(cls, methodName, Entity.class);
    if (exactMethod != null) {
        return exactMethod;
    }/*from   ww w  .j a va2s  . c o m*/

    // search through all methods
    Method[] methods = cls.getMethods();
    for (Method availableMethod : methods) {
        if (availableMethod.getName().equals(methodName)) {
            if (availableMethod.getParameterCount() == 1
                    && Component.class.isAssignableFrom(availableMethod.getReturnType())) {
                if (Entity.class.isAssignableFrom(availableMethod.getParameterTypes()[0])) {
                    // get accessible version of method
                    return MethodUtils.getAccessibleMethod(availableMethod);
                }
            }
        }
    }
    return null;
}

From source file:com.weibo.api.motan.proxy.RefererInvocationHandler.java

private Class<?> getRealReturnType(boolean asyncCall, Class<?> clazz, Method method, String methodName) {
    if (asyncCall) {
        try {/*w w w. java 2 s  .  c  om*/
            Method m = clazz.getMethod(methodName, method.getParameterTypes());
            return m.getReturnType();
        } catch (Exception e) {
            LoggerUtil.warn("RefererInvocationHandler get real return type fail. err:" + e.getMessage());
            return method.getReturnType();
        }
    } else {
        return method.getReturnType();
    }
}