List of utility methods to do Reflection Method Setter Get
String | getSetterName(Field field) get Setter Name String name = field.getName(); return "set" + name.substring(0, 1).toUpperCase(Locale.US) + name.substring(1); |
String | getSetterName(final Field field) get Setter Name return "set" + capitalizeFieldName(field); |
String | getSetterName(Method m) get Setter Name String name = m.getName(); if (name.substring(0, 3).equals("set")) name = name.substring(3); return name; |
String | getSetterName(Method m) Get setter name. String name = m.getName(); if (name.startsWith("set") && (name.length() >= 4) && m.getReturnType().equals(void.class) && (m.getParameterTypes().length == 1)) { return Character.toLowerCase(name.charAt(3)) + name.substring(4); return null; |
String | getSetterName(Method method) get Setter Name String name = getDefaultPropertyName(method); if (name == null) return null; return "set" + name; |
String | getSetterName(String name) get Setter Name return "set" + capitalizeFirstLetter(name); |
Method | getSetterOrGetter(Class clazz, String name, boolean isSetter) get Setter Or Getter String exceptMethodName = getSetterOrGetterName(name, isSetter); Method[] methods = clazz.getMethods(); if (methods != null) { for (Method method : methods) { if (method.getName().equals(exceptMethodName) && !Modifier.isAbstract(method.getModifiers()) && Modifier.isPublic(method.getModifiers())) { return method; return null; |
Map | getSetters(Class clazz) Returns a Map of setter methods of the given class. The key of the map contains the name of the attribute that can be accessed by the setter, the value the setter itself (an instance of java.lang.reflect.Method). final Map<String, Method> accessors = new HashMap<String, Method>(); final Method[] methods = clazz.getMethods(); for (Method method : methods) { String name; String methodName; methodName = method.getName(); if (!methodName.startsWith("set")) { continue; ... |
Method[] | getSetters(Class clazz) get Setters List<Method> outM = new ArrayList<Method>(); for (Method m : clazz.getMethods()) { if (m.getParameterTypes().length == 1 && m.getName().startsWith("set") && m.getReturnType() == null) { outM.add(m); return outM.toArray(new Method[outM.size()]); |
List | getSetters(Class klass) get Setters List<Method> res = new ArrayList<>(); Method[] methods = klass.getDeclaredMethods(); for (Method mth : methods) { int mod = mth.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isStatic(mod) && mth.getParameterCount() == 1 && mth.getName().matches("^set.*") && !isDeprecated(mth)) { res.add(mth); res.sort((o1, o2) -> { int cmp = o1.getName().compareToIgnoreCase(o2.getName()); return cmp; }); return res; |