@ Requires ( { "element != null" , "clazz != null" , "kinds != null" } ) @ SuppressWarnings ( "unchecked" ) public static < T extends ElementModel > T findEnclosingElement ( ElementModel element , Class < T > clazz , ElementKind ... kinds ) { List < ElementKind > list = Arrays . asList ( kinds ) ; for ( ; ; ) { element = element . getEnclosingElement ( ) ; if ( element == null ) { return null ; } if ( list . contains ( element . getKind ( ) ) && clazz . isAssignableFrom ( element . getClass ( ) ) ) { return ( T ) element ; } } }
Returns the closest enclosing element of the specified kind .