[clang-tools-extra] r270055 - [include-fixer] Make search handle fully qualified names correctly.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Thu May 19 05:41:57 PDT 2016


Author: d0k
Date: Thu May 19 07:41:56 2016
New Revision: 270055

URL: http://llvm.org/viewvc/llvm-project?rev=270055&view=rev
Log:
[include-fixer] Make search handle fully qualified names correctly.

If a search string starts with "::" we don't want to return any results
for suffixes of that string.

Differential Revision: http://reviews.llvm.org/D20424

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=270055&r1=270054&r2=270055&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp Thu May 19 07:41:56 2016
@@ -24,6 +24,12 @@ SymbolIndexManager::search(llvm::StringR
   llvm::SmallVector<llvm::StringRef, 8> Names;
   Identifier.split(Names, "::");
 
+  bool IsFullyQualified = false;
+  if (Identifier.startswith("::")) {
+    Names.erase(Names.begin()); // Drop first (empty) element.
+    IsFullyQualified = true;
+  }
+
   // As long as we don't find a result keep stripping name parts from the end.
   // This is to support nested classes which aren't recorded in the database.
   // Eventually we will either hit a class (namespaces aren't in the database
@@ -61,6 +67,11 @@ SymbolIndexManager::search(llvm::StringR
           }
         }
 
+        // If the name was qualified we only want to add results if we evaluated
+        // all contexts.
+        if (IsFullyQualified)
+          IsMatched &= (SymbolContext == Symbol.getContexts().end());
+
         // FIXME: Support full match. At this point, we only find symbols in
         // database which end with the same contexts with the identifier.
         if (IsMatched && IdentiferContext == Names.rend()) {

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=270055&r1=270054&r2=270055&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Thu May 19 07:41:56 2016
@@ -103,6 +103,12 @@ TEST(IncludeFixer, Typo) {
   // too.
   EXPECT_EQ("#include <string>\n\nstring foo;\n",
             runIncludeFixer("string foo;\n"));
+
+  // Fully qualified name.
+  EXPECT_EQ("#include <string>\n\n::std::string foo;\n",
+            runIncludeFixer("::std::string foo;\n"));
+  // Should not match std::string.
+  EXPECT_EQ("::string foo;\n", runIncludeFixer("::string foo;\n"));
 }
 
 TEST(IncludeFixer, IncompleteType) {




More information about the cfe-commits mailing list