Author: krasimir Date: Tue Jan 31 05:38:02 2017 New Revision: 293617 URL: http://llvm.org/viewvc/llvm-project?rev=293617&view=rev Log: [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 Modified: cfe/trunk/lib/Format/BreakableToken.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/BreakableToken.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293617&r1=293616&r2=293617&view=diff ============================================================================== --- cfe/trunk/lib/Format/BreakableToken.cpp (original) +++ cfe/trunk/lib/Format/BreakableToken.cpp Tue Jan 31 05:38:02 2017 @@ -304,7 +304,9 @@ static bool mayReflowContent(StringRef C // 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])); Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293617&r1=293616&r2=293617&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 31 05:38:02 2017 @@ -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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits