clang 20.0.0git
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]

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.
 
int runAndSave (FrontendActionFactory *ActionFactory)
 Call run(), apply all generated replacements, and immediately save the results to disk.
 
bool applyAllReplacements (Rewriter &Rewrite)
 Apply all stored replacements to the given Rewriter.
 
- 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 >(), IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS=llvm::vfs::getRealFileSystem(), IntrusiveRefCntPtr< FileManager > Files=nullptr)
 Constructs a clang tool to run over a list of files.
 
 ~ClangTool ()
 
void setDiagnosticConsumer (DiagnosticConsumer *DiagConsumer)
 Set a DiagnosticConsumer to use during parsing.
 
void mapVirtualFile (StringRef FilePath, StringRef Content)
 Map a virtual file to be used while running the tool.
 
void appendArgumentsAdjuster (ArgumentsAdjuster Adjuster)
 Append a command line arguments adjuster to the adjuster chain.
 
void clearArgumentsAdjusters ()
 Clear the command line arguments adjuster chain.
 
int run (ToolAction *Action)
 Runs an action over all files specified in the command line.
 
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.
 
void setPrintErrorMessage (bool PrintErrorMessage)
 Sets whether an error message should be printed out if an action fails.
 
FileManagergetFiles ()
 Returns the file manager used in the tool.
 
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 37 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 27 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 57 of file Refactoring.cpp.

References clang::tooling::applyAllReplacements(), clang::tooling::groupReplacementsByFile(), clang::Result, and clang::Rewrite.

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 32 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 36 of file Refactoring.cpp.

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


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