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.mobius.software.mqtt.parser.test.StaticData.java

public static boolean isGetter(Method method) {
    if (!method.getName().startsWith("get"))
        return false;
    if (method.getParameterTypes().length != 0)
        return false;
    if (void.class.equals(method.getReturnType()))
        return false;
    return true;/*  w w  w.ja va 2  s.com*/
}

From source file:com.wavemaker.tools.apidocs.tools.parser.util.MethodUtils.java

public static String getMethodUniqueIdentifierId(Method method) {
    Class<?>[] parameterTypes = method.getParameterTypes();
    HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
    for (Class parameterType : parameterTypes) {
        hashCodeBuilder.append(parameterType.getCanonicalName());
    }// w w  w  .  j  a  v a 2  s.  c  o  m
    return method.getName() + "-" + parameterTypes.length + "-" + hashCodeBuilder.toHashCode();
}

From source file:Main.java

private static Object[] bindParameters(Method method, String[] args) {
    List<Object> parameters = new ArrayList<Object>();
    Class<?>[] parameterTypes = method.getParameterTypes();
    for (int i = 0, len = parameterTypes.length; i < len; i++) {
        Class<?> type = parameterTypes[i];
        int remaining = Math.max(0, args.length - i);
        if (type.equals(String[].class)) {
            String[] rest = new String[remaining];
            System.arraycopy(args, 1, rest, 0, remaining);
            parameters.add(rest);//from  w  w  w .j a  va2  s .co  m
        } else if (remaining > 0) {
            parameters.add(convertParameter(args[i], parameterTypes[i]));
        } else {
            parameters.add(null);
        }
    }
    return parameters.toArray();
}

From source file:org.psnively.scala.beans.ScalaBeanInfo.java

private static boolean isScalaGetter(Method method) {
    return method.getParameterTypes().length == 0 && !method.getReturnType().equals(Void.TYPE)
            && !(method.getName().startsWith("get") || method.getName().startsWith("is"));
}

From source file:org.psnively.scala.beans.ScalaBeanInfo.java

public static boolean isScalaSetter(Method method) {
    return method.getParameterTypes().length == 1 && method.getReturnType().equals(Void.TYPE)
            && method.getName().endsWith(SCALA_SETTER_SUFFIX);
}

From source file:Main.java

public static Map<String, Object> getProperties(Object object, boolean includeSuperClasses, boolean deepCopy) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    if (object == null) {
        return map;
    }/* ww w  .  j a va2s  .co  m*/

    Class<?> objectClass = object.getClass();
    Method[] methods = includeSuperClasses ? objectClass.getMethods() : objectClass.getDeclaredMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 0 && !method.getReturnType().equals(Void.TYPE)) {
            String methodName = method.getName();
            String propertyName = "";
            if (methodName.startsWith("get")) {
                propertyName = methodName.substring(3);
            } else if (methodName.startsWith("is")) {
                propertyName = methodName.substring(2);
            }
            if (propertyName.length() > 0 && Character.isUpperCase(propertyName.charAt(0))) {
                propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);

                Object value = null;
                try {
                    value = method.invoke(object);
                } catch (Exception e) {
                }

                Object value2 = value;

                if (!deepCopy) {
                    map.put(propertyName, value);
                } else {
                    if (isSimpleObject(value)) {
                        map.put(propertyName, value);
                    } else if (value instanceof Map) {
                        Map<String, Object> submap = new HashMap<String, Object>();
                        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
                            submap.put(String.valueOf(entry.getKey()),
                                    convertObject(entry.getValue(), includeSuperClasses));
                        }
                        map.put(propertyName, submap);
                    } else if (value instanceof Iterable) {
                        List<Object> sublist = new ArrayList<Object>();
                        for (Object v : (Iterable<?>) object) {
                            sublist.add(convertObject(v, includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else if (value.getClass().isArray()) {
                        List<Object> sublist = new ArrayList<Object>();
                        int length = Array.getLength(value);
                        for (int i = 0; i < length; i++) {
                            sublist.add(convertObject(Array.get(value, i), includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else {
                        map.put(propertyName, getProperties(value, includeSuperClasses, deepCopy));
                    }
                }
            }
        }
    }

    return map;
}

From source file:Main.java

public static boolean hasGetterSignature(Method m) {
    // First: static methods can't be getters
    if (Modifier.isStatic(m.getModifiers())) {
        return false;
    }/*ww w. j ava 2  s . c  o  m*/
    // Must take no args
    Class<?>[] pts = m.getParameterTypes();
    if (pts != null && pts.length != 0) {
        return false;
    }
    // Can't be a void method
    if (Void.TYPE == m.getReturnType()) {
        return false;
    }
    // Otherwise looks ok:
    return true;
}

From source file:Main.java

public static String getDesc(Method paramMethod) {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("(");
    Class[] arrayOfClass = paramMethod.getParameterTypes();
    for (int i = 0; i < arrayOfClass.length; i++) {
        localStringBuffer.append(getDesc(arrayOfClass[i]));
    }// ww w .  j  av  a  2 s  .co  m
    localStringBuffer.append(")");
    localStringBuffer.append(getDesc(paramMethod.getReturnType()));
    return localStringBuffer.toString();
}

From source file:com.agileapes.couteau.context.spring.event.impl.GenericTranslationScheme.java

static boolean isGetter(Method method) {
    return Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())
            && method.getParameterTypes().length == 0 && !method.getReturnType().equals(void.class)
            && (method.getName().matches("get[A-Z].*")
                    || (method.getName().matches("is[A-Z].*") && method.getReturnType().equals(boolean.class)));
}

From source file:com.sonatype.security.ldap.api.DeepEqualsBuilder.java

private static boolean classHasEqualsMethod(Class clazz) {
    if (clazz != null) {
        Method[] methods = clazz.getDeclaredMethods();
        for (int ii = 0; ii < methods.length; ii++) {
            Method method = methods[ii];
            if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1
                    && method.getParameterTypes()[0].equals(Object.class)) {
                return true;
            }/*from  w w  w.j a v a 2  s  . c o m*/
        }
    }
    return false;
}