private List < ScannerPlugin < ? , ? > > getScannerPluginsForType ( final Class < ? > type ) { List < ScannerPlugin < ? , ? > > plugins = scannerPluginsPerType . get ( type ) ; if ( plugins == null ) { // The list of all scanner plugins which accept the given type final List < ScannerPlugin < ? , ? > > candidates = new LinkedList <> ( ) ; // The map of scanner plugins which produce a descriptor type final Map < Class < ? extends Descriptor > , Set < ScannerPlugin < ? , ? > > > pluginsByDescriptor = new HashMap <> ( ) ; for ( ScannerPlugin < ? , ? > scannerPlugin : scannerPlugins . values ( ) ) { Class < ? > scannerPluginType = scannerPlugin . getType ( ) ; if ( scannerPluginType . isAssignableFrom ( type ) ) { Class < ? extends Descriptor > descriptorType = scannerPlugin . getDescriptorType ( ) ; Set < ScannerPlugin < ? , ? > > pluginsForDescriptorType = pluginsByDescriptor . get ( descriptorType ) ; if ( pluginsForDescriptorType == null ) { pluginsForDescriptorType = new HashSet <> ( ) ; pluginsByDescriptor . put ( descriptorType , pluginsForDescriptorType ) ; } pluginsForDescriptorType . add ( scannerPlugin ) ; candidates . add ( scannerPlugin ) ; } } // Order plugins by the values of their optional @Requires // annotation plugins = DependencyResolver . newInstance ( candidates , new DependencyProvider < ScannerPlugin < ? , ? > > ( ) { @ Override public Set < ScannerPlugin < ? , ? > > getDependencies ( ScannerPlugin < ? , ? > dependent ) { Set < ScannerPlugin < ? , ? > > dependencies = new HashSet <> ( ) ; Requires annotation = dependent . getClass ( ) . getAnnotation ( Requires . class ) ; if ( annotation != null ) { for ( Class < ? extends Descriptor > descriptorType : annotation . value ( ) ) { Set < ScannerPlugin < ? , ? > > pluginsByDescriptorType = pluginsByDescriptor . get ( descriptorType ) ; if ( pluginsByDescriptorType != null ) { for ( ScannerPlugin < ? , ? > scannerPlugin : pluginsByDescriptorType ) { if ( ! scannerPlugin . equals ( dependent ) ) { dependencies . add ( scannerPlugin ) ; } } } } } return dependencies ; } } ) . resolve ( ) ; scannerPluginsPerType . put ( type , plugins ) ; } return plugins ; }
Determine the list of scanner plugins that handle the given type .