List of utility methods to do Reflection Method Getter Get
String | getGetterFieldName(Method method) Extract field name from the getter method String methodName = method.getName(); if (methodName.startsWith("get")) { return getFieldName(methodName.substring(3)); } else if (methodName.startsWith("is")) { return getFieldName(methodName.substring(2)); throw new IllegalArgumentException("Invalid getter method" + method.getName()); |
List | getGetterFields(final Class> clazz) get Getter Fields final List<Field> list = new ArrayList<Field>(); final Field[] fields = clazz.getDeclaredFields(); for (final Field field : fields) { if (fieldHasGetter(field, clazz)) { list.add(field); return list; ... |
Method | getGetterFor(Field field) get Getter For String name = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); try { return field.getDeclaringClass().getMethod("get" + name); } catch (NoSuchMethodException e) { return null; |
Method | getGetterFor(Object obj, Field field, Class objClass) get Getter For for (Method m : objClass.getDeclaredMethods()) { if (m.getName().equals(getGetterMethodName(field.getName(), false)) || m.getName().equals(getGetterMethodName(field.getName(), true))) { if (m.getGenericParameterTypes().length == 0) { return m; Class c = objClass.getSuperclass(); if (c != null) { return getGetterFor(obj, field, c); return null; |
List | getGetterFromCache(Class clazz) get Getter From Cache List<Method> methods = getterCache.get(clazz); if (methods == null) { methods = new ArrayList<>(); for (Method method : clazz.getDeclaredMethods()) { String name = method.getName(); if (method.getParameterTypes().length == 0) { if (name.startsWith("get")) { methods.add(method); ... |
Method | getGetterFromProperty(Class clazz, String property) get Getter From Property char[] chars = property.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return clazz.getMethod("get" + new String(chars)); |
Method | getGetterMethod(Class containingClass, String propertyName) get Getter Method String getterName = PROPERTY_ACCESSOR_PREFIX_GET + (propertyName.isEmpty() ? "" : propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); try { return containingClass.getMethod(getterName); } catch (NoSuchMethodException e) { String isserName = PROPERTY_ACCESSOR_PREFIX_IS + (propertyName.isEmpty() ? "" : propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); ... |
Method | getGetterMethod(Class type, String property) get Getter Method String getName = getEtterMethodName(property, "get"); try { return type.getMethod(getName); } catch (NoSuchMethodException e) { try { getName = getEtterMethodName(property, "is"); return type.getMethod(getName); } catch (Exception e1) { ... |
Method | getGetterMethod(Class> beanClass, String property) Returns getter method for property in specified beanClass
try { return beanClass.getMethod(GET + getMethodSuffix(property)); } catch (NoSuchMethodException ex1) { try { return beanClass.getMethod(IS + getMethodSuffix(property)); } catch (NoSuchMethodException ex2) { return null; |
Method | getGetterMethod(Class> c, String field) get Getter Method try { return c.getMethod(getterMethod(field)); } catch (NoSuchMethodException e) { throw new RuntimeException(e); |