clang-tools  12.0.0git
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 in clang-tidy checks in the following way:

#include "../utils/IncludeInserter.h"
#include "clang/Frontend/CompilerInstance.h"
class MyCheck : public ClangTidyCheck {
public:
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
Inserter = std::make_unique<IncludeInserter>(
SM, getLangOpts(), utils::IncludeSorter::IS_Google);
PP->addPPCallbacks(Inserter->CreatePPCallbacks());
}
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<clang::tidy::utils::IncludeInserter> Inserter;
};

Definition at line 56 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 62 of file IncludeInserter.cpp.

References clang::tidy::utils::IncludeSorter::AddInclude(), clang::tidy::utils::IncludeSorter::CreateIncludeInsertion(), FileName, and 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 80 of file IncludeInserter.h.


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