[include-fixer] Add mising qualifiers to all instances of an unidentified symbol.
Reviewers: bkramer
Subscribers: ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D22567
llvm-svn: 276280
diff --git a/clang-tools-extra/include-fixer/IncludeFixerContext.cpp b/clang-tools-extra/include-fixer/IncludeFixerContext.cpp
index 51713b5..c0223d5 100644
--- a/clang-tools-extra/include-fixer/IncludeFixerContext.cpp
+++ b/clang-tools-extra/include-fixer/IncludeFixerContext.cpp
@@ -75,14 +75,33 @@
} // anonymous namespace
IncludeFixerContext::IncludeFixerContext(
- const QuerySymbolInfo &QuerySymbol,
+ std::vector<QuerySymbolInfo> QuerySymbols,
std::vector<find_all_symbols::SymbolInfo> Symbols)
- : MatchedSymbols(std::move(Symbols)), QuerySymbol(QuerySymbol) {
+ : QuerySymbolInfos(std::move(QuerySymbols)),
+ MatchedSymbols(std::move(Symbols)) {
+ // Remove replicated QuerySymbolInfos with the same range.
+ //
+ // QuerySymbolInfos may contain replicated elements. Because CorrectTypo
+ // callback doesn't always work as we expected. In somecases, it will be
+ // triggered at the same position or unidentified symbol multiple times.
+ std::sort(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
+ [&](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+ if (A.Range.getOffset() != B.Range.getOffset())
+ return A.Range.getOffset() < B.Range.getOffset();
+ return A.Range.getLength() == B.Range.getLength();
+ });
+ QuerySymbolInfos.erase(
+ std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
+ [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+ return A.Range == B.Range;
+ }),
+ QuerySymbolInfos.end());
for (const auto &Symbol : MatchedSymbols) {
HeaderInfos.push_back(
{Symbol.getFilePath().str(),
createQualifiedNameForReplacement(
- QuerySymbol.RawIdentifier, QuerySymbol.ScopedQualifiers, Symbol)});
+ QuerySymbolInfos.front().RawIdentifier,
+ QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
}
// Deduplicate header infos.
HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),