Skip to content

Commit 6de2205

Browse files
sstwcwaokblast
authored andcommitted
[clang-format] Break the line within ObjC @selector (llvm#164674)
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
1 parent aa3760b commit 6de2205

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,8 +4407,12 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
44074407
// breaking after it.
44084408
if (Right.is(TT_SelectorName))
44094409
return 0;
4410-
if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
4411-
return Line.MightBeFunctionDecl ? 50 : 500;
4410+
if (Left.is(tok::colon)) {
4411+
if (Left.is(TT_ObjCMethodExpr))
4412+
return Line.MightBeFunctionDecl ? 50 : 500;
4413+
if (Left.is(TT_ObjCSelector))
4414+
return 500;
4415+
}
44124416

44134417
// In Objective-C type declarations, avoid breaking after the category's
44144418
// open paren (we'll prefer breaking after the protocol list's opening
@@ -6291,7 +6295,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62916295
TT_BitFieldColon)) {
62926296
return false;
62936297
}
6294-
if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
6298+
if (Left.is(tok::colon) && Left.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr))
6299+
return true;
6300+
if (Left.is(tok::colon) && Left.is(TT_DictLiteral)) {
62956301
if (Style.isProto()) {
62966302
if (!Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral())
62976303
return false;

clang/unittests/Format/FormatTestObjC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,12 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
949949
"[aaaaaaaaaaaaaaaaaaaaaaaaa\n"
950950
" aaaaaaaaaaaaaaaaa:aaaaaaaa\n"
951951
" aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];");
952+
verifyFormat("[objectName\n"
953+
" respondsToSelector:\n"
954+
" @selector(\n"
955+
" somelonglonglonglongnameeeeeeee:\n"
956+
" loooooooooanotherlonglonglonglongnametopush:\n"
957+
" otherlongnameforlimit:)];");
952958

953959
Style = getChromiumStyle(FormatStyle::LK_ObjC);
954960
Style.ColumnLimit = 80;

0 commit comments

Comments
 (0)