clang-tools  8.0.0
IncludeFixerContext.h
Go to the documentation of this file.
1 //===-- IncludeFixerContext.h - Include fixer context -----------*- 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_INCLUDEFIXERCONTEXT_H
11 #define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
12 
14 #include "clang/Tooling/Core/Replacement.h"
15 #include <string>
16 #include <vector>
17 
18 namespace clang {
19 namespace include_fixer {
20 
21 /// \brief A context for a file being processed. It includes all query
22 /// information, e.g. symbols being queried in database, all header candidates.
24 public:
25  struct HeaderInfo {
26  /// \brief The header where QualifiedName comes from.
27  std::string Header;
28  /// \brief A symbol name with completed namespace qualifiers which will
29  /// replace the original symbol.
30  std::string QualifiedName;
31  };
32 
33  struct QuerySymbolInfo {
34  /// \brief The raw symbol name being queried in database. This name might
35  /// miss some namespace qualifiers, and will be replaced by a fully
36  /// qualified one.
37  std::string RawIdentifier;
38 
39  /// \brief The qualifiers of the scope in which SymbolIdentifier lookup
40  /// occurs. It is represented as a sequence of names and scope resolution
41  /// operatiors ::, ending with a scope resolution operator (e.g. a::b::).
42  /// Empty if SymbolIdentifier is not in a specific scope.
43  std::string ScopedQualifiers;
44 
45  /// \brief The replacement range of RawIdentifier.
47  };
48 
49  IncludeFixerContext() = default;
50  IncludeFixerContext(StringRef FilePath,
51  std::vector<QuerySymbolInfo> QuerySymbols,
52  std::vector<find_all_symbols::SymbolInfo> Symbols);
53 
54  /// \brief Get symbol name.
55  llvm::StringRef getSymbolIdentifier() const {
56  return QuerySymbolInfos.front().RawIdentifier;
57  }
58 
59  /// \brief Get replacement range of the symbol.
61  return QuerySymbolInfos.front().Range;
62  }
63 
64  /// \brief Get the file path to the file being processed.
65  StringRef getFilePath() const { return FilePath; }
66 
67  /// \brief Get header information.
68  const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
69 
70  /// \brief Get information of symbols being querid.
71  const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const {
72  return QuerySymbolInfos;
73  }
74 
75 private:
76  friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
77 
78  /// \brief The file path to the file being processed.
79  std::string FilePath;
80 
81  /// \brief All instances of an unidentified symbol being queried.
82  std::vector<QuerySymbolInfo> QuerySymbolInfos;
83 
84  /// \brief The symbol candidates which match SymbolIdentifier. The symbols are
85  /// sorted in a descending order based on the popularity info in SymbolInfo.
86  std::vector<find_all_symbols::SymbolInfo> MatchedSymbols;
87 
88  /// \brief The header information.
89  std::vector<HeaderInfo> HeaderInfos;
90 };
91 
92 } // namespace include_fixer
93 } // namespace clang
94 
95 #endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
std::string QualifiedName
A symbol name with completed namespace qualifiers which will replace the original symbol...
const std::vector< QuerySymbolInfo > & getQuerySymbolInfos() const
Get information of symbols being querid.
StringRef getFilePath() const
Get the file path to the file being processed.
A context for a file being processed.
const std::vector< HeaderInfo > & getHeaderInfos() const
Get header information.
std::string RawIdentifier
The raw symbol name being queried in database.
std::string Header
The header where QualifiedName comes from.
tooling::Range Range
The replacement range of RawIdentifier.
llvm::StringRef getSymbolIdentifier() const
Get symbol name.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
std::string ScopedQualifiers
The qualifiers of the scope in which SymbolIdentifier lookup occurs.
tooling::Range getSymbolRange() const
Get replacement range of the symbol.