clang-tools 20.0.0git
IncludeFixerContext.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
10#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
11
13#include "clang/Tooling/Core/Replacement.h"
14#include <string>
15#include <vector>
16
17namespace clang {
18namespace include_fixer {
19
20/// A context for a file being processed. It includes all query
21/// information, e.g. symbols being queried in database, all header candidates.
23public:
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;
30 };
31
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;
37
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;
43
44 /// The replacement range of RawIdentifier.
45 tooling::Range Range;
46 };
47
49 IncludeFixerContext(StringRef FilePath,
50 std::vector<QuerySymbolInfo> QuerySymbols,
51 std::vector<find_all_symbols::SymbolInfo> Symbols);
52
53 /// Get symbol name.
54 llvm::StringRef getSymbolIdentifier() const {
55 return QuerySymbolInfos.front().RawIdentifier;
56 }
57
58 /// Get replacement range of the symbol.
59 tooling::Range getSymbolRange() const {
60 return QuerySymbolInfos.front().Range;
61 }
62
63 /// Get the file path to the file being processed.
64 StringRef getFilePath() const { return FilePath; }
65
66 /// Get header information.
67 const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
68
69 /// Get information of symbols being querid.
70 const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const {
71 return QuerySymbolInfos;
72 }
73
74private:
75 friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
76
77 /// The file path to the file being processed.
78 std::string FilePath;
79
80 /// All instances of an unidentified symbol being queried.
81 std::vector<QuerySymbolInfo> QuerySymbolInfos;
82
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;
86
87 /// The header information.
88 std::vector<HeaderInfo> HeaderInfos;
89};
90
91} // namespace include_fixer
92} // namespace clang
93
94#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
A context for a file being processed.
tooling::Range getSymbolRange() const
Get replacement range of the symbol.
const std::vector< HeaderInfo > & getHeaderInfos() const
Get header information.
StringRef getFilePath() const
Get the file path to the file being processed.
llvm::StringRef getSymbolIdentifier() const
Get symbol name.
const std::vector< QuerySymbolInfo > & getQuerySymbolInfos() const
Get information of symbols being querid.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::string QualifiedName
A symbol name with completed namespace qualifiers which will replace the original symbol.
std::string Header
The header where QualifiedName comes from.
std::string RawIdentifier
The raw symbol name being queried in database.
std::string ScopedQualifiers
The qualifiers of the scope in which SymbolIdentifier lookup occurs.
tooling::Range Range
The replacement range of RawIdentifier.