[clang-tools-extra] r269890 - [include-fixer] Ignore non-scoped enum declaration during search.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed May 18 02:04:44 PDT 2016
Author: hokein
Date: Wed May 18 04:04:43 2016
New Revision: 269890
URL: http://llvm.org/viewvc/llvm-project?rev=269890&view=rev
Log:
[include-fixer] Ignore non-scoped enum declaration during search.
Reviewers: bkramer
Subscribers: cfe-commits, ioeric
Differential Revision: http://reviews.llvm.org/D20354
Modified:
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
Modified: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp?rev=269890&r1=269889&r2=269890&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp Wed May 18 04:04:43 2016
@@ -41,10 +41,16 @@ SymbolIndexManager::search(llvm::StringR
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;
}
Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=269890&r1=269889&r2=269890&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Wed May 18 04:04:43 2016
@@ -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, ScopedNamespaceSymbol
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
More information about the cfe-commits
mailing list