/** * 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. */ public static void applySuggestedFixesToFiles(Iterable<SuggestedFix> fixes) throws IOException { Set<String> filenames = new HashSet<String>(); for (SuggestedFix fix : fixes) { filenames.addAll(fix.getReplacements().keySet()); } Map<String, String> filenameToCodeMap = new HashMap<String, String>(); for (String filename : filenames) { filenameToCodeMap.put(filename, Files.toString(new File(filename), UTF_8)); } Map<String, String> newCode = applySuggestedFixesToCode(fixes, filenameToCodeMap); for (Map.Entry<String, String> entry : newCode.entrySet()) { Files.write(entry.getValue(), new File(entry.getKey()), UTF_8); } }