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.laxser.blitz.web.impl.module.ControllerRef.java

private boolean quicklyPass(List<Method> pastMethods, Method method, Class<?> controllerClass) {
    // public, not static, not abstract, @Ignored
    if (!Modifier.isPublic(method.getModifiers()) || Modifier.isAbstract(method.getModifiers())
            || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(Ignored.class)) {
        if (logger.isDebugEnabled()) {
            logger.debug("ignores method of controller " + controllerClass.getName() + "." + method.getName()
                    + "  [@ignored?not public?abstract?static?]");
        }//  w  w w .  j  av  a 2  s .com
        return true;
    }
    // ?(?)?????
    for (Method past : pastMethods) {
        if (past.getName().equals(method.getName())) {
            if (Arrays.equals(past.getParameterTypes(), method.getParameterTypes())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBReflector.java

/**
 * Returns the annotated {@link DynamoDBRangeKey} getter for the class
 * given, or null if the class doesn't have one.
 *///from   www  .jav a  2 s  .c  o m
<T> Method getPrimaryRangeKeyGetter(Class<T> clazz) {
    synchronized (primaryRangeKeyGetterCache) {
        if (!primaryRangeKeyGetterCache.containsKey(clazz)) {
            Method rangeKeyMethod = null;
            for (Method method : getRelevantGetters(clazz)) {
                if (method.getParameterTypes().length == 0
                        && ReflectionUtils.getterOrFieldHasAnnotation(method, DynamoDBRangeKey.class)) {
                    rangeKeyMethod = method;
                    break;
                }
            }
            primaryRangeKeyGetterCache.put(clazz, rangeKeyMethod);
        }
        return primaryRangeKeyGetterCache.get(clazz);
    }
}

From source file:com.haulmont.cuba.core.app.AbstractBeansMetadata.java

protected List<MethodInfo> getAvailableMethods(String beanName) {
    List<MethodInfo> methods = new ArrayList<>();
    try {//from w  w  w.  j a v  a 2s  . c o  m
        AutowireCapableBeanFactory beanFactory = AppContext.getApplicationContext()
                .getAutowireCapableBeanFactory();
        if (beanFactory instanceof CubaDefaultListableBeanFactory) {
            BeanDefinition beanDefinition = ((CubaDefaultListableBeanFactory) beanFactory)
                    .getBeanDefinition(beanName);
            if (beanDefinition.isAbstract())
                return methods;
        }

        Object bean = AppBeans.get(beanName);

        @SuppressWarnings("unchecked")
        List<Class> classes = ClassUtils.getAllInterfaces(bean.getClass());
        for (Class aClass : classes) {
            if (aClass.getName().startsWith("org.springframework."))
                continue;

            Class<?> targetClass = bean instanceof TargetClassAware ? ((TargetClassAware) bean).getTargetClass()
                    : bean.getClass();

            for (Method method : aClass.getMethods()) {
                if (isMethodAvailable(method)) {
                    Method targetClassMethod = targetClass.getMethod(method.getName(),
                            method.getParameterTypes());
                    List<MethodParameterInfo> methodParameters = getMethodParameters(targetClassMethod);
                    MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
                    addMethod(methods, methodInfo);
                }
            }

            if (methods.isEmpty()) {
                for (Method method : bean.getClass().getMethods()) {
                    if (!method.getDeclaringClass().equals(Object.class) && isMethodAvailable(method)) {
                        List<MethodParameterInfo> methodParameters = getMethodParameters(method);
                        MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
                        addMethod(methods, methodInfo);
                    }
                }
            }
        }
    } catch (Throwable t) {
        log.debug(t.getMessage());
    }
    return methods;
}

From source file:com.github.dactiv.fear.service.RemoteApiCaller.java

/**
 * ??/* w w w . j  av  a2  s  .  c o m*/
 *
 * @param targetClass  class
 * @param method      ??
 * @param paramTypes  ?
 *
 * @return 
 */
private Method findParamMethod(Class<?> targetClass, String method, Class<?>[] paramTypes) {

    // ?
    Method[] methods = (targetClass.isInterface() ? targetClass.getMethods()
            : ReflectionUtils.getAllDeclaredMethods(targetClass));

    // ?
    for (Method m : methods) {
        // ??
        Class<?>[] methodParamTypes = m.getParameterTypes();
        // ??????
        if (m.getName().equals(method) && methodParamTypes.length == paramTypes.length) {
            // ??
            Boolean flag = Boolean.TRUE;
            // ??flag  true
            for (int i = 0; i < methodParamTypes.length; i++) {

                Class<?> paramTarget = paramTypes[i];
                Class<?> paramSource = methodParamTypes[i];

                if (paramTarget != null && paramTarget != paramSource
                        && !paramSource.isAssignableFrom(paramTarget)) {
                    flag = Boolean.FALSE;
                }

            }

            if (flag) {
                cacheService(targetClass, m, paramTypes);
                return m;
            }

        }

    }

    return null;
}

From source file:com.laxser.blitz.web.impl.module.ControllerRef.java

private boolean ignoresCommonMethod(Method method) {
    // ? Object 
    if (ClassUtils.hasMethod(Object.class, method.getName(), method.getParameterTypes())) {
        return true;
    }/*w w  w . jav  a  2  s.  co  m*/

    // ?java bean??
    String name = method.getName();
    if (name.startsWith("get") && name.length() > 3 && Character.isUpperCase(name.charAt("get".length()))
            && method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
        if (null == method.getAnnotation(Get.class)) {
            return true;
        }
    }
    if (name.startsWith("is") && name.length() > 3 && Character.isUpperCase(name.charAt("is".length()))
            && method.getParameterTypes().length == 0
            && (method.getReturnType() == boolean.class || method.getReturnType() == Boolean.class)) {
        if (null == method.getAnnotation(Get.class)) {
            return true;
        }
    }
    if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt("set".length()))
            && method.getParameterTypes().length == 1 && method.getReturnType() == void.class) {
        if (null == method.getAnnotation(Post.class)) {
            return true;
        }
    }
    return false;
}

From source file:com.springframework.beans.GenericTypeAwarePropertyDescriptor.java

public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName, Method readMethod,
        Method writeMethod, Class<?> propertyEditorClass) throws IntrospectionException {

    super(propertyName, null, null);

    if (beanClass == null) {
        throw new IntrospectionException("Bean class must not be null");
    }/* w ww .  j  a  va 2  s  .  c  om*/
    this.beanClass = beanClass;

    Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
    Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
    if (writeMethodToUse == null && readMethodToUse != null) {
        // Fallback: Original JavaBeans introspection might not have found matching setter
        // method due to lack of bridge method resolution, in case of the getter using a
        // covariant return type whereas the setter is defined for the concrete property type.
        Method candidate = ClassUtils.getMethodIfAvailable(this.beanClass,
                "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
        if (candidate != null && candidate.getParameterTypes().length == 1) {
            writeMethodToUse = candidate;
        }
    }
    this.readMethod = readMethodToUse;
    this.writeMethod = writeMethodToUse;

    if (this.writeMethod != null) {
        if (this.readMethod == null) {
            // Write method not matched against read method: potentially ambiguous through
            // several overloaded variants, in which case an arbitrary winner has been chosen
            // by the JDK's JavaBeans Introspector...
            Set<Method> ambiguousCandidates = new HashSet<Method>();
            for (Method method : beanClass.getMethods()) {
                if (method.getName().equals(writeMethodToUse.getName()) && !method.equals(writeMethodToUse)
                        && !method.isBridge()) {
                    ambiguousCandidates.add(method);
                }
            }
            if (!ambiguousCandidates.isEmpty()) {
                this.ambiguousWriteMethods = ambiguousCandidates;
            }
        }
        this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
        GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
    }

    if (this.readMethod != null) {
        this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
    } else if (this.writeMethodParameter != null) {
        this.propertyType = this.writeMethodParameter.getParameterType();
    }

    this.propertyEditorClass = propertyEditorClass;
}

From source file:com.glaf.core.util.ReflectUtils.java

public static boolean isBeanPropertyReadMethod(Method method) {
    return method != null && Modifier.isPublic(method.getModifiers())
            && !Modifier.isStatic(method.getModifiers()) && method.getReturnType() != void.class
            && method.getDeclaringClass() != Object.class && method.getParameterTypes().length == 0
            && ((method.getName().startsWith("get") && method.getName().length() > 3)
                    || (method.getName().startsWith("is") && method.getName().length() > 2));
}

From source file:com.searchbox.framework.service.SearchAdapterService.java

private void doAdapt(Class<?> requiredArg, Map<Method, Object> methods, List<Object> objects) {

    // Generate Parameter bag
    Map<Class<?>, List<Object>> arguments = mapArguments(new HashMap<Class<?>, List<Object>>(), objects);

    LOGGER.trace("XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO");
    LOGGER.trace("XOXOXOXOXOXOXOXOXOXOXOXO filter: "
            + ((requiredArg == null) ? "null" : requiredArg.getSimpleName()));
    LOGGER.trace("XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO");
    for (Class<?> clazz : arguments.keySet()) {
        LOGGER.trace("Bag for class: " + clazz.getSimpleName());
        for (Object obj : arguments.get(clazz)) {
            if (Collection.class.isAssignableFrom(obj.getClass())) {
                Iterator<?> obji = ((Collection<?>) obj).iterator();
                String out = "\tin bag: ";
                while (obji.hasNext()) {
                    out += obji.next().getClass().getSimpleName() + ", ";
                }/*from   w w w . j a  va  2  s.c  o  m*/
                LOGGER.trace(out);
            } else {
                LOGGER.trace("\tin bag: " + obj.getClass().getSimpleName());
            }
        }
    }
    LOGGER.trace("~~~~~~~~~~~~~~~~~~~~~~~~");

    for (Method method : matchingdMethods(requiredArg, methods.keySet(), arguments.keySet())) {
        Class<?>[] paramTypes = method.getParameterTypes();
        Object[][] parameters = new Object[paramTypes.length][];

        // Generate parameter matrix for permutation.
        LOGGER.debug("Got a matching method: " + method.getName());
        int x = 0;
        for (Class<?> paramType : paramTypes) {
            List<Object> currentparamters = new ArrayList<Object>();
            for (Entry<Class<?>, List<Object>> entry : arguments.entrySet()) {
                if (paramType.isAssignableFrom(entry.getKey())) {
                    for (Object goodparam : entry.getValue()) {
                        currentparamters.add(goodparam);
                    }
                }
            }
            parameters[x] = currentparamters.toArray(new Object[0]);
            x++;
        }

        LOGGER.debug("We'll need {} params", paramTypes.length);
        LOGGER.debug("Method bag is: ");
        for (int i = 0; i < paramTypes.length; i++) {
            LOGGER.debug("Bag for param: {} is this bag a list? {}", paramTypes[i].getSimpleName(),
                    parameters[i].getClass().getSimpleName());
            for (Object obj : parameters[i]) {
                LOGGER.debug("\tin bag: {}", obj.getClass().getSimpleName());
            }
        }

        // Execute method with permutated arguments.
        List<Object[]> argumentBags = ReflectionUtils.findAllArgumentPermutations(parameters);
        for (Object[] argumentsInBag : argumentBags) {
            LOGGER.trace("Found a working permutation for method: {} ", method.getName());
            for (Object obj : argumentsInBag) {
                LOGGER.trace("\t{}", obj.getClass().getSimpleName());
            }
            this.executeMethod(methods.get(method), method, argumentsInBag);
        }
        LOGGER.trace("~~~~~~~~~~~~~~~~~~~~~~~~");
    }
}

From source file:com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBReflector.java

/**
 * Returns the annotated {@link DynamoDBHashKey} getter for the class given,
 * throwing an exception if there isn't one.
 *//*from ww  w .  j a  v  a  2s . com*/
<T> Method getPrimaryHashKeyGetter(Class<T> clazz) {
    Method hashKeyMethod;
    synchronized (primaryHashKeyGetterCache) {
        if (!primaryHashKeyGetterCache.containsKey(clazz)) {
            for (Method method : getRelevantGetters(clazz)) {
                if (method.getParameterTypes().length == 0
                        && ReflectionUtils.getterOrFieldHasAnnotation(method, DynamoDBHashKey.class)) {
                    primaryHashKeyGetterCache.put(clazz, method);
                    break;
                }
            }
        }
        hashKeyMethod = primaryHashKeyGetterCache.get(clazz);
    }

    if (hashKeyMethod == null) {
        throw new DynamoDBMappingException(
                "Public, zero-parameter hash key property must be annotated with " + DynamoDBHashKey.class);
    }
    return hashKeyMethod;
}

From source file:com.espertech.esper.core.ResultDeliveryStrategyTypeArr.java

/**
 * Ctor.//from ww  w .j  a  v  a2 s. co m
 * @param subscriber is the receiver to method invocations
 * @param method is the method to deliver to
 */
public ResultDeliveryStrategyTypeArr(String statementName, Object subscriber, Method method) {
    this.statementName = statementName;
    this.subscriber = subscriber;
    FastClass fastClass = FastClass.create(Thread.currentThread().getContextClassLoader(),
            subscriber.getClass());
    this.fastMethod = fastClass.getMethod(method);
    componentType = method.getParameterTypes()[0].getComponentType();
}