//===--- AtomicChange.h - AtomicChange class --------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines AtomicChange which is used to create a set of source // changes, e.g. replacements and header insertions. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLING_REFACTORING_ATOMICCHANGE_H #define LLVM_CLANG_TOOLING_REFACTORING_ATOMICCHANGE_H #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/Any.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" namespace clang { namespace tooling { /// An atomic change is used to create and group a set of source edits, /// e.g. replacements or header insertions. Edits in an AtomicChange should be /// related, e.g. replacements for the same type reference and the corresponding /// header insertion/deletion. /// /// An AtomicChange is uniquely identified by a key and will either be fully /// applied or not applied at all. /// /// Calling setError on an AtomicChange stores the error message and marks it as /// bad, i.e. none of its source edits will be applied. class AtomicChange { … }; AtomicChanges; // Defines specs for applying changes. struct ApplyChangesSpec { … }; /// Applies all AtomicChanges in \p Changes to the \p Code. /// /// This completely ignores the file path in each change and replaces them with /// \p FilePath, i.e. callers are responsible for ensuring all changes are for /// the same file. /// /// \returns The changed code if all changes are applied successfully; /// otherwise, an llvm::Error carrying llvm::StringError is returned (the Error /// message can be converted to string with `llvm::toString()` and the /// error_code should be ignored). llvm::Expected<std::string> applyAtomicChanges(llvm::StringRef FilePath, llvm::StringRef Code, llvm::ArrayRef<AtomicChange> Changes, const ApplyChangesSpec &Spec); } // end namespace tooling } // end namespace clang #endif // LLVM_CLANG_TOOLING_REFACTORING_ATOMICCHANGE_H