//===---------- IncludeInserter.h - clang-tidy ----------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H #include "IncludeSorter.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/StringSet.h" #include <memory> #include <optional> namespace clang { class Preprocessor; namespace tidy::utils { /// 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: /// \code /// #include "../ClangTidyCheck.h" /// #include "../utils/IncludeInserter.h" /// /// namespace clang { /// namespace tidy { /// /// class MyCheck : public ClangTidyCheck { /// public: /// void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, /// Preprocessor *ModuleExpanderPP) override { /// Inserter.registerPreprocessor(PP); /// } /// /// void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... } /// /// void check( /// const ast_matchers::MatchFinder::MatchResult& Result) override { /// ... /// Inserter.createMainFileIncludeInsertion("path/to/Header.h"); /// ... /// } /// /// private: /// utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google}; /// }; /// } // namespace tidy /// } // namespace clang /// \endcode class IncludeInserter { … }; } // namespace tidy::utils } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H