@Test public void shouldRecognizeFieldNamesFromGettersSetters() { assertEquals("boolField", MemberUtil.getFieldNameFromGetterSetterName("isBoolField")); assertEquals("something", MemberUtil.getFieldNameFromGetterSetterName("getSomething")); assertEquals("dateOfBirth", MemberUtil.getFieldNameFromGetterSetterName("getDateOfBirth")); assertEquals("oneTwoThree", MemberUtil.getFieldNameFromGetterSetterName("isOneTwoThree")); }
public static String getFieldNameFromGetterSetterName(String getterSetterName) { if (StringUtils.isBlank(getterSetterName)) { throw new IllegalArgumentException("Provided getter or setter name cannot be null or empty"); } else if (getterSetterName.startsWith(SETTER_PREFIX) || getterSetterName.startsWith(GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(GET_OR_SET_END_INDEX)); } else if (getterSetterName.startsWith(BOOLEAN_GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(IS_END_INDEX)); } else { throw new IllegalArgumentException(getterSetterName + " does not start with get/set/is"); } }
MemberUtil { public static String getFieldNameFromGetterSetterName(String getterSetterName) { if (StringUtils.isBlank(getterSetterName)) { throw new IllegalArgumentException("Provided getter or setter name cannot be null or empty"); } else if (getterSetterName.startsWith(SETTER_PREFIX) || getterSetterName.startsWith(GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(GET_OR_SET_END_INDEX)); } else if (getterSetterName.startsWith(BOOLEAN_GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(IS_END_INDEX)); } else { throw new IllegalArgumentException(getterSetterName + " does not start with get/set/is"); } } }
MemberUtil { public static String getFieldNameFromGetterSetterName(String getterSetterName) { if (StringUtils.isBlank(getterSetterName)) { throw new IllegalArgumentException("Provided getter or setter name cannot be null or empty"); } else if (getterSetterName.startsWith(SETTER_PREFIX) || getterSetterName.startsWith(GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(GET_OR_SET_END_INDEX)); } else if (getterSetterName.startsWith(BOOLEAN_GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(IS_END_INDEX)); } else { throw new IllegalArgumentException(getterSetterName + " does not start with get/set/is"); } } private  MemberUtil(); }
MemberUtil { public static String getFieldNameFromGetterSetterName(String getterSetterName) { if (StringUtils.isBlank(getterSetterName)) { throw new IllegalArgumentException("Provided getter or setter name cannot be null or empty"); } else if (getterSetterName.startsWith(SETTER_PREFIX) || getterSetterName.startsWith(GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(GET_OR_SET_END_INDEX)); } else if (getterSetterName.startsWith(BOOLEAN_GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(IS_END_INDEX)); } else { throw new IllegalArgumentException(getterSetterName + " does not start with get/set/is"); } } private  MemberUtil(); static List<Member> getMembers(Class<?> clazz, Predicate memberPredicate); static String getFieldName(AnnotatedElement object); static String getFieldName(Member object); static String getDefaultEnumName(String entityClassName, String fieldName); static Class<?> getCorrectType(AnnotatedElement object); static Class<?> getCorrectType(Member object); static Class<?> getGenericType(AnnotatedElement object); static Class<?> getGenericType(AnnotatedElement object, int typeNumber); static Class<?> getGenericType(Member object, int typeNumber); static String getGetterName(String fieldName, CtClass declaring); static String getSetterName(String fieldName); static boolean isGetter(Member member); static boolean isSetter(Member member); static String getFieldNameFromGetterSetterName(String getterSetterName); static Class<?> getDeclaringClass(AccessibleObject ac); static List<AccessibleObject> getFieldAndAccessorsForElement(AccessibleObject ao); }
MemberUtil { public static String getFieldNameFromGetterSetterName(String getterSetterName) { if (StringUtils.isBlank(getterSetterName)) { throw new IllegalArgumentException("Provided getter or setter name cannot be null or empty"); } else if (getterSetterName.startsWith(SETTER_PREFIX) || getterSetterName.startsWith(GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(GET_OR_SET_END_INDEX)); } else if (getterSetterName.startsWith(BOOLEAN_GETTER_PREFIX)) { return Introspector.decapitalize(getterSetterName.substring(IS_END_INDEX)); } else { throw new IllegalArgumentException(getterSetterName + " does not start with get/set/is"); } } private  MemberUtil(); static List<Member> getMembers(Class<?> clazz, Predicate memberPredicate); static String getFieldName(AnnotatedElement object); static String getFieldName(Member object); static String getDefaultEnumName(String entityClassName, String fieldName); static Class<?> getCorrectType(AnnotatedElement object); static Class<?> getCorrectType(Member object); static Class<?> getGenericType(AnnotatedElement object); static Class<?> getGenericType(AnnotatedElement object, int typeNumber); static Class<?> getGenericType(Member object, int typeNumber); static String getGetterName(String fieldName, CtClass declaring); static String getSetterName(String fieldName); static boolean isGetter(Member member); static boolean isSetter(Member member); static String getFieldNameFromGetterSetterName(String getterSetterName); static Class<?> getDeclaringClass(AccessibleObject ac); static List<AccessibleObject> getFieldAndAccessorsForElement(AccessibleObject ao); static final String GETTER_PREFIX; static final String BOOLEAN_GETTER_PREFIX; static final String SETTER_PREFIX; static final int GET_OR_SET_END_INDEX; static final int IS_END_INDEX; }