@@ -569,19 +569,33 @@ public int compare(File f1, File f2) {
569
569
}
570
570
};
571
571
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
+
572
585
/** Extract all supported candidate files that pass the filters. */
573
586
private void extractSource () throws IOException {
574
587
// default extractor
575
588
FileExtractor defaultExtractor =
576
589
new FileExtractor (mkExtractorConfig (), outputConfig , trapCache );
577
590
591
+ FileExtractors extractors = new FileExtractors (defaultExtractor );
592
+
578
593
// custom extractor for explicitly specified file types
579
- Map <String , FileExtractor > customExtractors = new LinkedHashMap <>();
580
594
for (Map .Entry <String , FileType > spec : fileTypes .entrySet ()) {
581
595
String extension = spec .getKey ();
582
596
String fileType = spec .getValue ().name ();
583
597
ExtractorConfig extractorConfig = mkExtractorConfig ().withFileType (fileType );
584
- customExtractors .put (extension , new FileExtractor (extractorConfig , outputConfig , trapCache ));
598
+ extractors . customExtractors .put (extension , new FileExtractor (extractorConfig , outputConfig , trapCache ));
585
599
}
586
600
587
601
Set <Path > filesToExtract = new LinkedHashSet <>();
@@ -610,15 +624,14 @@ private void extractSource() throws IOException {
610
624
611
625
// extract remaining files
612
626
extractFiles (
613
- filesToExtract , extractedFiles , defaultExtractor , customExtractors ,
627
+ filesToExtract , extractedFiles , extractors ,
614
628
f -> !(hasTypeScriptFiles && isFileDerivedFromTypeScriptFile (f , extractedFiles )));
615
629
}
616
630
617
631
private void extractFiles (
618
632
Set <Path > filesToExtract ,
619
633
Set <Path > extractedFiles ,
620
- FileExtractor defaultExtractor ,
621
- Map <String , FileExtractor > customExtractors ,
634
+ FileExtractors extractors ,
622
635
Predicate <Path > shouldExtract ) {
623
636
624
637
for (Path f : filesToExtract ) {
@@ -628,12 +641,7 @@ private void extractFiles(
628
641
continue ;
629
642
}
630
643
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 );
637
645
}
638
646
}
639
647
0 commit comments