Align trailing block comments like trailing line comments.
llvm-svn: 174537
This commit is contained in:
parent
8911b86400
commit
94f0e1382a
|
@ -80,6 +80,11 @@ FormatStyle getChromiumStyle() {
|
|||
return ChromiumStyle;
|
||||
}
|
||||
|
||||
static bool isTrailingComment(const AnnotatedToken &Tok) {
|
||||
return Tok.is(tok::comment) &&
|
||||
(Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
|
||||
}
|
||||
|
||||
/// \brief Manages the whitespaces around tokens and their replacements.
|
||||
///
|
||||
/// This includes special handling for certain constructs, e.g. the alignment of
|
||||
|
@ -99,8 +104,7 @@ public:
|
|||
|
||||
// Align line comments if they are trailing or if they continue other
|
||||
// trailing comments.
|
||||
if (Tok.Type == TT_LineComment &&
|
||||
(Tok.Parent != NULL || !Comments.empty())) {
|
||||
if (isTrailingComment(Tok) && (Tok.Parent != NULL || !Comments.empty())) {
|
||||
if (Style.ColumnLimit >=
|
||||
Spaces + WhitespaceStartColumn + Tok.FormatTok.TokenLength) {
|
||||
Comments.push_back(StoredComment());
|
||||
|
@ -115,7 +119,7 @@ public:
|
|||
}
|
||||
|
||||
// If this line does not have a trailing comment, align the stored comments.
|
||||
if (Tok.Children.empty() && Tok.Type != TT_LineComment)
|
||||
if (Tok.Children.empty() && !isTrailingComment(Tok))
|
||||
alignComments();
|
||||
storeReplacement(Tok.FormatTok,
|
||||
std::string(NewLines, '\n') + std::string(Spaces, ' '));
|
||||
|
@ -207,11 +211,6 @@ private:
|
|||
tooling::Replacements Replaces;
|
||||
};
|
||||
|
||||
static bool isTrailingComment(const AnnotatedToken &Tok) {
|
||||
return Tok.is(tok::comment) &&
|
||||
(Tok.Children.empty() || Tok.Children[0].MustBreakBefore);
|
||||
}
|
||||
|
||||
class UnwrappedLineFormatter {
|
||||
public:
|
||||
UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr,
|
||||
|
|
|
@ -1985,6 +1985,13 @@ TEST_F(FormatTest, BlockComments) {
|
|||
"bool aaaaaaaaaaaaa = /* trailing comment */\n"
|
||||
" aaaaaaaaaaaaaaaaaaaaaaaaaaa||aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
|
||||
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaa;"));
|
||||
EXPECT_EQ(
|
||||
"int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
|
||||
"int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
|
||||
"int cccccccccccccccccccccccccccccc; /* comment */\n",
|
||||
format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
|
||||
"int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
|
||||
"int cccccccccccccccccccccccccccccc; /* comment */\n"));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, BlockCommentsInMacros) {
|
||||
|
|
Loading…
Reference in New Issue