@ SuppressWarnings ( "unchecked" ) private < T > void addClass ( Set < Class < ? extends T > > classes , String includeRegExp , String className , Class < T > ofType , Class < ? extends Annotation > annotationClass ) { if ( className . matches ( includeRegExp ) ) { try { Class < ? > matchingClass = Class . forName ( className ) ; matchingClass . asSubclass ( ofType ) ; classes . add ( ( Class < T > ) matchingClass ) ; } catch ( ClassNotFoundException cnfe ) { throw new IllegalStateException ( "Scannotation found a class that does not exist " + className + " !" , cnfe ) ; } catch ( ClassCastException cce ) { throw new IllegalStateException ( "Class " + className + " is annoted with @" + annotationClass + " but does not extend or implement " + ofType ) ; } } }
Created and adds the event to the eventsFound set if its package matches the includeRegExp .