package android.platform.test.rule /** Checks if the class, or any of its superclasses, have [annotation]. */ fun Class?.hasAnnotation(annotation: Class): Boolean = getLowestAncestorClassAnnotation(this, annotation) != null /** * Return the lowest ancestor annotation matching [annotationClass]. * * This assumes that a class is an ancestor of itself. */ fun getLowestAncestorClassAnnotation( testClass: Class?, annotationClass: Class, ): V? { return if (testClass == null) { null } else { testClass.getAnnotation(annotationClass) ?: getLowestAncestorClassAnnotation(testClass.superclass, annotationClass) } }