clang 10.0.0git

Public Member Functions | List of all members
clang::tooling::Replacement Class Reference

A text replacement. More...

`#include "clang/Tooling/Core/Replacement.h"`

## Public Member Functions
| Replacement ()
| Creates an invalid (not applicable) replacement. More...
| Replacement (StringRef FilePath, unsigned Offset, unsigned Length, StringRef ReplacementText)
| Creates a replacement of the range [Offset, Offset+Length) in FilePath with ReplacementText. More...
| Replacement (const SourceManager &Sources, SourceLocation Start, unsigned Length, StringRef ReplacementText)
| Creates a Replacement of the range [Start, Start+Length) with ReplacementText. More...
| Replacement (const SourceManager &Sources, const CharSourceRange &Range, StringRef ReplacementText, const LangOptions &LangOpts=LangOptions())
| Creates a Replacement of the given range with ReplacementText. More...
template<typename Node >
| Replacement (const SourceManager &Sources, const Node &NodeToReplace, StringRef ReplacementText, const LangOptions &LangOpts=LangOptions())
| Creates a Replacement of the node with ReplacementText. More...
bool | isApplicable () const
| Returns whether this replacement can be applied to a file. More...
bool | apply (Rewriter &Rewrite) const
| Applies the replacement on the Rewriter. More...
std::string | toString () const
| Returns a human readable string representation. More...
StringRef | getFilePath () const
| Accessors. More...
unsigned | getOffset () const
unsigned | getLength () const
StringRef | getReplacementText () const

## Detailed Description

A text replacement.

Represents a SourceManager independent replacement of a range of text in a specific file.

Definition at line 83 of file Replacement.h.

## Constructor & Destructor Documentation

## ◆ Replacement() [1/5]

Replacement::Replacement | ( |  | ) |

Creates an invalid (not applicable) replacement.

Definition at line 45 of file Replacement.cpp.

Referenced by getRangeSize().

## ◆ Replacement() [2/5]

Replacement::Replacement | ( | StringRef | FilePath,
|  | unsigned | Offset,
|  | unsigned | Length,
|  | StringRef | ReplacementText
| ) |  |

Creates a replacement of the range [Offset, Offset+Length) in FilePath with ReplacementText.

Parameters

  FilePath | A source file accessible via a SourceManager.
  Offset | The byte offset of the start of the range in the file.
  Length | The length of the range in bytes.

Definition at line 47 of file Replacement.cpp.

## ◆ Replacement() [3/5]

Replacement::Replacement | ( | const SourceManager & | Sources,
|  | SourceLocation | Start,
|  | unsigned | Length,
|  | StringRef | ReplacementText
| ) |  |

Creates a Replacement of the range [Start, Start+Length) with ReplacementText.

Definition at line 52 of file Replacement.cpp.

## ◆ Replacement() [4/5]

Replacement::Replacement | ( | const SourceManager & | Sources,
|  | const CharSourceRange & | Range,
|  | StringRef | ReplacementText,
|  | const LangOptions & | LangOpts = `LangOptions()`
| ) |  |

Creates a Replacement of the given range with ReplacementText.

Definition at line 57 of file Replacement.cpp.

## ◆ Replacement() [5/5]

template<typename Node >

clang::tooling::Replacement::Replacement | ( | const SourceManager & | Sources,
|  | const Node & | NodeToReplace,
|  | StringRef | ReplacementText,
|  | const LangOptions & | LangOpts = `LangOptions()`
| ) |  |

Creates a Replacement of the node with ReplacementText.

Definition at line 359 of file Replacement.h.

References clang::CharSourceRange::getTokenRange().

## Member Function Documentation

## ◆ apply()

bool Replacement::apply | ( | Rewriter & | Rewrite | ) | const

Applies the replacement on the Rewriter.

Definition at line 68 of file Replacement.cpp.

References clang::SrcMgr::C_User, clang::FileManager::getFile(), clang::SourceManager::getFileManager(), clang::tooling::Range::getLength(), clang::SourceManager::getLocForStartOfFile(), clang::tooling::Range::getOffset(), clang::SourceManager::getOrCreateFileID(), clang::Rewriter::getSourceMgr(), clang::Rewriter::ReplaceText(), and SM.

## ◆ getFilePath()

StringRef clang::tooling::Replacement::getFilePath | ( |  | ) | const
| inline

Accessors.

Definition at line 120 of file Replacement.h.

Referenced by clang::tooling::Replacements::add(), getRangeSize(), clang::tooling::AtomicChange::insert(), clang::tooling::ReplacementError::message(), clang::tooling::operator<(), clang::tooling::operator==(), and clang::tooling::ReplaceNodeWithTemplate::run().

## ◆ getLength()

unsigned clang::tooling::Replacement::getLength | ( |  | ) | const
| inline

Definition at line 122 of file Replacement.h.

Referenced by clang::tooling::Replacements::add(), clang::tooling::calculateRangesAfterReplacements(), combineAndSortRanges(), clang::format::formatReplacements(), clang::tooling::Replacements::getAffectedRanges(), getRangeSize(), clang::tooling::ReplacementError::message(), clang::tooling::operator<(), and clang::tooling::operator==().

## ◆ getOffset()

unsigned clang::tooling::Replacement::getOffset | ( |  | ) | const
| inline

Definition at line 121 of file Replacement.h.

Referenced by clang::tooling::Replacements::add(), clang::tooling::calculateRangesAfterReplacements(), combineAndSortRanges(), clang::format::formatReplacements(), clang::tooling::Replacements::getAffectedRanges(), getRangeSize(), clang::tooling::AtomicChange::insert(), clang::tooling::ReplacementError::message(), clang::tooling::operator<(), and clang::tooling::operator==().

## ◆ getReplacementText()

StringRef clang::tooling::Replacement::getReplacementText | ( |  | ) | const
| inline

Definition at line 123 of file Replacement.h.

References toString().

Referenced by clang::tooling::Replacements::add(), clang::format::formatReplacements(), clang::tooling::Replacements::getAffectedRanges(), getRangeSize(), clang::tooling::ReplacementError::message(), clang::tooling::operator<(), and clang::tooling::operator==().

## ◆ isApplicable()

bool Replacement::isApplicable | ( |  | ) | const

Returns whether this replacement can be applied to a file.

Only replacements that are in a valid file can be applied.

Definition at line 64 of file Replacement.cpp.

References InvalidLocation.

## ◆ toString()

std::string Replacement::toString | ( |  | ) | const

Returns a human readable string representation.

Definition at line 87 of file Replacement.cpp.

References clang::tooling::Range::getLength(), and clang::tooling::Range::getOffset().

The documentation for this class was generated from the following files:

- include/clang/Tooling/Core/Replacement.h
- lib/Tooling/Core/Replacement.cpp