summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/include-fixer/SymbolIndexManager.cpp14
-rw-r--r--clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp10
2 files changed, 20 insertions, 4 deletions
diff --git a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
index 27b0f015a33..9982a0e05a5 100644
--- a/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
+++ b/clang-tools-extra/include-fixer/SymbolIndexManager.cpp
@@ -41,10 +41,16 @@ SymbolIndexManager::search(llvm::StringRef Identifier) const {
auto SymbolContext = Symbol.getContexts().begin();
auto IdentiferContext = Names.rbegin() + 1; // Skip identifier name;
// Match the remaining context names.
- for (; IdentiferContext != Names.rend() &&
- SymbolContext != Symbol.getContexts().end();
- ++IdentiferContext, ++SymbolContext) {
- if (SymbolContext->second != *IdentiferContext) {
+ while (IdentiferContext != Names.rend() &&
+ SymbolContext != Symbol.getContexts().end()) {
+ if (SymbolContext->second == *IdentiferContext) {
+ ++IdentiferContext;
+ ++SymbolContext;
+ } else if (SymbolContext->first ==
+ find_all_symbols::SymbolInfo::ContextType::EnumDecl) {
+ // Skip non-scoped enum context.
+ ++SymbolContext;
+ } else {
IsMatched = false;
break;
}
diff --git a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
index e36edf66d57..39af81b7c1c 100644
--- a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
+++ b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
@@ -62,6 +62,10 @@ static std::string runIncludeFixer(
SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar.h\"",
1, {{SymbolInfo::ContextType::Namespace, "b"},
{SymbolInfo::ContextType::Namespace, "a"}}),
+ SymbolInfo("Green", SymbolInfo::SymbolKind::Class, "\"color.h\"",
+ 1, {{SymbolInfo::ContextType::EnumDecl, "Color"},
+ {SymbolInfo::ContextType::Namespace, "b"},
+ {SymbolInfo::ContextType::Namespace, "a"}}),
};
auto SymbolIndexMgr = llvm::make_unique<include_fixer::SymbolIndexManager>();
SymbolIndexMgr->addSymbolIndex(
@@ -166,6 +170,12 @@ TEST(IncludeFixer, ScopedNamespaceSymbols) {
EXPECT_EQ("#include \"bar.h\"\nnamespace A { b::bar b; }\n",
runIncludeFixer("namespace A { b::bar b; }\n"));
}
+
+TEST(IncludeFixer, EnumConstantSymbols) {
+ EXPECT_EQ("#include \"color.h\"\nint test = a::b::Green;\n",
+ runIncludeFixer("int test = a::b::Green;\n"));
+}
+
} // namespace
} // namespace include_fixer
} // namespace clang
OpenPOWER on IntegriCloud