10#include "llvm/ADT/STLExtras.h"
13namespace include_fixer {
18llvm::SmallVector<llvm::StringRef, 8>
19SplitQualifiers(llvm::StringRef StringQualifiers) {
20 llvm::SmallVector<llvm::StringRef, 8>
Qualifiers;
21 StringQualifiers.split(Qualifiers,
"::");
25std::string createQualifiedNameForReplacement(
26 llvm::StringRef RawSymbolName,
27 llvm::StringRef SymbolScopedQualifiersName,
28 const find_all_symbols::SymbolInfo &MatchedSymbol) {
31 if (RawSymbolName.starts_with(
"::"))
32 return std::string(RawSymbolName);
34 std::string QualifiedName = MatchedSymbol.getQualifiedName();
42 auto SymbolQualifiers = SplitQualifiers(RawSymbolName);
43 std::string StrippedQualifiers;
44 while (!SymbolQualifiers.empty() &&
45 !llvm::StringRef(QualifiedName).ends_with(SymbolQualifiers.back())) {
47 "::" + SymbolQualifiers.back().str() + StrippedQualifiers;
48 SymbolQualifiers.pop_back();
51 std::string FullyQualifiedName = QualifiedName + StrippedQualifiers;
54 auto FullySymbolQualifiers = SplitQualifiers(FullyQualifiedName);
55 auto ScopedQualifiers = SplitQualifiers(SymbolScopedQualifiersName);
56 auto FullySymbolQualifiersIter = FullySymbolQualifiers.begin();
57 auto SymbolScopedQualifiersIter = ScopedQualifiers.begin();
58 while (FullySymbolQualifiersIter != FullySymbolQualifiers.end() &&
59 SymbolScopedQualifiersIter != ScopedQualifiers.end()) {
60 if (*FullySymbolQualifiersIter != *SymbolScopedQualifiersIter)
62 ++FullySymbolQualifiersIter;
63 ++SymbolScopedQualifiersIter;
66 for (; FullySymbolQualifiersIter != FullySymbolQualifiers.end();
67 ++FullySymbolQualifiersIter) {
70 Result += *FullySymbolQualifiersIter;
78 StringRef FilePath, std::vector<QuerySymbolInfo> QuerySymbols,
79 std::vector<find_all_symbols::SymbolInfo> Symbols)
80 : FilePath(FilePath), QuerySymbolInfos(std::move(QuerySymbols)),
81 MatchedSymbols(std::move(Symbols)) {
87 llvm::sort(QuerySymbolInfos,
89 return std::make_pair(A.Range.getOffset(), A.Range.getLength()) <
90 std::make_pair(B.Range.getOffset(), B.Range.getLength());
92 QuerySymbolInfos.erase(
93 std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
95 return A.Range == B.Range;
97 QuerySymbolInfos.end());
98 for (
const auto &Symbol : MatchedSymbols) {
99 HeaderInfos.push_back(
100 {Symbol.getFilePath().str(),
101 createQualifiedNameForReplacement(
102 QuerySymbolInfos.front().RawIdentifier,
103 QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
106 HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),
108 return A.Header == B.Header &&
109 A.QualifiedName == B.QualifiedName;
IncludeFixerContext()=default
@ Qualifiers
The mix involves change in the qualifiers.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//