Annotations - find all annotated parents

This commit is contained in:
Emmanuel BENOîT 2015-09-14 08:43:29 +02:00
parent 5b3d927aae
commit 604967af9c
2 changed files with 38 additions and 0 deletions
src/main/java/info/ebenoit/ebul/reflection

View file

@ -197,4 +197,26 @@ public final class Annotations
return found;
}
public static < T > ArrayList< Class< ? super T > > findParentsWith( final Class< T > klass ,
final Class< ? extends Annotation > annotation )
{
ArrayList< Class< ? super T > > output = new ArrayList< >( );
findParentsWith( output , klass , annotation );
return output;
}
public static < T > void findParentsWith( ArrayList< Class< ? super T > > output , Class< T > klass ,
Class< ? extends Annotation > annotation )
{
Class< ? super T > current = klass;
while ( current != null ) {
if ( current.getDeclaredAnnotation( annotation ) != null ) {
output.add( current );
}
current = current.getSuperclass( );
}
}
}