List of utility methods to do Reflection Method Setter Get
Method | getSetterMethodByFieldName(String fieldName, Field field) get Setter Method By Field Name StringBuilder sb = new StringBuilder(fieldName.length() + 3); sb.append("set"); sb.append(fieldName); sb.setCharAt(3, Character.toUpperCase(sb.charAt(3))); try { return field.getDeclaringClass().getDeclaredMethod(sb.toString(), field.getType()); } catch (NoSuchMethodException e) { return null; ... |
Method | getSetterMethodByProperty(String propertyName, Class> beanClass, Class> setterParamType) get Setter Method By Property return getSetterMethod(toSetterName(propertyName), beanClass, setterParamType);
|
Method | getSetterMethodForClass(Class cls, String beanName, Class type) Obtain a (Java bean) setter method from a class or superclasses using reflection. return findDeclaredMethodInHeirarchy(cls, getJavaBeanSetterName(beanName), type);
|
Method | getSetterMethodFromGetter(final Method getter) Return a setter Method for a given getter Method . if (!isGetter(getter)) { throw new IllegalArgumentException("Method is not a getter method!"); String[] prefixes = { "get", "is" }; String setterName; for (String prefix : prefixes) { if (getter.getName().startsWith(prefix)) { String name = getter.getName().substring(prefix.length()); ... |
Method[] | getSetterMethods(Class> clazz) get Setter Methods if (clazz == null) { return new Method[] {}; Method[] methods = clazz.getMethods(); List<Method> mlist = new ArrayList<Method>(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String methodName = method.getName(); ... |
List | getSetterMethods(Class> clazz) get Setter Methods Method[] methods = clazz.getMethods(); ArrayList<Method> setterMethods = new ArrayList<Method>(methods.length); for (Method method : methods) { if (!Modifier.isPublic(method.getModifiers()) || (method.getParameterTypes().length != 1) || !method.getName().startsWith("set")) { continue; setterMethods.add(method); ... |
List | getSetterMethods(Class> clazz) get Setter Methods List<Method> props = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { String methodName = method.getName(); if (SETTER_METHOD_NAME_PATTERN.matcher(methodName).find() && method.getParameterTypes().length == 1) { props.add(method); return props; ... |
List | getSetterMethods(Class> objectType) get Setter Methods List<Method> result = new ArrayList<Method>(); Method[] methods = objectType.getMethods(); for (Method method : methods) { if (isValidSetterMethod(method)) { result.add(method); return result; ... |
Map | getSetterMethods(Class> pojoClass) Gets the setters of a pojo as a map of String as key and Method as value. HashMap<String, Method> methods = new HashMap<String, Method>(); fillSetterMethods(pojoClass, methods); return methods; |
List | getSetterMethods(final Class> clazz) get Setter Methods final List<Method> result = new ArrayList<Method>(); for (Method m : clazz.getMethods()) { if (m.getName().startsWith("set")) { if (m.getParameterTypes().length == 1) { result.add(m); return result; |