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:org.jboss.arquillian.spring.integration.enricher.AbstractSpringInjectionEnricher.java

/**
 * {@inheritDoc}/*from   w  w  w .j  a  v a  2 s .co  m*/
 */
@Override
public Object[] resolve(Method method) {

    return new Object[method.getParameterTypes().length];
}

From source file:MethodComparator.java

public int compare(Method m1, Method m2) {

    int val = m1.getName().compareTo(m2.getName());
    if (val == 0) {
        val = m1.getParameterTypes().length - m2.getParameterTypes().length;
        if (val == 0) {
            Class[] types1 = m1.getParameterTypes();
            Class[] types2 = m2.getParameterTypes();
            for (int i = 0; i < types1.length; i++) {
                val = types1[i].getName().compareTo(types2[i].getName());

                if (val != 0) {
                    break;
                }/*from   w  w  w.  ja  v  a  2  s .  co  m*/
            }
        }
    }
    return val;
}

From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java

private static String argSignature(Method method) {
    Class param[] = method.getParameterTypes();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < param.length; i++) {
        if (i > 0)
            buf.append(",");
        buf.append(param[i].getName());/*w w w.j  av  a2 s .  com*/
    }
    return buf.toString();
}

From source file:com.jeeframework.util.classes.ClassUtils.java

/**
 * Given a method, which may come from an interface, and a target class used
 * in the current reflective invocation, find the corresponding target method
 * if there is one. E.g. the method may be <code>IFoo.bar()</code> and the
 * target class may be <code>DefaultFoo</code>. In this case, the method may be
 * <code>DefaultFoo.bar()</code>. This enables attributes on that method to be found.
 * <p><b>NOTE:</b> In contrast to {@link org.springframework.aop.support.AopUtils#getMostSpecificMethod},
 * this method does <i>not</i> resolve Java 5 bridge methods automatically.
 * Call {@link org.springframework.core.BridgeMethodResolver#findBridgedMethod}
 * if bridge method resolution is desirable (e.g. for obtaining metadata from
 * the original method definition)./*www  . j  a v  a 2 s  . c  o  m*/
 * @param method the method to be invoked, which may come from an interface
 * @param targetClass the target class for the current invocation.
 * May be <code>null</code> or may not even implement the method.
 * @return the specific target method, or the original method if the
 * <code>targetClass</code> doesn't implement it or is <code>null</code>
 * @see org.springframework.aop.support.AopUtils#getMostSpecificMethod
 */
public static Method getMostSpecificMethod(Method method, Class targetClass) {
    if (method != null && targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
        try {
            method = targetClass.getMethod(method.getName(), method.getParameterTypes());
        } catch (NoSuchMethodException ex) {
            // Perhaps the target class doesn't implement this method:
            // that's fine, just use the original method.
        }
    }
    return method;
}

From source file:lucee.runtime.reflection.storage.SoftMethodStorage.java

/**
 * stores arguments of a method/*w  ww.j  a  va  2  s.  c o m*/
 * @param method
 * @param methodArgs
 */
private void storeArgs(Method method, Array methodArgs) {

    Class[] pmt = method.getParameterTypes();
    Object o = methodArgs.get(pmt.length + 1, null);
    Method[] args;
    if (o == null) {
        args = new Method[1];
        methodArgs.setEL(pmt.length + 1, args);
    } else {
        Method[] ms = (Method[]) o;
        args = new Method[ms.length + 1];
        for (int i = 0; i < ms.length; i++) {
            args[i] = ms[i];
        }
        methodArgs.setEL(pmt.length + 1, args);
    }
    args[args.length - 1] = method;
}

From source file:net.kamhon.ieagle.util.VoUtil.java

/**
 * To upperCase object String field/*from w  w  w . j  a  v  a  2  s  .  c  o m*/
 * 
 * @param all
 *            default is false. true means toUpperCase all String field, false toUpperCase the fields have
 *            net.kamhon.ieagle.vo.core.annotation.ToUpperCase.
 * 
 * @param objects
 */
public static void toUpperCaseProperties(boolean all, Object... objects) {
    for (Object object : objects) {
        if (object == null) {
            continue;
        }

        // getter for String field only
        Map<String, Method> getterMap = new HashMap<String, Method>();
        // setter for String field only
        Map<String, Method> setterMap = new HashMap<String, Method>();

        Class<?> clazz = object.getClass();

        Method[] methods = clazz.getMethods();

        for (Method method : methods) {
            /*
             * log.debug("method = " + method.getName());
             * log.debug("method.getParameterTypes().length = " +
             * method.getParameterTypes().length); if
             * (method.getParameterTypes().length == 1)
             * log.debug("method.getParameterTypes()[0] = " +
             * method.getParameterTypes()[0]);
             * log.debug("method.getReturnType() = " +
             * method.getReturnType());
             * log.debug("================================================="
             * );
             */
            if (method.getName().startsWith("get") && method.getParameterTypes().length == 0
                    && method.getReturnType().equals(String.class)) {

                // if method name is getXxx
                String fieldName = method.getName().substring(3);
                fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);

                getterMap.put(fieldName, method);
            } else if (method.getName().startsWith("set") && method.getParameterTypes().length == 1
                    && method.getParameterTypes()[0] == String.class
                    && method.getReturnType().equals(void.class)) {
                // log.debug("setter = " + method.getName());

                // if method name is setXxx
                String fieldName = method.getName().substring(3);
                fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);

                setterMap.put(fieldName, method);
            }
        }

        // if the key exists in both getter & setter
        for (String key : getterMap.keySet()) {
            if (setterMap.containsKey(key)) {
                try {
                    Method getterMethod = getterMap.get(key);
                    Method setterMethod = setterMap.get(key);

                    // if not all, check on Field
                    if (!all) {
                        Field field = null;

                        Class<?> tmpClazz = clazz;
                        // looping up to superclass to get decleared field
                        do {
                            try {
                                field = tmpClazz.getDeclaredField(key);
                            } catch (Exception ex) {
                                // do nothing
                            }

                            if (field != null) {
                                break;
                            }

                            tmpClazz = tmpClazz.getSuperclass();
                        } while (tmpClazz != null);

                        ToUpperCase toUpperCase = field.getAnnotation(ToUpperCase.class);
                        if (toUpperCase == null || toUpperCase.upperCase() == false) {
                            continue;
                        }
                    }

                    String value = (String) getterMethod.invoke(object, new Object[] {});

                    if (StringUtils.isNotBlank(value))
                        setterMethod.invoke(object, value.toUpperCase());

                } catch (Exception ex) {
                    // log.error("Getter Setter for " + key + " has error ", ex);
                }
            }
        }
    }
}

From source file:com.consol.citrus.admin.converter.endpoint.AbstractEndpointConverter.java

/**
 *
 * @param setter//from   w  w w.ja va 2s.  c om
 * @param value
 * @return
 */
private Object getMethodArgument(Method setter, String value) {
    Class<?> type = setter.getParameterTypes()[0];
    if (type.isInstance(value)) {
        return type.cast(value);
    }

    try {
        return new SimpleTypeConverter().convertIfNecessary(value, type);
    } catch (ConversionNotSupportedException e) {
        if (String.class.equals(type)) {
            return value.toString();
        }

        throw new ApplicationRuntimeException("Unable to convert method argument type", e);
    }
}

From source file:com.home.ln_spring.ch4.mi.FormatMessageReplacer.java

private boolean isFormatMessageMethod(Method method) {
    //  ? ? //from   w  ww  . j  a v  a  2 s  . c o  m
    if (method.getParameterTypes().length != 1) {
        return false;
    }

    //  ? 
    if (!("formatMessage".equals(method.getName()))) {
        return false;
    }

    //   
    if (method.getReturnType() != String.class) {
        return false;
    }

    //   
    if (method.getParameterTypes()[0] != String.class) {
        return false;
    }

    return true;
}

From source file:com.mejmo.appletraus.client.domain.AppletRausInstanceProxy.java

public void assignMethods() {
    List<Method> methods = Util.getPublicMethods(applet.getClass());
    mappedMethods.clear();//www  .j a  v  a 2s .c  o m
    for (Method method : methods) {
        if (mappedMethods.containsKey(method.getName(), method.getParameterTypes().length)) {
            logger.error("Found public method " + method.getName()
                    + " but it was already discovered with this count of "
                    + "parameters. Overloading parameter types not supported yet.");
            continue;
        }
        logger.debug("Found public method " + method.getName() + " with " + method.getParameterTypes().length
                + " parameter count");
        mappedMethods.put(method.getName(), method.getParameterTypes().length, method);
    }
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Check whether the specified method is a property getter
 *
 * @param method The method//from www.  jav a 2s. com
 * @return true if the method is a property getter
 */
public static boolean isPropertyGetter(Method method) {
    return !Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers())
            && GrailsNameUtils.isGetter(method.getName(), method.getReturnType(), method.getParameterTypes());
}