@@ -569,19 +569,33 @@ public int compare(File f1, File f2) {
569569 }
570570 };
571571
572+ class FileExtractors {
573+ FileExtractor defaultExtractor ;
574+ Map <String , FileExtractor > customExtractors = new LinkedHashMap <>();
575+
576+ FileExtractors (FileExtractor defaultExtractor ) {
577+ this .defaultExtractor = defaultExtractor ;
578+ }
579+
580+ public FileExtractor forFile (Path f ) {
581+ return customExtractors .getOrDefault (FileUtil .extension (f ), defaultExtractor );
582+ }
583+ }
584+
572585 /** Extract all supported candidate files that pass the filters. */
573586 private void extractSource () throws IOException {
574587 // default extractor
575588 FileExtractor defaultExtractor =
576589 new FileExtractor (mkExtractorConfig (), outputConfig , trapCache );
577590
591+ FileExtractors extractors = new FileExtractors (defaultExtractor );
592+
578593 // custom extractor for explicitly specified file types
579- Map <String , FileExtractor > customExtractors = new LinkedHashMap <>();
580594 for (Map .Entry <String , FileType > spec : fileTypes .entrySet ()) {
581595 String extension = spec .getKey ();
582596 String fileType = spec .getValue ().name ();
583597 ExtractorConfig extractorConfig = mkExtractorConfig ().withFileType (fileType );
584- customExtractors .put (extension , new FileExtractor (extractorConfig , outputConfig , trapCache ));
598+ extractors . customExtractors .put (extension , new FileExtractor (extractorConfig , outputConfig , trapCache ));
585599 }
586600
587601 Set <Path > filesToExtract = new LinkedHashSet <>();
@@ -610,15 +624,14 @@ private void extractSource() throws IOException {
610624
611625 // extract remaining files
612626 extractFiles (
613- filesToExtract , extractedFiles , defaultExtractor , customExtractors ,
627+ filesToExtract , extractedFiles , extractors ,
614628 f -> !(hasTypeScriptFiles && isFileDerivedFromTypeScriptFile (f , extractedFiles )));
615629 }
616630
617631 private void extractFiles (
618632 Set <Path > filesToExtract ,
619633 Set <Path > extractedFiles ,
620- FileExtractor defaultExtractor ,
621- Map <String , FileExtractor > customExtractors ,
634+ FileExtractors extractors ,
622635 Predicate <Path > shouldExtract ) {
623636
624637 for (Path f : filesToExtract ) {
@@ -628,12 +641,7 @@ private void extractFiles(
628641 continue ;
629642 }
630643 extractedFiles .add (f );
631- FileExtractor extractor = defaultExtractor ;
632- if (!fileTypes .isEmpty ()) {
633- String extension = FileUtil .extension (f );
634- if (customExtractors .containsKey (extension )) extractor = customExtractors .get (extension );
635- }
636- extract (extractor , f , null );
644+ extract (extractors .forFile (f ), f , null );
637645 }
638646 }
639647
0 commit comments