clang  6.0.0svn
Public Member Functions | List of all members
clang::tooling::RefactoringTool Class Reference

A tool to run refactorings. More...

#include "clang/Tooling/Refactoring.h"

Inheritance diagram for clang::tooling::RefactoringTool:
Inheritance graph
[legend]
Collaboration diagram for clang::tooling::RefactoringTool:
Collaboration graph
[legend]

Public Member Functions

 RefactoringTool (const CompilationDatabase &Compilations, ArrayRef< std::string > SourcePaths, std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
 
std::map< std::string, Replacements > & getReplacements ()
 Returns the file path to replacements map to which replacements should be added during the run of the tool. More...
 
int runAndSave (FrontendActionFactory *ActionFactory)
 Call run(), apply all generated replacements, and immediately save the results to disk. More...
 
bool applyAllReplacements (Rewriter &Rewrite)
 Apply all stored replacements to the given Rewriter. More...
 
- Public Member Functions inherited from clang::tooling::ClangTool
 ClangTool (const CompilationDatabase &Compilations, ArrayRef< std::string > SourcePaths, std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
 Constructs a clang tool to run over a list of files. More...
 
 ~ClangTool ()
 
void setDiagnosticConsumer (DiagnosticConsumer *DiagConsumer)
 Set a DiagnosticConsumer to use during parsing. More...
 
void mapVirtualFile (StringRef FilePath, StringRef Content)
 Map a virtual file to be used while running the tool. More...
 
void appendArgumentsAdjuster (ArgumentsAdjuster Adjuster)
 Append a command line arguments adjuster to the adjuster chain. More...
 
void clearArgumentsAdjusters ()
 Clear the command line arguments adjuster chain. More...
 
int run (ToolAction *Action)
 Runs an action over all files specified in the command line. More...
 
int buildASTs (std::vector< std::unique_ptr< ASTUnit >> &ASTs)
 Create an AST for each file specified in the command line and append them to ASTs. More...
 
FileManagergetFiles ()
 Returns the file manager used in the tool. More...
 
llvm::ArrayRef< std::string > getSourcePaths () const
 

Detailed Description

A tool to run refactorings.

This is a refactoring specific version of

See also
ClangTool. FrontendActions passed to run() and runAndSave() should add replacements to getReplacements().

Definition at line 38 of file Refactoring.h.

Constructor & Destructor Documentation

◆ RefactoringTool()

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

Definition at line 28 of file Refactoring.cpp.

Member Function Documentation

◆ applyAllReplacements()

bool clang::tooling::RefactoringTool::applyAllReplacements ( Rewriter Rewrite)

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.

Returns
true if all replacements apply. false otherwise.

Definition at line 58 of file Refactoring.cpp.

References clang::tooling::applyAllReplacements(), clang::SourceManager::getFileManager(), clang::Rewriter::getSourceMgr(), clang::tooling::groupReplacementsByFile(), and clang::Rewriter::overwriteChangedFiles().

Referenced by runAndSave().

◆ getReplacements()

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

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

Definition at line 33 of file Refactoring.cpp.

◆ runAndSave()

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

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

Returns
0 upon success. Non-zero upon failure.

Definition at line 37 of file Refactoring.cpp.

References applyAllReplacements(), clang::tooling::ClangTool::getFiles(), and clang::tooling::ClangTool::run().


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