From 71359673dc54191605c5fd507246ff13363a80c6 Mon Sep 17 00:00:00 2001
From: Krasimir Georgiev <krasimir@google.com>
Date: Tue, 31 Jan 2017 11:38:02 +0000
Subject: [PATCH] [clang-format] Don't reflow comment lines starting with '@'.

Summary:
This patch stops reflowing comment lines starting with '@', since they commonly
have a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293617 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/BreakableToken.cpp   | 4 +++-
 unittests/Format/FormatTest.cpp | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index 95d1a63dfa8..dd28ba7d4a2 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -304,7 +304,9 @@ static bool mayReflowContent(StringRef Content) {
   // Simple heuristic for what to reflow: content should contain at least two
   // characters and either the first or second character must be
   // non-punctuation.
-  return Content.size() >= 2 && !Content.endswith("\\") &&
+  return Content.size() >= 2 &&
+         // Lines starting with '@' commonly have special meaning.
+         !Content.startswith("@") && !Content.endswith("\\") &&
          // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
          // true, then the first code point must be 1 byte long.
          (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 4d4b64b20b3..7348fa030df 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2244,6 +2244,15 @@ TEST_F(FormatTest, ReflowsComments) {
                 "// long long long long\n"
                 "// ... --- ...",
                 getLLVMStyleWithColumns(20)));
+
+  // Don't reflow lines starting with '@'.
+  EXPECT_EQ("// long long long\n"
+            "// long\n"
+            "// @param arg",
+            format("// long long long long\n"
+                   "// @param arg",
+                   getLLVMStyleWithColumns(20)));
+
   // Reflow lines that have a non-punctuation character among their first 2
   // characters.
   EXPECT_EQ("// long long long\n"
-- 
GitLab