public static void applySuggestedFixesToFiles ( Iterable < SuggestedFix > fixes ) throws IOException { Set < String > filenames = new HashSet <> ( ) ; for ( SuggestedFix fix : fixes ) { filenames . addAll ( fix . getReplacements ( ) . keySet ( ) ) ; } Map < String , String > filenameToCodeMap = new HashMap <> ( ) ; for ( String filename : filenames ) { filenameToCodeMap . put ( filename , Files . asCharSource ( new File ( filename ) , UTF_8 ) . read ( ) ) ; } Map < String , String > newCode = applySuggestedFixesToCode ( fixes , filenameToCodeMap ) ; for ( Map . Entry < String , String > entry : newCode . entrySet ( ) ) { Files . asCharSink ( new File ( entry . getKey ( ) ) , UTF_8 ) . write ( entry . getValue ( ) ) ; } }
Applies the provided set of suggested fixes to the files listed in the suggested fixes . The fixes can be provided in any order but they may not have any overlapping modifications for the same file .