clang 20.0.0git
|
An atomic change is used to create and group a set of source edits, e.g. More...
#include "clang/Tooling/Refactoring/AtomicChange.h"
Public Member Functions | |
AtomicChange (const SourceManager &SM, SourceLocation KeyPosition) | |
Creates an atomic change around KeyPosition with the key being a concatenation of the file name and the offset of KeyPosition . | |
AtomicChange (const SourceManager &SM, SourceLocation KeyPosition, llvm::Any Metadata) | |
AtomicChange (llvm::StringRef FilePath, llvm::StringRef Key) | |
Creates an atomic change for FilePath with a customized key. | |
AtomicChange (AtomicChange &&)=default | |
AtomicChange (const AtomicChange &)=default | |
AtomicChange & | operator= (AtomicChange &&)=default |
AtomicChange & | operator= (const AtomicChange &)=default |
bool | operator== (const AtomicChange &Other) const |
std::string | toYAMLString () |
Returns the atomic change as a YAML string. | |
const std::string & | getKey () const |
Returns the key of this change, which is a concatenation of the file name and offset of the key position. | |
const std::string & | getFilePath () const |
Returns the path of the file containing this atomic change. | |
void | setError (llvm::StringRef Error) |
If this change could not be created successfully, e.g. | |
bool | hasError () const |
Returns whether an error has been set on this list. | |
const std::string & | getError () const |
Returns the error message or an empty string if it does not exist. | |
llvm::Error | replace (const SourceManager &SM, const CharSourceRange &Range, llvm::StringRef ReplacementText) |
Adds a replacement that replaces the given Range with ReplacementText. | |
llvm::Error | replace (const SourceManager &SM, SourceLocation Loc, unsigned Length, llvm::StringRef Text) |
Adds a replacement that replaces range [Loc, Loc+Length) with Text . | |
llvm::Error | insert (const SourceManager &SM, SourceLocation Loc, llvm::StringRef Text, bool InsertAfter=true) |
Adds a replacement that inserts Text at Loc . | |
void | addHeader (llvm::StringRef Header) |
Adds a header into the file that contains the key position. | |
void | removeHeader (llvm::StringRef Header) |
Removes a header from the file that contains the key position. | |
const Replacements & | getReplacements () const |
Returns a const reference to existing replacements. | |
Replacements & | getReplacements () |
llvm::ArrayRef< std::string > | getInsertedHeaders () const |
llvm::ArrayRef< std::string > | getRemovedHeaders () const |
const llvm::Any & | getMetadata () const |
Static Public Member Functions | |
static AtomicChange | convertFromYAML (llvm::StringRef YAMLContent) |
Converts a YAML-encoded automic change to AtomicChange. | |
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.
Definition at line 37 of file AtomicChange.h.
clang::tooling::AtomicChange::AtomicChange | ( | const SourceManager & | SM, |
SourceLocation | KeyPosition | ||
) |
Creates an atomic change around KeyPosition
with the key being a concatenation of the file name and the offset of KeyPosition
.
KeyPosition
should be the location of the key syntactical element that is being changed, e.g. the call to a refactored method.
Definition at line 196 of file AtomicChange.cpp.
References clang::FullSourceLoc::getDecomposedLoc(), clang::FileEntryRef::getName(), clang::FullSourceLoc::getSpellingLoc(), and SM.
clang::tooling::AtomicChange::AtomicChange | ( | const SourceManager & | SM, |
SourceLocation | KeyPosition, | ||
llvm::Any | Metadata | ||
) |
Definition at line 207 of file AtomicChange.cpp.
|
inline |
Creates an atomic change for FilePath
with a customized key.
Definition at line 49 of file AtomicChange.h.
|
default |
|
default |
void clang::tooling::AtomicChange::addHeader | ( | llvm::StringRef | Header | ) |
Adds a header into the file that contains the key position.
Header can be in angle brackets or double quotation marks. By default (header is not quoted), header will be surrounded with double quotes.
Definition at line 292 of file AtomicChange.cpp.
|
static |
Converts a YAML-encoded automic change to AtomicChange.
Definition at line 242 of file AtomicChange.cpp.
References E.
|
inline |
Returns the error message or an empty string if it does not exist.
Definition at line 83 of file AtomicChange.h.
|
inline |
Returns the path of the file containing this atomic change.
Definition at line 71 of file AtomicChange.h.
|
inline |
Definition at line 121 of file AtomicChange.h.
|
inline |
Returns the key of this change, which is a concatenation of the file name and offset of the key position.
Definition at line 68 of file AtomicChange.h.
|
inline |
Definition at line 129 of file AtomicChange.h.
|
inline |
Definition at line 125 of file AtomicChange.h.
|
inline |
Definition at line 119 of file AtomicChange.h.
|
inline |
Returns a const reference to existing replacements.
Definition at line 117 of file AtomicChange.h.
Referenced by clang::tooling::RenamingASTConsumer::HandleTranslationUnit().
|
inline |
Returns whether an error has been set on this list.
Definition at line 80 of file AtomicChange.h.
llvm::Error clang::tooling::AtomicChange::insert | ( | const SourceManager & | SM, |
SourceLocation | Loc, | ||
llvm::StringRef | Text, | ||
bool | InsertAfter = true |
||
) |
Adds a replacement that inserts Text
at Loc
.
If this insertion conflicts with an existing insertion (at the same position), this will be inserted before/after the existing insertion depending on InsertAfter
. Users should use replace
with Length=0
instead if they do not want conflict resolving by default. If the conflicting replacement is not an insertion, an error is returned.
Definition at line 269 of file AtomicChange.cpp.
References clang::tooling::ReplacementError::get(), clang::tooling::ReplacementError::getExistingReplacement(), clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getOffset(), clang::if(), clang::tooling::insert_conflict, Loc, SM, and Text.
|
default |
|
default |
bool clang::tooling::AtomicChange::operator== | ( | const AtomicChange & | Other | ) | const |
Definition at line 223 of file AtomicChange.cpp.
References clang::Other.
void clang::tooling::AtomicChange::removeHeader | ( | llvm::StringRef | Header | ) |
Removes a header from the file that contains the key position.
Definition at line 296 of file AtomicChange.cpp.
llvm::Error clang::tooling::AtomicChange::replace | ( | const SourceManager & | SM, |
const CharSourceRange & | Range, | ||
llvm::StringRef | ReplacementText | ||
) |
Adds a replacement that replaces the given Range with ReplacementText.
Definition at line 258 of file AtomicChange.cpp.
References SM.
Referenced by clang::tooling::convertChangesToFileReplacements(), and clang::tooling::createRenameAtomicChanges().
llvm::Error clang::tooling::AtomicChange::replace | ( | const SourceManager & | SM, |
SourceLocation | Loc, | ||
unsigned | Length, | ||
llvm::StringRef | Text | ||
) |
Adds a replacement that replaces range [Loc, Loc+Length) with Text
.
Definition at line 264 of file AtomicChange.cpp.
|
inline |
If this change could not be created successfully, e.g.
because of conflicts among replacements, use this to set an error description. Thereby, places that cannot be fixed automatically can be gathered when applying changes.
Definition at line 77 of file AtomicChange.h.
std::string clang::tooling::AtomicChange::toYAMLString | ( | ) |
Returns the atomic change as a YAML string.
Definition at line 232 of file AtomicChange.cpp.