class AtomicChange

Declaration

class AtomicChange { /* full declaration omitted */ };

Description

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.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:37

Member Variables

private std::string Key
private std::string FilePath
private std::string Error
private std::vector<std::string> InsertedHeaders
private std::vector<std::string> RemovedHeaders
private tooling::Replacements Replaces
private llvm::Any Metadata

Method Overview

  • public AtomicChange(const clang::SourceManager & SM, clang::SourceLocation KeyPosition, llvm::Any Metadata)
  • private AtomicChange(std::string Key, std::string FilePath, std::string Error, std::vector<std::string> InsertedHeaders, std::vector<std::string> RemovedHeaders, clang::tooling::Replacements Replaces)
  • private AtomicChange()
  • public AtomicChange(const clang::tooling::AtomicChange &)
  • public AtomicChange(const clang::SourceManager & SM, clang::SourceLocation KeyPosition)
  • public AtomicChange(llvm::StringRef FilePath, llvm::StringRef Key)
  • public AtomicChange(clang::tooling::AtomicChange &&)
  • public void addHeader(llvm::StringRef Header)
  • public static clang::tooling::AtomicChange convertFromYAML(llvm::StringRef YAMLContent)
  • public const std::string & getError() const
  • public const std::string & getFilePath() const
  • public llvm::ArrayRef<std::string> getInsertedHeaders() const
  • public const std::string & getKey() const
  • public const llvm::Any & getMetadata() const
  • public llvm::ArrayRef<std::string> getRemovedHeaders() const
  • public const clang::tooling::Replacements & getReplacements() const
  • public clang::tooling::Replacements & getReplacements()
  • public bool hasError() const
  • public llvm::Error insert(const clang::SourceManager & SM, clang::SourceLocation Loc, llvm::StringRef Text, bool InsertAfter = true)
  • public void removeHeader(llvm::StringRef Header)
  • public llvm::Error replace(const clang::SourceManager & SM, clang::SourceLocation Loc, unsigned int Length, llvm::StringRef Text)
  • public llvm::Error replace(const clang::SourceManager & SM, const clang::CharSourceRange & Range, llvm::StringRef ReplacementText)
  • public void setError(llvm::StringRef Error)
  • public std::string toYAMLString()

Methods

AtomicChange(const clang::SourceManager& SM,
             clang::SourceLocation KeyPosition,
             llvm::Any Metadata)

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:45

Parameters

const clang::SourceManager& SM
clang::SourceLocation KeyPosition
llvm::Any Metadata

AtomicChange(
    std::string Key,
    std::string FilePath,
    std::string Error,
    std::vector<std::string> InsertedHeaders,
    std::vector<std::string> RemovedHeaders,
    clang::tooling::Replacements Replaces)

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:134

Parameters

std::string Key
std::string FilePath
std::string Error
std::vector<std::string> InsertedHeaders
std::vector<std::string> RemovedHeaders
clang::tooling::Replacements Replaces

AtomicChange()

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:132

AtomicChange(const clang::tooling::AtomicChange&)

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:53

Parameters

const clang::tooling::AtomicChange&

AtomicChange(const clang::SourceManager& SM,
             clang::SourceLocation KeyPosition)

Description

Creates an atomic change around \p KeyPosition with the key being a concatenation of the file name and the offset of \p KeyPosition. \p KeyPosition should be the location of the key syntactical element that is being changed, e.g. the call to a refactored method.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:43

Parameters

const clang::SourceManager& SM
clang::SourceLocation KeyPosition

AtomicChange(llvm::StringRef FilePath,
             llvm::StringRef Key)

Description

Creates an atomic change for \p FilePath with a customized key.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:49

Parameters

llvm::StringRef FilePath
llvm::StringRef Key

AtomicChange(clang::tooling::AtomicChange&&)

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:52

Parameters

clang::tooling::AtomicChange&&

void addHeader(llvm::StringRef Header)

Description

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.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:111

Parameters

llvm::StringRef Header

static clang::tooling::AtomicChange
convertFromYAML(llvm::StringRef YAMLContent)

Description

Converts a YAML-encoded automic change to AtomicChange.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:64

Parameters

llvm::StringRef YAMLContent

const std::string& getError() const

Description

Returns the error message or an empty string if it does not exist.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:83

const std::string& getFilePath() const

Description

Returns the path of the file containing this atomic change.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:71

llvm::ArrayRef<std::string> getInsertedHeaders()
    const

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:121

const std::string& getKey() const

Description

Returns the key of this change, which is a concatenation of the file name and offset of the key position.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:68

const llvm::Any& getMetadata() const

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:129

llvm::ArrayRef<std::string> getRemovedHeaders()
    const

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:125

const clang::tooling::Replacements&
getReplacements() const

Description

Returns a const reference to existing replacements.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:117

clang::tooling::Replacements& getReplacements()

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:119

bool hasError() const

Description

Returns whether an error has been set on this list.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:80

llvm::Error insert(const clang::SourceManager& SM,
                   clang::SourceLocation Loc,
                   llvm::StringRef Text,
                   bool InsertAfter = true)

Description

Adds a replacement that inserts \p Text at \p Loc. If this insertion conflicts with an existing insertion (at the same position), this will be inserted before/after the existing insertion depending on\p 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.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:105

Parameters

const clang::SourceManager& SM
clang::SourceLocation Loc
llvm::StringRef Text
bool InsertAfter = true

Returns

An llvm::Error carrying ReplacementError on error.

void removeHeader(llvm::StringRef Header)

Description

Removes a header from the file that contains the key position.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:114

Parameters

llvm::StringRef Header

llvm::Error replace(
    const clang::SourceManager& SM,
    clang::SourceLocation Loc,
    unsigned int Length,
    llvm::StringRef Text)

Description

Adds a replacement that replaces range [Loc, Loc+Length) with\p Text.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:94

Parameters

const clang::SourceManager& SM
clang::SourceLocation Loc
unsigned int Length
llvm::StringRef Text

Returns

An llvm::Error carrying ReplacementError on error.

llvm::Error replace(
    const clang::SourceManager& SM,
    const clang::CharSourceRange& Range,
    llvm::StringRef ReplacementText)

Description

Adds a replacement that replaces the given Range with ReplacementText.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:88

Parameters

const clang::SourceManager& SM
const clang::CharSourceRange& Range
llvm::StringRef ReplacementText

Returns

An llvm::Error carrying ReplacementError on error.

void setError(llvm::StringRef Error)

Description

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.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:77

Parameters

llvm::StringRef Error

std::string toYAMLString()

Description

Returns the atomic change as a YAML string.

Declared at: clang/include/clang/Tooling/Refactoring/AtomicChange.h:61