class RefactoringTool

Declaration

class RefactoringTool : public ClangTool { /* full declaration omitted */ };

Description

A tool to run refactorings. This is a refactoring specific version of

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

Inherits from: ClangTool

Member Variables

private std::map<std::string, Replacements> FileToReplaces

Method Overview

  • public RefactoringTool(const clang::tooling::CompilationDatabase & Compilations, ArrayRef<std::string> SourcePaths, std::shared_ptr<PCHContainerOperations> PCHContainerOps = std::make_shared<clang::PCHContainerOperations>())
  • public bool applyAllReplacements(clang::Rewriter & Rewrite)
  • public std::map<std::string, Replacements> & getReplacements()
  • public int runAndSave(clang::tooling::FrontendActionFactory * ActionFactory)
  • private int saveRewrittenFiles(clang::Rewriter & Rewrite)

Inherited from ClangTool:

Methods

RefactoringTool(
    const clang::tooling::CompilationDatabase&
        Compilations,
    ArrayRef<std::string> SourcePaths,
    std::shared_ptr<PCHContainerOperations>
        PCHContainerOps = std::make_shared<
            clang::PCHContainerOperations>())

Declared at: clang/include/clang/Tooling/Refactoring.h:40

Parameters

const clang::tooling::CompilationDatabase& Compilations
ArrayRef<std::string> SourcePaths
std::shared_ptr<PCHContainerOperations> PCHContainerOps = std::make_shared<clang::PCHContainerOperations>()

bool applyAllReplacements(
    clang::Rewriter& Rewrite)

Description

Apply all stored replacements to the given Rewriter. FileToReplaces will be deduplicated with `groupReplacementsByFile` before application. Replacement applications happen independently of the success of other applications.

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

Parameters

clang::Rewriter& Rewrite

Returns

true if all replacements apply. false otherwise.

std::map<std::string, Replacements>&
getReplacements()

Description

Returns the file path to replacements map to which replacements should be added during the run of the tool.

Declared at: clang/include/clang/Tooling/Refactoring.h:47

int runAndSave(
    clang::tooling::FrontendActionFactory*
        ActionFactory)

Description

Call run(), apply all generated replacements, and immediately save the results to disk.

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

Parameters

clang::tooling::FrontendActionFactory* ActionFactory

Returns

0 upon success. Non-zero upon failure.

int saveRewrittenFiles(clang::Rewriter& Rewrite)

Description

Write all refactored files to disk.

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

Parameters

clang::Rewriter& Rewrite