List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:MainClass.java
public static void printMethods(Class cl) { Method[] methods = cl.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; Class retType = m.getReturnType(); Class[] paramTypes = m.getParameterTypes(); String name = m.getName(); System.out.print(Modifier.toString(m.getModifiers())); System.out.print(" " + retType.getName() + " " + name + "("); for (int j = 0; j < paramTypes.length; j++) { if (j > 0) System.out.print(", "); System.out.print(paramTypes[j].getName()); }//from ww w .j a v a 2 s . c o m System.out.println(");"); } }
From source file:Main.java
public static synchronized Method getSetter(final Class targetClass, final String propertyName) { String setterName = "set" + Character.toUpperCase(propertyName.charAt(0)); if (setterName.length() > 1) setterName += propertyName.substring(1); final Method[] methods = targetClass.getMethods(); for (Method m : methods) { if (m.getName().equals(setterName) && m.getParameterTypes().length == 1) return m; }/* www . ja v a2 s .c o m*/ return null; }
From source file:springfox.documentation.schema.property.bean.Accessors.java
public static boolean maybeAGetter(Method method) { if (method.getParameterTypes().length == 0) { return notAVoidMethod(method); }// w w w.j av a 2 s . c o m return false; }
From source file:springfox.documentation.schema.property.bean.Accessors.java
public static boolean maybeASetter(Method method) { return method.getParameterTypes().length == 1; }
From source file:Util.java
private static void fillSetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillSetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 1 && m.getName().startsWith(SET) && Modifier.isPublic(m.getModifiers())) { baseMap.put(toProperty(SET.length(), m.getName()), m); }/*w ww. j a va 2 s . c om*/ } }
From source file:Main.java
public static boolean isAccessor(Method method, String findValue) { boolean accessor = false; final Class<?>[] parameterTypes = method.getParameterTypes(); final String methodName = method.getName(); if (parameterTypes.length == 0 && method.getReturnType() != null && (methodName.startsWith("get") || methodName.startsWith("is")) && methodName.toLowerCase().indexOf(findValue.toLowerCase()) > -1) { accessor = true;//from www . j a va 2 s .c o m } return accessor; }
From source file:Util.java
private static void fillGetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillGetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && m.getReturnType() != null && Modifier.isPublic(m.getModifiers())) { String name = m.getName(); if (name.startsWith(IS)) baseMap.put(toProperty(IS.length(), name), m); else if (name.startsWith(GET)) baseMap.put(toProperty(GET.length(), name), m); }//from w ww .j a va 2 s .c om } }
From source file:Main.java
public static String getMethodName(Method method, Class<?>[] parameterClasses, String rightCode) { if (method.getParameterTypes().length > parameterClasses.length) { Class<?>[] types = method.getParameterTypes(); StringBuilder buf = new StringBuilder(rightCode); for (int i = parameterClasses.length; i < types.length; i++) { if (buf.length() > 0) { buf.append(","); }// w ww . ja v a2 s.c om Class<?> type = types[i]; String def; if (type == boolean.class) { def = "false"; } else if (type == char.class) { def = "\'\\0\'"; } else if (type == byte.class || type == short.class || type == int.class || type == long.class || type == float.class || type == double.class) { def = "0"; } else { def = "null"; } buf.append(def); } } return method.getName() + "(" + rightCode + ")"; }
From source file:com.ngdata.sep.util.io.Closer.java
public static void close(Object object) { if (object != null) { try {// ww w .jav a2s . com Method closeMethod = null; Method[] methods = object.getClass().getMethods(); for (Method method : methods) { if (method.getParameterTypes().length == 0) { if (method.getName().equals("close")) { closeMethod = method; break; } else if (method.getName().equals("shutdown")) { closeMethod = method; } else if (method.getName().equals("stop")) { closeMethod = method; } } } if (closeMethod != null) { closeMethod.invoke(object); } else { Log log = LogFactory.getLog(Closer.class); log.error("Do not know how to close object of type " + object.getClass().getName()); } } catch (Throwable t) { Log log = LogFactory.getLog(Closer.class); log.error("Error closing object of type " + object.getClass().getName(), t); } } }
From source file:Main.java
static <T extends Annotation> T getSuperMethodAnnotation(Class<?> superClass, Method method, Class<T> annotationClass) { try {/* w w w.jav a2 s.c o m*/ return superClass.getMethod(method.getName(), method.getParameterTypes()) .getAnnotation(annotationClass); } catch (NoSuchMethodException ignored) { return null; } }