blob: fe95056840dde2a7acec4bc3cfeb85915399cb4f [file] [log] [blame]
Benjamin Kramer6b236262016-04-20 12:43:43 +00001//===-- IncludeFixer.h - Include inserter -----------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
11#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
12
Benjamin Kramera3d82332016-05-13 09:27:54 +000013#include "SymbolIndexManager.h"
Benjamin Kramer6b236262016-04-20 12:43:43 +000014#include "clang/Tooling/Core/Replacement.h"
15#include "clang/Tooling/Tooling.h"
Eugene Zelenkoa54a2122016-05-02 17:49:00 +000016#include <memory>
17#include <vector>
Benjamin Kramer6b236262016-04-20 12:43:43 +000018
19namespace clang {
Eugene Zelenkoa54a2122016-05-02 17:49:00 +000020
21class CompilerInvocation;
22class DiagnosticConsumer;
23class FileManager;
24class PCHContainerOperations;
25
Benjamin Kramer6b236262016-04-20 12:43:43 +000026namespace include_fixer {
27
28class IncludeFixerActionFactory : public clang::tooling::ToolAction {
29public:
Benjamin Kramera3d82332016-05-13 09:27:54 +000030 /// \param SymbolIndexMgr A source for matching symbols to header files.
Benjamin Kramer6b236262016-04-20 12:43:43 +000031 /// \param Replacements Storage for the output of the fixer.
Eric Liu702cfd12016-05-19 08:21:09 +000032 /// \param StyleName Fallback style for reformatting.
Benjamin Kramer3a45fab2016-04-28 11:21:29 +000033 /// \param MinimizeIncludePaths whether inserted include paths are optimized.
Benjamin Kramer6b236262016-04-20 12:43:43 +000034 IncludeFixerActionFactory(
Eric Liu702cfd12016-05-19 08:21:09 +000035 SymbolIndexManager &SymbolIndexMgr, std::set<std::string> &Headers,
Eric Liu692aca62016-05-04 08:22:35 +000036 std::vector<clang::tooling::Replacement> &Replacements,
Eric Liu702cfd12016-05-19 08:21:09 +000037 StringRef StyleName, bool MinimizeIncludePaths = true);
38
Eugene Zelenkoa54a2122016-05-02 17:49:00 +000039 ~IncludeFixerActionFactory() override;
Benjamin Kramer6b236262016-04-20 12:43:43 +000040
41 bool
42 runInvocation(clang::CompilerInvocation *Invocation,
43 clang::FileManager *Files,
44 std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps,
45 clang::DiagnosticConsumer *Diagnostics) override;
46
47private:
48 /// The client to use to find cross-references.
Benjamin Kramera3d82332016-05-13 09:27:54 +000049 SymbolIndexManager &SymbolIndexMgr;
Benjamin Kramer6b236262016-04-20 12:43:43 +000050
Eric Liu702cfd12016-05-19 08:21:09 +000051 /// Headers to be added.
52 std::set<std::string> &Headers;
53
Benjamin Kramer6b236262016-04-20 12:43:43 +000054 /// Replacements are written here.
55 std::vector<clang::tooling::Replacement> &Replacements;
Benjamin Kramer3a45fab2016-04-28 11:21:29 +000056
57 /// Whether inserted include paths should be optimized.
58 bool MinimizeIncludePaths;
Eric Liu702cfd12016-05-19 08:21:09 +000059
60 /// The fallback format style for formatting after insertion if no
61 /// clang-format config file was found.
62 std::string FallbackStyle;
Benjamin Kramer6b236262016-04-20 12:43:43 +000063};
64
65} // namespace include_fixer
66} // namespace clang
67
68#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H