diff options
author | Haojian Wu <hokein@google.com> | 2016-07-14 09:39:12 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2016-07-14 09:39:12 +0000 |
commit | 0c05e2e4b6620f7cbb9e1b031c82287fafd742ac (patch) | |
tree | 06badf325a2a5e9504d0cf7c8afb87b924cae088 | |
parent | b0304114146ef3653c15fcbe7a0a43c9d66488d3 (diff) | |
download | bcm5719-llvm-0c05e2e4b6620f7cbb9e1b031c82287fafd742ac.tar.gz bcm5719-llvm-0c05e2e4b6620f7cbb9e1b031c82287fafd742ac.zip |
[include-fixer] Correct an incorrecst judgement about prefix scoped qualifiers.
Summary:
The judgement that checks whether the fully-qualified name has scoped qualifiers
prefix is incorrect. Should always check whether the first matched postion is the
beginning position.
Reviewers: bkramer
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D22343
llvm-svn: 275386
-rw-r--r-- | clang-tools-extra/include-fixer/IncludeFixerContext.cpp | 9 | ||||
-rw-r--r-- | clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp | 11 |
2 files changed, 15 insertions, 5 deletions
diff --git a/clang-tools-extra/include-fixer/IncludeFixerContext.cpp b/clang-tools-extra/include-fixer/IncludeFixerContext.cpp index 02b3a0e412e..988b440ca1c 100644 --- a/clang-tools-extra/include-fixer/IncludeFixerContext.cpp +++ b/clang-tools-extra/include-fixer/IncludeFixerContext.cpp @@ -42,9 +42,12 @@ std::string createQualifiedNameForReplacement( } // Append the missing stripped qualifiers. std::string FullyQualifiedName = QualifiedName + StrippedQualifiers; - auto pos = FullyQualifiedName.find(SymbolScopedQualifiers); - return FullyQualifiedName.substr( - pos == std::string::npos ? 0 : SymbolScopedQualifiers.size()); + + // Skips symbol scoped qualifiers prefix. + if (llvm::StringRef(FullyQualifiedName).startswith(SymbolScopedQualifiers)) + return FullyQualifiedName.substr(SymbolScopedQualifiers.size()); + + return FullyQualifiedName; } } // anonymous namespace diff --git a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp index 9ee7d0ab7e5..7f887a17cd0 100644 --- a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp +++ b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp @@ -63,6 +63,9 @@ static std::string runIncludeFixer( SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar.h\"", 1, {{SymbolInfo::ContextType::Namespace, "b"}, {SymbolInfo::ContextType::Namespace, "a"}}), + SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar2.h\"", 1, + {{SymbolInfo::ContextType::Namespace, "c"}, + {SymbolInfo::ContextType::Namespace, "a"}}), SymbolInfo("Green", SymbolInfo::SymbolKind::Class, "\"color.h\"", 1, {{SymbolInfo::ContextType::EnumDecl, "Color"}, {SymbolInfo::ContextType::Namespace, "b"}, @@ -237,11 +240,15 @@ TEST(IncludeFixer, FixNamespaceQualifiers) { runIncludeFixer("namespace a {\nnamespace b{\nbar b;\n}\n}\n")); EXPECT_EQ("c::b::bar b;\n", runIncludeFixer("c::b::bar b;\n")); - EXPECT_EQ("#include \"bar.h\"\nnamespace c {\na::b::bar b;\n}\n", + EXPECT_EQ("#include \"bar.h\"\nnamespace d {\na::b::bar b;\n}\n", + runIncludeFixer("namespace d {\nbar b;\n}\n")); + EXPECT_EQ("#include \"bar2.h\"\nnamespace c {\na::c::bar b;\n}\n", runIncludeFixer("namespace c {\nbar b;\n}\n")); // Test nested classes. - EXPECT_EQ("#include \"bar.h\"\nnamespace c {\na::b::bar::t b;\n}\n", + EXPECT_EQ("#include \"bar.h\"\nnamespace d {\na::b::bar::t b;\n}\n", + runIncludeFixer("namespace d {\nbar::t b;\n}\n")); + EXPECT_EQ("#include \"bar2.h\"\nnamespace c {\na::c::bar::t b;\n}\n", runIncludeFixer("namespace c {\nbar::t b;\n}\n")); EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nb::bar::t b;\n}\n", runIncludeFixer("namespace a {\nbar::t b;\n}\n")); |