1 package android.platform.test.rule 2 3 /** Checks if the class, or any of its superclasses, have [annotation]. */ hasAnnotationnull4fun <T> Class<T>?.hasAnnotation(annotation: Class<out Annotation>): Boolean = 5 getLowestAncestorClassAnnotation(this, annotation) != null 6 7 /** 8 * Return the lowest ancestor annotation matching [annotationClass]. 9 * 10 * This assumes that a class is an ancestor of itself. 11 */ 12 fun <T, V : Annotation> getLowestAncestorClassAnnotation( 13 testClass: Class<T>?, 14 annotationClass: Class<V>, 15 ): V? { 16 return if (testClass == null) { 17 null 18 } else { 19 testClass.getAnnotation(annotationClass) 20 ?: getLowestAncestorClassAnnotation(testClass.superclass, annotationClass) 21 } 22 } 23