@Test public void shouldRecognizeSetters() throws NoSuchMethodException { for (Method method : legitimateSetters()) { assertTrue("Method " + method.getName() + " was not recognized as a setter", MemberUtil.isSetter(method)); } for (Member[] memberColl : Arrays.asList(legitimateGetters(), fakeGetters(), fakeSetters(), fields())) { for (Member member : memberColl) { assertFalse("Member " + member.getName() + " was incorrectly recognized as a setter", MemberUtil.isSetter(member)); } } }
public static boolean isSetter(Member member) { if (member instanceof Method && !Modifier.isStatic(member.getModifiers())) { Method method = (Method) member; return method.getName().startsWith(SETTER_PREFIX) && method.getReturnType().equals(Void.TYPE) && ArrayUtils.getLength(method.getParameterTypes()) == 1; } else { return false; } }
MemberUtil { public static boolean isSetter(Member member) { if (member instanceof Method && !Modifier.isStatic(member.getModifiers())) { Method method = (Method) member; return method.getName().startsWith(SETTER_PREFIX) && method.getReturnType().equals(Void.TYPE) && ArrayUtils.getLength(method.getParameterTypes()) == 1; } else { return false; } } }
MemberUtil { public static boolean isSetter(Member member) { if (member instanceof Method && !Modifier.isStatic(member.getModifiers())) { Method method = (Method) member; return method.getName().startsWith(SETTER_PREFIX) && method.getReturnType().equals(Void.TYPE) && ArrayUtils.getLength(method.getParameterTypes()) == 1; } else { return false; } } private  MemberUtil(); }
MemberUtil { public static boolean isSetter(Member member) { if (member instanceof Method && !Modifier.isStatic(member.getModifiers())) { Method method = (Method) member; return method.getName().startsWith(SETTER_PREFIX) && method.getReturnType().equals(Void.TYPE) && ArrayUtils.getLength(method.getParameterTypes()) == 1; } else { return false; } } 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 boolean isSetter(Member member) { if (member instanceof Method && !Modifier.isStatic(member.getModifiers())) { Method method = (Method) member; return method.getName().startsWith(SETTER_PREFIX) && method.getReturnType().equals(Void.TYPE) && ArrayUtils.getLength(method.getParameterTypes()) == 1; } else { return false; } } 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; }