class Replacement

Declaration

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

Description

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

Declared at: clang/include/clang/Tooling/Core/Replacement.h:83

Member Variables

private std::string FilePath
private clang::tooling::Range ReplacementRange
private std::string ReplacementText

Method Overview

  • public Replacement()
  • public Replacement(llvm::StringRef FilePath, unsigned int Offset, unsigned int Length, llvm::StringRef ReplacementText)
  • public Replacement(const clang::SourceManager & Sources, clang::SourceLocation Start, unsigned int Length, llvm::StringRef ReplacementText)
  • public Replacement(const clang::SourceManager & Sources, const clang::CharSourceRange & Range, llvm::StringRef ReplacementText, const clang::LangOptions & LangOpts = clang::LangOptions())
  • public template <typename Node> Replacement(const clang::SourceManager & Sources, const Node & NodeToReplace, llvm::StringRef ReplacementText, const clang::LangOptions & LangOpts = clang::LangOptions())
  • public bool apply(clang::Rewriter & Rewrite) const
  • public llvm::StringRef getFilePath() const
  • public unsigned int getLength() const
  • public unsigned int getOffset() const
  • public llvm::StringRef getReplacementText() const
  • public bool isApplicable() const
  • private void setFromSourceLocation(const clang::SourceManager & Sources, clang::SourceLocation Start, unsigned int Length, llvm::StringRef ReplacementText)
  • private void setFromSourceRange(const clang::SourceManager & Sources, const clang::CharSourceRange & Range, llvm::StringRef ReplacementText, const clang::LangOptions & LangOpts)
  • public std::string toString() const

Methods

Replacement()

Description

Creates an invalid (not applicable) replacement.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:86

Replacement(llvm::StringRef FilePath,
            unsigned int Offset,
            unsigned int Length,
            llvm::StringRef ReplacementText)

Description

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

Declared at: clang/include/clang/Tooling/Core/Replacement.h:94

Parameters

llvm::StringRef FilePath
A source file accessible via a SourceManager.
unsigned int Offset
The byte offset of the start of the range in the file.
unsigned int Length
The length of the range in bytes.
llvm::StringRef ReplacementText

Replacement(const clang::SourceManager& Sources,
            clang::SourceLocation Start,
            unsigned int Length,
            llvm::StringRef ReplacementText)

Description

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

Declared at: clang/include/clang/Tooling/Core/Replacement.h:99

Parameters

const clang::SourceManager& Sources
clang::SourceLocation Start
unsigned int Length
llvm::StringRef ReplacementText

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

Description

Creates a Replacement of the given range with ReplacementText.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:103

Parameters

const clang::SourceManager& Sources
const clang::CharSourceRange& Range
llvm::StringRef ReplacementText
const clang::LangOptions& LangOpts = clang::LangOptions()

template <typename Node>
Replacement(const clang::SourceManager& Sources,
            const Node& NodeToReplace,
            llvm::StringRef ReplacementText,
            const clang::LangOptions& LangOpts =
                clang::LangOptions())

Description

Creates a Replacement of the node with ReplacementText.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:109

Templates

Node

Parameters

const clang::SourceManager& Sources
const Node& NodeToReplace
llvm::StringRef ReplacementText
const clang::LangOptions& LangOpts = clang::LangOptions()

bool apply(clang::Rewriter& Rewrite) const

Description

Applies the replacement on the Rewriter.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:127

Parameters

clang::Rewriter& Rewrite

llvm::StringRef getFilePath() const

Description

Accessors. @ {

Declared at: clang/include/clang/Tooling/Core/Replacement.h:120

unsigned int getLength() const

Declared at: clang/include/clang/Tooling/Core/Replacement.h:122

unsigned int getOffset() const

Declared at: clang/include/clang/Tooling/Core/Replacement.h:121

llvm::StringRef getReplacementText() const

Declared at: clang/include/clang/Tooling/Core/Replacement.h:123

bool isApplicable() const

Description

Returns whether this replacement can be applied to a file. Only replacements that are in a valid file can be applied.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:116

void setFromSourceLocation(
    const clang::SourceManager& Sources,
    clang::SourceLocation Start,
    unsigned int Length,
    llvm::StringRef ReplacementText)

Declared at: clang/include/clang/Tooling/Core/Replacement.h:133

Parameters

const clang::SourceManager& Sources
clang::SourceLocation Start
unsigned int Length
llvm::StringRef ReplacementText

void setFromSourceRange(
    const clang::SourceManager& Sources,
    const clang::CharSourceRange& Range,
    llvm::StringRef ReplacementText,
    const clang::LangOptions& LangOpts)

Declared at: clang/include/clang/Tooling/Core/Replacement.h:135

Parameters

const clang::SourceManager& Sources
const clang::CharSourceRange& Range
llvm::StringRef ReplacementText
const clang::LangOptions& LangOpts

std::string toString() const

Description

Returns a human readable string representation.

Declared at: clang/include/clang/Tooling/Core/Replacement.h:130