From ba6b315ea92fec6bdf5092511c23f6681805cfd0 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Thu, 18 May 2017 07:36:21 +0000 Subject: [PATCH] clang-format: fix prefix for doxygen comments after member Summary: Doxygen supports putting documentation blocks after member, by adding an additional < marker in the comment block. This patch makes sure this marker is used in lines which are introduced by breaking the comment. int foo; ///< Some very long comment. becomes: int foo; ///< Some very long ///< comment. Contributed by @Typz! Reviewers: krasimir Reviewed By: krasimir Subscribers: djasper, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33282 llvm-svn: 303330 --- clang/lib/Format/BreakableToken.cpp | 7 ++++++- clang/unittests/Format/FormatTestComments.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index c97486e..f70597c 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -41,7 +41,8 @@ static bool IsBlank(char C) { } static StringRef getLineCommentIndentPrefix(StringRef Comment) { - static const char *const KnownPrefixes[] = {"///", "//", "//!"}; + static const char *const KnownPrefixes[] = { + "///<", "//!<", "///", "//", "//!"}; StringRef LongestPrefix; for (StringRef KnownPrefix : KnownPrefixes) { if (Comment.startswith(KnownPrefix)) { @@ -692,6 +693,10 @@ BreakableLineCommentSection::BreakableLineCommentSection( Prefix[i] = "/// "; else if (Prefix[i] == "//!") Prefix[i] = "//! "; + else if (Prefix[i] == "///<") + Prefix[i] = "///< "; + else if (Prefix[i] == "//!<") + Prefix[i] = "//!< "; } Tokens[i] = LineTok; diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 4238efe5..f6d4710 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -1198,6 +1198,16 @@ TEST_F(FormatTestComments, ReflowsComments) { format("/* long long long long\n" " * long */", getLLVMStyleWithColumns(20))); + EXPECT_EQ("///< long long long\n" + "///< long long\n", + format("///< long long long long\n" + "///< long\n", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("//!< long long long\n" + "//!< long long\n", + format("//!< long long long long\n" + "//!< long\n", + getLLVMStyleWithColumns(20))); // Don't bring leading whitespace up while reflowing. EXPECT_EQ("/* long long long\n" -- 2.7.4