use of com.google.errorprone.apply.FileDestination in project error-prone by google.
the class RefactoringCollection method refactor.
static RefactoringCollection refactor(PatchingOptions patchingOptions) {
Path rootPath = buildRootPath();
FileDestination fileDestination;
Function<URI, RefactoringResult> postProcess;
if (patchingOptions.inPlace()) {
fileDestination = new FsFileDestination(rootPath);
postProcess = uri -> RefactoringResult.create(String.format("Refactoring changes were successfully applied to %s," + " please check the refactored code and recompile.", uri), RefactoringResultType.CHANGED);
} else {
Path baseDir = rootPath.resolve(patchingOptions.baseDirectory());
Path patchFilePath = baseDir.resolve("error-prone.patch");
PatchFileDestination patchFileDestination = new PatchFileDestination(baseDir, rootPath);
postProcess = new Function<URI, RefactoringResult>() {
private final AtomicBoolean first = new AtomicBoolean(true);
@Override
public RefactoringResult apply(URI uri) {
try {
writePatchFile(first, uri, patchFileDestination, patchFilePath);
return RefactoringResult.create("Changes were written to " + patchFilePath + ". Please inspect the file and apply with: " + "patch -p0 -u -i error-prone.patch", RefactoringResultType.CHANGED);
} catch (IOException e) {
throw new RuntimeException("Failed to emit patch file!", e);
}
}
};
fileDestination = patchFileDestination;
}
ImportOrganizer importOrganizer = patchingOptions.importOrganizer();
return new RefactoringCollection(rootPath, fileDestination, postProcess, importOrganizer);
}
Aggregations