forked from OSchip/llvm-project
[include-fixer] Ignore non-scoped enum declaration during search.
Reviewers: bkramer Subscribers: cfe-commits, ioeric Differential Revision: http://reviews.llvm.org/D20354 llvm-svn: 269890
This commit is contained in:
parent
2874ac3e28
commit
ff6d195c2d
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue