[PATCH] D22343: [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:46:44 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL275386: [include-fixer] Correct an incorrecst judgement about prefix scoped qualifiers. (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D22343?vs=63941&id=63942#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D22343

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

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
@@ -63,6 +63,9 @@
       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 @@
             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"));
Index: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
===================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
+++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp
@@ -42,9 +42,12 @@
   }
   // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22343.63942.patch
Type: text/x-patch
Size: 2765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160714/bb7d229b/attachment-0001.bin>


More information about the cfe-commits mailing list