[clang-tools-extra] r275386 - [include-fixer] Correct an incorrecst judgement about prefix scoped qualifiers.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 14 02:39:12 PDT 2016


Author: hokein
Date: Thu Jul 14 04:39:12 2016
New Revision: 275386

URL: http://llvm.org/viewvc/llvm-project?rev=275386&view=rev
Log:
[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

Modified:
    clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
    clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp?rev=275386&r1=275385&r2=275386&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp Thu Jul 14 04:39:12 2016
@@ -42,9 +42,12 @@ std::string createQualifiedNameForReplac
   }
   // 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

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=275386&r1=275385&r2=275386&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Thu Jul 14 04:39:12 2016
@@ -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, FixNamespaceQualifier
             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"));




More information about the cfe-commits mailing list