[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / clang-include-fixer / IncludeFixerContext.h
blobe819d30b2915664c601f2aa2c0b2db67d3dc488c
1 //===-- IncludeFixerContext.h - Include fixer context -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
10 #define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
12 #include "find-all-symbols/SymbolInfo.h"
13 #include "clang/Tooling/Core/Replacement.h"
14 #include <string>
15 #include <vector>
17 namespace clang {
18 namespace include_fixer {
20 /// A context for a file being processed. It includes all query
21 /// information, e.g. symbols being queried in database, all header candidates.
22 class IncludeFixerContext {
23 public:
24 struct HeaderInfo {
25 /// The header where QualifiedName comes from.
26 std::string Header;
27 /// A symbol name with completed namespace qualifiers which will
28 /// replace the original symbol.
29 std::string QualifiedName;
32 struct QuerySymbolInfo {
33 /// The raw symbol name being queried in database. This name might
34 /// miss some namespace qualifiers, and will be replaced by a fully
35 /// qualified one.
36 std::string RawIdentifier;
38 /// The qualifiers of the scope in which SymbolIdentifier lookup
39 /// occurs. It is represented as a sequence of names and scope resolution
40 /// operators ::, ending with a scope resolution operator (e.g. a::b::).
41 /// Empty if SymbolIdentifier is not in a specific scope.
42 std::string ScopedQualifiers;
44 /// The replacement range of RawIdentifier.
45 tooling::Range Range;
48 IncludeFixerContext() = default;
49 IncludeFixerContext(StringRef FilePath,
50 std::vector<QuerySymbolInfo> QuerySymbols,
51 std::vector<find_all_symbols::SymbolInfo> Symbols);
53 /// Get symbol name.
54 llvm::StringRef getSymbolIdentifier() const {
55 return QuerySymbolInfos.front().RawIdentifier;
58 /// Get replacement range of the symbol.
59 tooling::Range getSymbolRange() const {
60 return QuerySymbolInfos.front().Range;
63 /// Get the file path to the file being processed.
64 StringRef getFilePath() const { return FilePath; }
66 /// Get header information.
67 const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
69 /// Get information of symbols being querid.
70 const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const {
71 return QuerySymbolInfos;
74 private:
75 friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
77 /// The file path to the file being processed.
78 std::string FilePath;
80 /// All instances of an unidentified symbol being queried.
81 std::vector<QuerySymbolInfo> QuerySymbolInfos;
83 /// The symbol candidates which match SymbolIdentifier. The symbols are
84 /// sorted in a descending order based on the popularity info in SymbolInfo.
85 std::vector<find_all_symbols::SymbolInfo> MatchedSymbols;
87 /// The header information.
88 std::vector<HeaderInfo> HeaderInfos;
91 } // namespace include_fixer
92 } // namespace clang
94 #endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H