List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:Main.java
public static String parseParameterTypes(Method method) { String parameterTypes = ""; for (Class<?> parameterClass : method.getParameterTypes()) parameterTypes += parseClassType(parameterClass); return parameterTypes; }
From source file:Main.java
/** * Convenience method for obtaining most non-null human readable properties * of a JComponent. Array properties are not included. * <P>//from w w w . j a v a 2s . c o m * Implementation note: The returned value is a HashMap. This is subject * to change, so callers should code against the interface Map. * * @param component the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(JComponent component) { Map<Object, Object> retVal = new HashMap<Object, Object>(); Class<?> clazz = component.getClass(); Method[] methods = clazz.getMethods(); Object value = null; for (Method method : methods) { if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) { try { Class returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && !setExclude.contains(method.getName())) { String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be accessed } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { } } } return retVal; }
From source file:Main.java
private static List<Object> createParamsArray(Method m, List<Object> availableParams) { List<Object> params = new ArrayList<Object>(); Class<?>[] paramTypes = m.getParameterTypes(); for (Class<?> type : paramTypes) { for (Object param : availableParams) { if (param != null && type.isAssignableFrom(param.getClass())) { params.add(param);/*w ww. j a va 2 s . c om*/ } } } return params; }
From source file:Main.java
private static final Method findMethod(Class<?> clazz, String name, List<Class<?>> actualArgs) { for (final Method m : clazz.getMethods()) { if (m.getName().equals(name) && callableWith(m.getParameterTypes(), actualArgs)) { return m; }/*from www . j av a 2s . c o m*/ } return null; }
From source file:Main.java
static boolean isSuperMethodAnnotated(Class<?> superClass, Method method, Class<? extends Annotation> annotationClass) { try {//from w w w. j a v a 2 s. c o m return superClass.getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(annotationClass); } catch (NoSuchMethodException ignored) { return false; } }
From source file:Main.java
public static String generateNameOfMethod(Class<?> providerClass, Method method) { StringBuilder buider = new StringBuilder(providerClass.getName()).append(method.getName()); Class<?>[] paramTypes = method.getParameterTypes(); for (Class<?> c : paramTypes) { buider.append(c.getName());/* w w w . j av a 2 s .c o m*/ } return buider.toString(); }
From source file:Main.java
/** * Convenience method for obtaining most non-null human readable properties * of a JComponent. Array properties are not included. * <P>// w ww . j av a 2 s.c o m * Implementation note: The returned value is a HashMap. This is subject to * change, so callers should code against the interface Map. * * @param component * the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(final JComponent component) { final Map<Object, Object> retVal = new HashMap<Object, Object>(); final Class<?> clazz = component.getClass(); final Method[] methods = clazz.getMethods(); Object value = null; for (final Method method : methods) { if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) { try { final Class returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && !setExclude.contains(method.getName())) { final String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be // accessed } catch (final IllegalAccessException ex) { } catch (final IllegalArgumentException ex) { } catch (final InvocationTargetException ex) { } } } return retVal; }
From source file:Main.java
/** * Convenience method for obtaining most non-null human readable properties * of a JComponent. Array properties are not included. * <P>//w w w. j a va 2 s.com * Implementation note: The returned value is a HashMap. This is subject * to change, so callers should code against the interface Map. * * @param component the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(JComponent component) { Map<Object, Object> retVal = new HashMap<>(); Class<?> clazz = component.getClass(); Method[] methods = clazz.getMethods(); Object value = null; for (Method method : methods) { if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) { try { Class<?> returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && !setExclude.contains(method.getName())) { String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be accessed } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { } } } return retVal; }
From source file:ShowClass.java
public static void printMethodOrConstructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();/*from w ww. jav a 2 s . co m*/ parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typeName(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typeName(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(exceptions[i])); } System.out.println(";"); }
From source file:Main.java
public static void print_method_or_constructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();/*from w w w.j a v a 2 s.co m*/ parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(exceptions[i])); } System.out.println(";"); }