Index: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp +++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp @@ -41,10 +41,16 @@ 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; } Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp +++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp @@ -62,6 +62,10 @@ 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(); SymbolIndexMgr->addSymbolIndex( @@ -166,6 +170,12 @@ 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