clang 8.0.0

Public Types | Public Member Functions | List of all members
clang::FixItRewriter Class Reference

`#include "clang/Rewrite/Frontend/FixItRewriter.h"`

Inheritance diagram for clang::FixItRewriter:
[legend]
Collaboration diagram for clang::FixItRewriter:
[legend]

## Public Types
using | iterator = Rewriter::buffer_iterator

## Public Member Functions
| FixItRewriter (DiagnosticsEngine &Diags, SourceManager &SourceMgr, const LangOptions &LangOpts, FixItOptions *FixItOpts)
| Initialize a new fix-it rewriter. More...
| ~FixItRewriter () override
| Destroy the fix-it rewriter. More...
bool | IsModified (FileID ID) const
| Check whether there are modifications for a given file. More...
iterator | buffer_begin ()
iterator | buffer_end ()
bool | WriteFixedFile (FileID ID, raw_ostream &OS)
| Write a single modified source file. More...
bool | WriteFixedFiles (std::vector< std::pair< std::string, std::string >> *RewrittenFiles=nullptr)
| Write the modified source files. More...
bool | IncludeInDiagnosticCounts () const override
| IncludeInDiagnosticCounts - This method (whose default implementation returns true) indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number of diagnostics reported by DiagnosticsEngine. More...
void | HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
| HandleDiagnostic - Handle this diagnostic, reporting it to the user or capturing it to a log as needed. More...
void | Diag (SourceLocation Loc, unsigned DiagID)
| Emit a diagnostic via the adapted diagnostic client. More...
Public Member Functions inherited from clang::DiagnosticConsumer
| DiagnosticConsumer ()=default
virtual | ~DiagnosticConsumer ()
unsigned | getNumErrors () const
unsigned | getNumWarnings () const
virtual void | clear ()
virtual void | BeginSourceFile (const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
| Callback to inform the diagnostic client that processing of a source file is beginning. More...
virtual void | EndSourceFile ()
| Callback to inform the diagnostic client that processing of a source file has ended. More...
virtual void | finish ()
| Callback to inform the diagnostic client that processing of all source files has ended. More...

## Additional Inherited Members
Protected Attributes inherited from clang::DiagnosticConsumer
unsigned | NumWarnings = 0
| Number of warnings reported. More...
unsigned | NumErrors = 0
| Number of errors reported. More...

## Detailed Description

Definition at line 63 of file FixItRewriter.h.

## Member Typedef Documentation

## ◆ iterator

using clang::FixItRewriter::iterator = Rewriter::buffer_iterator

Definition at line 101 of file FixItRewriter.h.

## Constructor & Destructor Documentation

## ◆ FixItRewriter()

FixItRewriter::FixItRewriter | ( | DiagnosticsEngine & | Diags,
|  | SourceManager & | SourceMgr,
|  | const LangOptions & | LangOpts,
|  | FixItOptions * | FixItOpts
| ) |  |

Initialize a new fix-it rewriter.

Definition at line 38 of file FixItRewriter.cpp.

References clang::DiagnosticsEngine::getClient(), clang::DiagnosticsEngine::setClient(), and clang::DiagnosticsEngine::takeClient().

## ◆ ~FixItRewriter()

FixItRewriter::~FixItRewriter | ( |  | ) |
| override

Destroy the fix-it rewriter.

Definition at line 48 of file FixItRewriter.cpp.

References clang::DiagnosticsEngine::setClient().

## Member Function Documentation

## ◆ buffer_begin()

iterator clang::FixItRewriter::buffer_begin | ( |  | ) |
| inline

Definition at line 104 of file FixItRewriter.h.

References clang::Rewriter::buffer_begin().

Referenced by WriteFixedFiles().

## ◆ buffer_end()

iterator clang::FixItRewriter::buffer_end | ( |  | ) |
| inline

Definition at line 105 of file FixItRewriter.h.

References clang::Rewriter::buffer_end(), and Diag().

Referenced by WriteFixedFiles().

## ◆ Diag()

void FixItRewriter::Diag | ( | SourceLocation | Loc,
|  | unsigned | DiagID
| ) |  |

Emit a diagnostic via the adapted diagnostic client.

Definition at line 198 of file FixItRewriter.cpp.

References clang::FixItOptions::~FixItOptions().

Referenced by HandleDiagnostic(), and WriteFixedFiles().

## ◆ HandleDiagnostic()

void FixItRewriter::HandleDiagnostic | ( | DiagnosticsEngine::Level | DiagLevel,
|  | const Diagnostic & | Info
| ) |  |
| override virtual

HandleDiagnostic - Handle this diagnostic, reporting it to the user or capturing it to a log as needed.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 127 of file FixItRewriter.cpp.

References clang::FixItHint::BeforePreviousInsertions, clang::FixItHint::CodeToInsert, Diag(), clang::DiagnosticsEngine::Error, clang::CharSourceRange::getBegin(), clang::CharSourceRange::getEnd(), clang::Diagnostic::getFixItHint(), clang::Diagnostic::getLocation(), clang::Diagnostic::getNumFixItHints(), clang::DiagnosticConsumer::HandleDiagnostic(), clang::edit::Commit::insert(), clang::FixItHint::InsertFromRange, clang::edit::Commit::insertFromRange(), clang::edit::Commit::isCommitable(), clang::CharSourceRange::isTokenRange(), clang::CharSourceRange::isValid(), clang::Last, clang::DiagnosticsEngine::Note, clang::edit::Commit::remove(), clang::FixItHint::RemoveRange, and clang::edit::Commit::replace().

## ◆ IncludeInDiagnosticCounts()

bool FixItRewriter::IncludeInDiagnosticCounts | ( |  | ) | const
| override virtual

IncludeInDiagnosticCounts - This method (whose default implementation returns true) indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number of diagnostics reported by DiagnosticsEngine.

Reimplemented from clang::DiagnosticConsumer.

Definition at line 123 of file FixItRewriter.cpp.

## ◆ IsModified()

bool clang::FixItRewriter::IsModified | ( | FileID | ID | ) | const
| inline

Check whether there are modifications for a given file.

Definition at line 97 of file FixItRewriter.h.

References clang::Rewriter::getRewriteBufferFor().

## ◆ WriteFixedFile()

bool FixItRewriter::WriteFixedFile | ( | FileID | ID,
|  | raw_ostream & | OS
| ) |  |

Write a single modified source file.

Returns
  true if there was an error, false otherwise.

Definition at line 52 of file FixItRewriter.cpp.

References clang::CharSourceRange::getBegin(), clang::Rewriter::getRangeSize(), clang::Rewriter::getRewriteBufferFor(), clang::Rewriter::InsertText(), clang::Rewriter::ReplaceText(), clang::comments::tok::text, and clang::RewriteBuffer::write().

## ◆ WriteFixedFiles()

bool FixItRewriter::WriteFixedFiles | ( | std::vector< std::pair< std::string, std::string >> * | RewrittenFiles = `nullptr` | ) |

Write the modified source files.

Returns
  true if there was an error, false otherwise.

Definition at line 79 of file FixItRewriter.cpp.

References buffer_begin(), buffer_end(), Diag(), Filename, clang::FileEntry::getName(), and clang::RewriteBuffer::write().

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

- include/clang/Rewrite/Frontend/FixItRewriter.h
- lib/Frontend/Rewrite/FixItRewriter.cpp