private Class < ? > nextDecoratedClassInHierarchy ( Class < ? > previousTemplateClass , Class < ? > candidate ) { if ( candidate == previousTemplateClass ) { // terminate the recursion return null ; } else if ( candidate == Object . class ) { // this should never happen - we should terminate recursion first throw new IllegalStateException ( "Did not find previous extension" ) ; } else { boolean isDecorated = candidate . isAnnotationPresent ( Decorated . class ) ; if ( isDecorated ) return candidate ; else return nextDecoratedClassInHierarchy ( previousTemplateClass , candidate . getSuperclass ( ) ) ; } }
recursively find the next superclass with an