@Test public void testIsGetterWithRealIsPositive() throws Exception { assertThat("isGetter should have returned true for method named 'isSomething'", ReflectionHelper.isGetter(IsGetterTester.class.getMethod("isSomething")), is(true)); }
public static boolean isGetter(final Method method) { if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) { final String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { return !void.class.equals(method.getReturnType()); } else if (methodName.startsWith("is") && methodName.length() > 2) { return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()); } } return false; }
ReflectionHelper { public static boolean isGetter(final Method method) { if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) { final String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { return !void.class.equals(method.getReturnType()); } else if (methodName.startsWith("is") && methodName.length() > 2) { return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()); } } return false; } }
ReflectionHelper { public static boolean isGetter(final Method method) { if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) { final String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { return !void.class.equals(method.getReturnType()); } else if (methodName.startsWith("is") && methodName.length() > 2) { return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()); } } return false; } private  ReflectionHelper(); }
ReflectionHelper { public static boolean isGetter(final Method method) { if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) { final String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { return !void.class.equals(method.getReturnType()); } else if (methodName.startsWith("is") && methodName.length() > 2) { return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()); } } return false; } private  ReflectionHelper(); static Class<?> getDeclaringClass(final AccessibleObject ao); static String objectToString(final Object o); static String methodInstanceToString(final Object o, final Method m); static PrivilegedAction<Class<T>> classForNamePA(final String name); @SuppressWarnings("unchecked") static PrivilegedAction<Class<T>> classForNamePA(final String name, final ClassLoader cl); static PrivilegedAction<ClassLoader> getClassLoaderPA(final Class<?> clazz); static PrivilegedAction<Field[]> getDeclaredFieldsPA(final Class<?> clazz); static PrivilegedAction<Field[]> getAllFieldsPA(final Class<?> clazz); static PrivilegedAction<Collection<? extends Method>> getDeclaredMethodsPA(final Class<?> clazz); static PrivilegedExceptionAction<Class<T>> classForNameWithExceptionPEA(final String name); @SuppressWarnings("unchecked") static PrivilegedExceptionAction<Class<T>> classForNameWithExceptionPEA(final String name, final ClassLoader cl); static PrivilegedAction<ClassLoader> getContextClassLoaderPA(); static PrivilegedAction setContextClassLoaderPA(final ClassLoader classLoader); static PrivilegedAction setAccessibleMethodPA(final Method m); static List<Class<?>> getGenericTypeArgumentClasses(final Type type); static List<ClassTypePair> getTypeArgumentAndClass(final Type type); static boolean isPrimitive(final Type type); static Type[] getTypeArguments(final Type type); static Type getTypeArgument(final Type type, final int index); @SuppressWarnings("unchecked") static Class<T> erasure(final Type type); static boolean isSubClassOf(final Type subType, final Type superType); static boolean isArray(final Type type); static boolean isArrayOfType(final Type type, final Class<?> componentType); static Type getArrayComponentType(final Type type); static Class<?> getArrayForComponentType(final Class<?> c); @SuppressWarnings("unchecked") static PrivilegedAction<Method> getValueOfStringMethodPA(final Class<?> clazz); @SuppressWarnings("unchecked") static PrivilegedAction<Method> getFromStringStringMethodPA(final Class<?> clazz); static PrivilegedAction<Constructor> getStringConstructorPA(final Class<?> clazz); static PrivilegedAction<Constructor<?>[]> getDeclaredConstructorsPA(final Class<?> clazz); static PrivilegedAction<Constructor<?>> getDeclaredConstructorPA(final Class<?> clazz, final Class<?>... params); static Collection<Class<? extends Annotation>> getAnnotationTypes(final AnnotatedElement annotatedElement,
                                                                             final Class<? extends Annotation> metaAnnotation); static boolean isGetter(final Method method); static GenericType genericTypeFor(final Object instance); static boolean isSetter(final Method method); static String getPropertyName(final Method method); static Class<?> theMostSpecificTypeOf(final Set<Type> contractTypes); static Class[] getParameterizedClassArguments(final DeclaringClassInterfacePair p); static Type[] getParameterizedTypeArguments(final DeclaringClassInterfacePair p); static DeclaringClassInterfacePair getClass(final Class<?> concrete, final Class<?> iface); static ClassTypePair resolveGenericType(final Class concreteClass, final Class declaringClass,
                                                   final Class rawResolvedType, final Type genericResolvedType); static ClassTypePair resolveTypeVariable(final Class<?> c, final Class<?> dc, final TypeVariable tv); static PrivilegedAction<Method> findMethodOnClassPA(final Class<?> c, final Method m); static PrivilegedAction<Method[]> getMethodsPA(final Class<?> c); static Method findOverridingMethodOnClass(final Class<?> clazz, final Method method); static OsgiRegistry getOsgiRegistryInstance(); static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name); static Class<?> getRawClass(Type type); }
ReflectionHelper { public static boolean isGetter(final Method method) { if (method.getParameterTypes().length == 0 && Modifier.isPublic(method.getModifiers())) { final String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) { return !void.class.equals(method.getReturnType()); } else if (methodName.startsWith("is") && methodName.length() > 2) { return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType()); } } return false; } private  ReflectionHelper(); static Class<?> getDeclaringClass(final AccessibleObject ao); static String objectToString(final Object o); static String methodInstanceToString(final Object o, final Method m); static PrivilegedAction<Class<T>> classForNamePA(final String name); @SuppressWarnings("unchecked") static PrivilegedAction<Class<T>> classForNamePA(final String name, final ClassLoader cl); static PrivilegedAction<ClassLoader> getClassLoaderPA(final Class<?> clazz); static PrivilegedAction<Field[]> getDeclaredFieldsPA(final Class<?> clazz); static PrivilegedAction<Field[]> getAllFieldsPA(final Class<?> clazz); static PrivilegedAction<Collection<? extends Method>> getDeclaredMethodsPA(final Class<?> clazz); static PrivilegedExceptionAction<Class<T>> classForNameWithExceptionPEA(final String name); @SuppressWarnings("unchecked") static PrivilegedExceptionAction<Class<T>> classForNameWithExceptionPEA(final String name, final ClassLoader cl); static PrivilegedAction<ClassLoader> getContextClassLoaderPA(); static PrivilegedAction setContextClassLoaderPA(final ClassLoader classLoader); static PrivilegedAction setAccessibleMethodPA(final Method m); static List<Class<?>> getGenericTypeArgumentClasses(final Type type); static List<ClassTypePair> getTypeArgumentAndClass(final Type type); static boolean isPrimitive(final Type type); static Type[] getTypeArguments(final Type type); static Type getTypeArgument(final Type type, final int index); @SuppressWarnings("unchecked") static Class<T> erasure(final Type type); static boolean isSubClassOf(final Type subType, final Type superType); static boolean isArray(final Type type); static boolean isArrayOfType(final Type type, final Class<?> componentType); static Type getArrayComponentType(final Type type); static Class<?> getArrayForComponentType(final Class<?> c); @SuppressWarnings("unchecked") static PrivilegedAction<Method> getValueOfStringMethodPA(final Class<?> clazz); @SuppressWarnings("unchecked") static PrivilegedAction<Method> getFromStringStringMethodPA(final Class<?> clazz); static PrivilegedAction<Constructor> getStringConstructorPA(final Class<?> clazz); static PrivilegedAction<Constructor<?>[]> getDeclaredConstructorsPA(final Class<?> clazz); static PrivilegedAction<Constructor<?>> getDeclaredConstructorPA(final Class<?> clazz, final Class<?>... params); static Collection<Class<? extends Annotation>> getAnnotationTypes(final AnnotatedElement annotatedElement,
                                                                             final Class<? extends Annotation> metaAnnotation); static boolean isGetter(final Method method); static GenericType genericTypeFor(final Object instance); static boolean isSetter(final Method method); static String getPropertyName(final Method method); static Class<?> theMostSpecificTypeOf(final Set<Type> contractTypes); static Class[] getParameterizedClassArguments(final DeclaringClassInterfacePair p); static Type[] getParameterizedTypeArguments(final DeclaringClassInterfacePair p); static DeclaringClassInterfacePair getClass(final Class<?> concrete, final Class<?> iface); static ClassTypePair resolveGenericType(final Class concreteClass, final Class declaringClass,
                                                   final Class rawResolvedType, final Type genericResolvedType); static ClassTypePair resolveTypeVariable(final Class<?> c, final Class<?> dc, final TypeVariable tv); static PrivilegedAction<Method> findMethodOnClassPA(final Class<?> c, final Method m); static PrivilegedAction<Method[]> getMethodsPA(final Class<?> c); static Method findOverridingMethodOnClass(final Class<?> clazz, final Method method); static OsgiRegistry getOsgiRegistryInstance(); static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name); static Class<?> getRawClass(Type type);  }