r357695 - [clang-format] Preserve include blocks in ObjC Google style

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 4 07:04:26 PDT 2019


Author: krasimir
Date: Thu Apr  4 07:04:26 2019
New Revision: 357695

URL: http://llvm.org/viewvc/llvm-project?rev=357695&view=rev
Log:
[clang-format] Preserve include blocks in ObjC Google style

Summary:
r357567 started to regroup include block for Google style; it was meant to apply
only for C++. This patch reverts this for ObjC.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: thakis, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60263

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/SortIncludesTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357695&r1=357694&r2=357695&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Apr  4 07:04:26 2019
@@ -877,6 +877,11 @@ FormatStyle getGoogleStyle(FormatStyle::
   } else if (Language == FormatStyle::LK_ObjC) {
     GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
     GoogleStyle.ColumnLimit = 100;
+    // "Regroup" doesn't work well for ObjC yet (main header heuristic,
+    // relationship between ObjC standard library headers and other heades,
+    // #imports, etc.)
+    GoogleStyle.IncludeStyle.IncludeBlocks =
+        tooling::IncludeStyle::IBS_Preserve;
   }
 
   return GoogleStyle;

Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=357695&r1=357694&r2=357695&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original)
+++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Thu Apr  4 07:04:26 2019
@@ -653,6 +653,18 @@ TEST_F(SortIncludesTest, DoNotOutputRepl
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
+
+TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
+  FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
+
+  EXPECT_EQ("#include <a.h>\n"
+            "#include <b.h>\n"
+            "#include \"a.h\"",
+            sort("#include <b.h>\n"
+                 "#include <a.h>\n"
+                 "#include \"a.h\""));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang




More information about the cfe-commits mailing list