List of utility methods to do Reflection Method Getter Get
String | getGetterName(Method m) Get getter name. String name = m.getName(); if (name.startsWith("get") && (name.length() >= 4) && !m.getReturnType().equals(void.class) && (m.getParameterTypes().length == 0)) { return Character.toLowerCase(name.charAt(3)) + name.substring(4); if (name.startsWith("is") && (name.length() >= 3) && (m.getReturnType().equals(boolean.class) || m.getReturnType().equals(Boolean.class)) && (m.getParameterTypes().length == 0)) { ... |
String | getGetterName(Method method) get Getter Name String name = getDefaultPropertyName(method); if (name == null) return null; return "get" + name; |
String | getGetterName(Method mtd) get Getter Name String name = mtd.getName(); if (name.startsWith("get")) { return Character.toLowerCase(name.charAt(3)) + name.substring(4); if (name.startsWith("is")) { return Character.toLowerCase(name.charAt(2)) + name.substring(3); return null; ... |
Method | getGetterOrNull(Class> clazz, String name, Class> type) get Getter Or Null Class<?> beanClass = clazz; String methodName = ((type.equals(Boolean.class) || type.equals(boolean.class)) ? "is" : "get") + name; while (beanClass != null && !beanClass.equals(Object.class)) { try { return beanClass.getDeclaredMethod(methodName); } catch (SecurityException | NoSuchMethodException e) { beanClass = beanClass.getSuperclass(); ... |
String | getGetterPropertyName(Method getterMethod) get Getter Property Name if (getterMethod == null) { return null; String name = getterMethod.getName(); if (name.startsWith("is")) { return name.substring(2); } else { return name.substring(3); ... |
List | getGetters(Class c) get Getters List<Method> list = new ArrayList<Method>(); Method[] methods = c.getMethods(); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName(); if (!name.startsWith("get") || name.equals("getClass") || name.equals("getInstance") || methods[i].getParameterTypes().length != 0) { continue; list.add(methods[i]); return list; |
Method[] | getGetters(Class clazz) get Getters List<Method> outM = new ArrayList<Method>(); for (Method m : clazz.getMethods()) { if (m.getParameterTypes().length == 0 && m.getName().startsWith("get") && m.getReturnType() != null) { outM.add(m); return outM.toArray(new Method[outM.size()]); |
Set | getGetters(Class extends Object> klass) get Getters Set<Method> getters = new HashSet<Method>(); for (Method m : Arrays.asList(klass.getDeclaredMethods())) { if (m.getName().startsWith("get") && m.getParameterTypes().length == 0 && !void.class.equals(m.getReturnType())) { getters.add(m); return getters; ... |
List | getGetters(Class> c) Finds the getters of a class. Method[] allMethods = c.getDeclaredMethods(); List<Method> getters = new LinkedList<>(); for (Method m : allMethods) { if (((m.getReturnType().equals(boolean.class) && m.getName().startsWith("is")) || m.getName().startsWith("get")) && m.getParameterTypes().length == 0) { getters.add(m); return getters; |
Map | getGetters(Class> clazz) get Getters Map<String, Method> map = new LinkedHashMap<String, Method>(); Class<?> searchType = clazz; while (searchType != null && searchType != Object.class) { Method[] methods = (searchType.isInterface()) ? new Method[0] : searchType.getDeclaredMethods(); for (Method method : methods) { String name = method.getName(); int modifiers = method.getModifiers(); if (modifiers - Modifier.PUBLIC == 0 && method.getParameterTypes().length == 0) { ... |