List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:com.example.administrator.mytestdemo.premission.yzjpermission.PermissionUtils.java
static <T extends Annotation> Method[] findMethodForRequestCode(Class<?> source, Class<T> annotation, int requestCode) { List<Method> methods = new ArrayList<>(1); for (Method method : source.getDeclaredMethods()) if (method.isAnnotationPresent(annotation)) if (isSameRequestCode(method, annotation, requestCode)) methods.add(method);/* w ww.j a v a2 s . co m*/ return methods.toArray(new Method[methods.size()]); }
From source file:com.jaspersoft.jasperserver.util.QueryUtil.java
/** * Execute DataBaseMetaData methods using reflection * @param dmd/*from w w w . j a v a 2s . com*/ * @param methodName * @param parameters * @return * @throws ClassNotFoundException */ public static Method findMethod(DatabaseMetaData dmd, String methodName, Object[] parameters) throws ClassNotFoundException { long startTime = System.currentTimeMillis(); try { if (logger.isDebugEnabled()) { logger.debug("Enter findMethod .. Start Time" + System.currentTimeMillis()); } Class cl = Class.forName("java.sql.DatabaseMetaData"); Method[] methods = cl.getDeclaredMethods(); // Trying to avoid collision of methods with varying parameters and avoid having to do parameter class types int paramCount = 0; if (null != parameters) { paramCount = parameters.length; } for (Method m : methods) { if (m.getName().equals(methodName)) { if (Modifier.isPublic(m.getModifiers()) && m.getParameterTypes().length == paramCount) { return m; } } } //for return null; } finally { if (logger.isDebugEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("Exit findMethod .. Total Time Spent: " + elapsedTime); } } }
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];/* w ww.j a va2s . c o m*/ 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); } } }
From source file:org.apache.bval.util.reflection.Reflection.java
/** * Convenient point for {@link Privilizing} {@link Class#getDeclaredMethods()}. * @param clazz/*from www . ja v a 2s .com*/ * @return {@link Method} array */ public static Method[] getDeclaredMethods(final Class<?> clazz) { return clazz.getDeclaredMethods(); }
From source file:jp.go.nict.langrid.testresource.loader.NodeLoader_1_2.java
protected static void addProperties(Class<?> clazz, Set<String> properties, Set<String> tupleProperties) { for (Method m : clazz.getDeclaredMethods()) { if (m.getParameterTypes().length != 1) continue; String name = m.getName(); if (!name.startsWith("set")) continue; if (!Modifier.isPublic(m.getModifiers())) continue; String propName = name.substring(3, 4).toLowerCase() + name.substring(4); if (m.getParameterTypes()[0].isArray()) { tupleProperties.add(propName); } else {// w w w . j av a 2s . co m properties.add(propName); } } }
From source file:MethodHashing.java
public static Method findMethodByHash(Class clazz, long hash) throws Exception { Method[] methods = clazz.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (methodHash(methods[i]) == hash) return methods[i]; }//from w w w. ja v a 2s . c om if (clazz.getSuperclass() != null) { return findMethodByHash(clazz.getSuperclass(), hash); } return null; }
From source file:cz.jirutka.validator.collection.internal.AnnotationUtils.java
/** * Whether the annotation type contains attribute of the specified name. *///from w w w .ja v a2 s . c o m public static boolean hasAttribute(Class<? extends Annotation> annotationType, String attributeName) { for (Method m : annotationType.getDeclaredMethods()) { if (m.getName().equals(attributeName)) { return true; } } return false; }
From source file:Main.java
public static String getSetMethod(Class<?> c, String prefix, String postfix) { StringWriter sw = new StringWriter(); if (prefix == null) prefix = ""; if (postfix == null) postfix = ""; Method[] ms = c.getDeclaredMethods(); if (ms != null && ms.length > 0) { for (Method m : ms) { String name = m.getName(); if (name.startsWith("set") && isPublicNoStatic(m.getModifiers())) { sw.append(prefix).append(name).append("(").append(postfix).append(");\r\n"); }//from w w w.ja v a2s .c om } } return sw.toString(); }
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];//from w ww . j a va 2 s. c o m 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 source file:com.xhsoft.framework.common.utils.ReflectUtil.java
/** * <p>Description:ReflectionMap?</p> * @param target/* www .ja v a2 s . c om*/ * @return Map<String,Object> * @author wanggq * @since 2009-9-9 */ @SuppressWarnings("unchecked") public static Map<String, Object> getMapFieldData(Object target) { Map<String, Object> map = new HashMap<String, Object>(); Class clazz = target.getClass(); Field[] fields = clazz.getDeclaredFields(); Method[] methods = clazz.getDeclaredMethods(); for (Field field : fields) { String fieldName = field.getName(); if ("messageTypeId".equals(fieldName)) { continue; } String getMethod = "get" + StringUtils.capitalize(fieldName); for (Method method : methods) { if (method.getName().equals(getMethod)) { try { Object ret = method.invoke(target, null); map.put(fieldName, ret); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return map; }