std::string RefactoringTool::writeReplacements(clang::Rewriter &rewriter) { std::ostringstream oss; for ( auto i = rewriter.buffer_begin(), e = rewriter.buffer_end(); i != e; ++i ) { llvm::raw_os_ostream stream(oss); i->second.write(stream); stream.flush(); } return oss.str(); }
bool writeFiles(const clang::Rewriter &Rewrites) { for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(), BufferE = Rewrites.buffer_end(); BufferI != BufferE; ++BufferI) { const char *FileName = Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName(); std::error_code EC; llvm::raw_fd_ostream FileStream(FileName, EC, llvm::sys::fs::F_Text); if (EC) { errs() << "Warning: Could not write to " << EC.message() << "\n"; continue; } BufferI->second.write(FileStream); } return true; }
bool writeFiles(const clang::Rewriter &Rewrites) { for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(), BufferE = Rewrites.buffer_end(); BufferI != BufferE; ++BufferI) { const char *FileName = Rewrites.getSourceMgr().getFileEntryForID(BufferI->first)->getName(); std::string ErrorInfo; llvm::raw_fd_ostream FileStream(FileName, ErrorInfo); if (!ErrorInfo.empty()) { errs() << "Warning: Could not write to " << FileName << "\n"; continue; } BufferI->second.write(FileStream); } return true; }