clang-tools  6.0.0svn
Public Member Functions | Friends | List of all members
clang::tidy::utils::IncludeInserter Class Reference

Produces fixes to insert specified includes to source files, if not yet present. More...

#include <IncludeInserter.h>

Public Member Functions

 IncludeInserter (const SourceManager &SourceMgr, const LangOptions &LangOpts, IncludeSorter::IncludeStyle Style)
 
 ~IncludeInserter ()
 
std::unique_ptr< PPCallbacksCreatePPCallbacks ()
 Create PPCallbacks for registration with the compiler's preprocessor. More...
 
llvm::Optional< FixItHint > CreateIncludeInsertion (FileID FileID, llvm::StringRef Header, bool IsAngled)
 Creates a Header inclusion directive fixit. More...
 

Friends

class IncludeInserterCallback
 

Detailed Description

Produces fixes to insert specified includes to source files, if not yet present.

IncludeInserter can be used by ClangTidyCheck in the following fashion:

class MyCheck : public ClangTidyCheck {
public:
void registerPPCallbacks(CompilerInstance& Compiler) override {
Inserter.reset(new IncludeInserter(&Compiler.getSourceManager(),
&Compiler.getLangOpts()));
Compiler.getPreprocessor().addPPCallbacks(
Inserter->CreatePPCallback());
}
void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
void check(
const ast_matchers::MatchFinder::MatchResult& Result) override {
...
Inserter->CreateIncludeInsertion(
Result.SourceManager->getMainFileID(), "path/to/Header.h",
/*IsAngled=*/false);
...
}
private:
std::unique_ptr<IncludeInserter> Inserter;
};

Definition at line 55 of file IncludeInserter.h.

Constructor & Destructor Documentation

◆ IncludeInserter()

clang::tidy::utils::IncludeInserter::IncludeInserter ( const SourceManager &  SourceMgr,
const LangOptions &  LangOpts,
IncludeSorter::IncludeStyle  Style 
)

Definition at line 37 of file IncludeInserter.cpp.

◆ ~IncludeInserter()

clang::tidy::utils::IncludeInserter::~IncludeInserter ( )

Definition at line 42 of file IncludeInserter.cpp.

Member Function Documentation

◆ CreateIncludeInsertion()

llvm::Optional< FixItHint > clang::tidy::utils::IncludeInserter::CreateIncludeInsertion ( FileID  FileID,
llvm::StringRef  Header,
bool  IsAngled 
)

Creates a Header inclusion directive fixit.

Returns llvm::None on error or if inclusion directive already exists.

Definition at line 49 of file IncludeInserter.cpp.

References IsAngled.

◆ CreatePPCallbacks()

std::unique_ptr< PPCallbacks > clang::tidy::utils::IncludeInserter::CreatePPCallbacks ( )

Create PPCallbacks for registration with the compiler's preprocessor.

Definition at line 44 of file IncludeInserter.cpp.

Friends And Related Function Documentation

◆ IncludeInserterCallback

friend class IncludeInserterCallback
friend

Definition at line 78 of file IncludeInserter.h.


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