|
clang
5.0.0
|
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. More... | |
| AtomicChange (llvm::StringRef FilePath, llvm::StringRef Key) | |
Creates an atomic change for FilePath with a customized key. More... | |
| std::string | toYAMLString () |
| Returns the atomic change as a YAML string. More... | |
| 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. More... | |
| const std::string & | getFilePath () const |
| Returns the path of the file containing this atomic change. More... | |
| void | setError (llvm::StringRef Error) |
| If this change could not be created successfully, e.g. More... | |
| bool | hasError () const |
| Returns whether an error has been set on this list. More... | |
| const std::string & | getError () const |
| Returns the error message or an empty string if it does not exist. More... | |
| llvm::Error | replace (const SourceManager &SM, const CharSourceRange &Range, llvm::StringRef ReplacementText) |
| Adds a replacement that replaces the given Range with ReplacementText. More... | |
| llvm::Error | replace (const SourceManager &SM, SourceLocation Loc, unsigned Length, llvm::StringRef Text) |
Adds a replacement that replaces range [Loc, Loc+Length) with Text. More... | |
| llvm::Error | insert (const SourceManager &SM, SourceLocation Loc, llvm::StringRef Text, bool InsertAfter=true) |
Adds a replacement that inserts Text at Loc. More... | |
| void | addHeader (llvm::StringRef Header) |
| Adds a header into the file that contains the key position. More... | |
| void | removeHeader (llvm::StringRef Header) |
| Removes a header from the file that contains the key position. More... | |
| const Replacements & | getReplacements () const |
| Returns a const reference to existing replacements. More... | |
| llvm::ArrayRef< std::string > | getInsertedHeaders () const |
| llvm::ArrayRef< std::string > | getRemovedHeaders () const |
Static Public Member Functions | |
| static AtomicChange | convertFromYAML (llvm::StringRef YAMLContent) |
| Converts a YAML-encoded automic change to AtomicChange. More... | |
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 36 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 87 of file AtomicChange.cpp.
References clang::FullSourceLoc::getDecomposedLoc(), clang::SourceManager::getFileEntryForID(), clang::FileEntry::getName(), and clang::FullSourceLoc::getSpellingLoc().
|
inline |
Creates an atomic change for FilePath with a customized key.
Definition at line 45 of file AtomicChange.h.
| 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 168 of file AtomicChange.cpp.
|
static |
Converts a YAML-encoded automic change to AtomicChange.
Definition at line 118 of file AtomicChange.cpp.
References clang::tooling::Replacements::add(), E, clang::Error, and Input.
|
inline |
Returns the error message or an empty string if it does not exist.
Definition at line 71 of file AtomicChange.h.
|
inline |
Returns the path of the file containing this atomic change.
Definition at line 59 of file AtomicChange.h.
|
inline |
Definition at line 107 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 56 of file AtomicChange.h.
|
inline |
Definition at line 111 of file AtomicChange.h.
|
inline |
Returns a const reference to existing replacements.
Definition at line 105 of file AtomicChange.h.
Referenced by clang::tooling::USRSymbolRenamer::HandleTranslationUnit().
|
inline |
Returns whether an error has been set on this list.
Definition at line 68 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 145 of file AtomicChange.cpp.
References clang::tooling::Replacements::add(), clang::Error, clang::tooling::ReplacementError::get(), clang::tooling::ReplacementError::getExistingReplacement(), clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getOffset(), clang::tooling::Replacements::getShiftedCodePosition(), clang::tooling::insert_conflict, clang::tooling::Replacements::merge(), and Text.
| void clang::tooling::AtomicChange::removeHeader | ( | llvm::StringRef | Header | ) |
Removes a header from the file that contains the key position.
Definition at line 172 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 134 of file AtomicChange.cpp.
References clang::tooling::Replacements::add(), and Replacement.
Referenced by 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 140 of file AtomicChange.cpp.
References clang::tooling::Replacements::add(), and Replacement.
|
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 65 of file AtomicChange.h.
| std::string clang::tooling::AtomicChange::toYAMLString | ( | ) |
Returns the atomic change as a YAML string.
Definition at line 108 of file AtomicChange.cpp.
1.8.6