@Test public void shouldGetAnnotatedSuperClass() { Class<?> cls = ModelHelper.getAnnotatedResourceClass(ChildOne.class, Grpc.class); assertThat(cls, equalTo(Parent.class)); }
public static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation) { Class<?> foundInterface = null; Class<?> cls = resourceClass; do { if (cls.getDeclaredAnnotation(annotation) != null) { return cls; } if (foundInterface == null) { for (final Class<?> i : cls.getInterfaces()) { if (i.getDeclaredAnnotation(annotation) != null) { foundInterface = i; break; } } } cls = cls.getSuperclass(); } while (cls != null); if (foundInterface != null) { return foundInterface; } return resourceClass; }
ModelHelper { public static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation) { Class<?> foundInterface = null; Class<?> cls = resourceClass; do { if (cls.getDeclaredAnnotation(annotation) != null) { return cls; } if (foundInterface == null) { for (final Class<?> i : cls.getInterfaces()) { if (i.getDeclaredAnnotation(annotation) != null) { foundInterface = i; break; } } } cls = cls.getSuperclass(); } while (cls != null); if (foundInterface != null) { return foundInterface; } return resourceClass; } }
ModelHelper { public static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation) { Class<?> foundInterface = null; Class<?> cls = resourceClass; do { if (cls.getDeclaredAnnotation(annotation) != null) { return cls; } if (foundInterface == null) { for (final Class<?> i : cls.getInterfaces()) { if (i.getDeclaredAnnotation(annotation) != null) { foundInterface = i; break; } } } cls = cls.getSuperclass(); } while (cls != null); if (foundInterface != null) { return foundInterface; } return resourceClass; } private  ModelHelper(); }
ModelHelper { public static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation) { Class<?> foundInterface = null; Class<?> cls = resourceClass; do { if (cls.getDeclaredAnnotation(annotation) != null) { return cls; } if (foundInterface == null) { for (final Class<?> i : cls.getInterfaces()) { if (i.getDeclaredAnnotation(annotation) != null) { foundInterface = i; break; } } } cls = cls.getSuperclass(); } while (cls != null); if (foundInterface != null) { return foundInterface; } return resourceClass; } private  ModelHelper(); static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation); static PrivilegedAction<Collection<? extends Method>> getDeclaredMethodsPA(final Class<?> clazz); static PrivilegedAction<Method> findMethodOnClassPA(final Class<?> cls, final Method m); static Type getArrayComponentType(final Type type); static Class<?> getArrayForComponentType(final Class<?> c); static MarshallerSupplier getMarshallerSupplier(GrpcMarshaller annotation); static Class<?> getGenericType(Type type); }
ModelHelper { public static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation) { Class<?> foundInterface = null; Class<?> cls = resourceClass; do { if (cls.getDeclaredAnnotation(annotation) != null) { return cls; } if (foundInterface == null) { for (final Class<?> i : cls.getInterfaces()) { if (i.getDeclaredAnnotation(annotation) != null) { foundInterface = i; break; } } } cls = cls.getSuperclass(); } while (cls != null); if (foundInterface != null) { return foundInterface; } return resourceClass; } private  ModelHelper(); static Class<?> getAnnotatedResourceClass(Class<?> resourceClass, Class<? extends Annotation> annotation); static PrivilegedAction<Collection<? extends Method>> getDeclaredMethodsPA(final Class<?> clazz); static PrivilegedAction<Method> findMethodOnClassPA(final Class<?> cls, final Method m); static Type getArrayComponentType(final Type type); static Class<?> getArrayForComponentType(final Class<?> c); static MarshallerSupplier getMarshallerSupplier(GrpcMarshaller annotation); static Class<?> getGenericType(Type type);  }