return true;
if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
return true;
+ if (Style.Language == FormatStyle::LK_ObjC &&
+ Current.ObjCSelectorNameParts > 1 &&
+ Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
+ return true;
+ }
if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
Style.isCpp() &&
/// e.g. because several of them are block-type.
unsigned LongestObjCSelectorName = 0;
+ /// \brief How many parts ObjC selector have (i.e. how many parameters method
+ /// has).
+ unsigned ObjCSelectorNameParts = 0;
+
/// \brief Stores the number of required fake parentheses and the
/// corresponding operator precedence.
///
if (Contexts.back().FirstObjCSelectorName) {
Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
Contexts.back().LongestObjCSelectorName;
+ Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts =
+ Left->ParameterCount;
if (Left->BlockParameterCount > 1)
Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = 0;
}
TT_DesignatedInitializerLSquare)) {
Left->Type = TT_ObjCMethodExpr;
StartsObjCMethodExpr = true;
+ // ParameterCount might have been set to 1 before expression was
+ // recognized as ObjCMethodExpr (as '1 + number of commas' formula is
+ // used for other expression types). Parameter counter has to be,
+ // therefore, reset to 0.
+ Left->ParameterCount = 0;
Contexts.back().ColonIsObjCMethodExpr = true;
if (Parent && Parent->is(tok::r_paren))
Parent->Type = TT_CastRParen;
void updateParameterCount(FormatToken *Left, FormatToken *Current) {
if (Current->is(tok::l_brace) && Current->BlockKind == BK_Block)
++Left->BlockParameterCount;
- if (Current->is(tok::comma)) {
+ if (Left->Type == TT_ObjCMethodExpr) {
+ if (Current->is(tok::colon))
+ ++Left->ParameterCount;
+ } else if (Current->is(tok::comma)) {
++Left->ParameterCount;
if (!Left->Role)
Left->Role.reset(new CommaSeparatedList(Style));
" ofSize:aa:bbb\n"
" atOrigin:cc:dd];");
+ // Inline block as a first argument.
+ verifyFormat("[object justBlock:^{\n"
+ " a = 42;\n"
+ "}];");
+ verifyFormat("[object\n"
+ " justBlock:^{\n"
+ " a = 42;\n"
+ " }\n"
+ " notBlock:42\n"
+ " a:42];");
+ verifyFormat("[object\n"
+ " firstBlock:^{\n"
+ " a = 42;\n"
+ " }\n"
+ " blockWithLongerName:^{\n"
+ " a = 42;\n"
+ " }];");
+ verifyFormat("[object\n"
+ " blockWithLongerName:^{\n"
+ " a = 42;\n"
+ " }\n"
+ " secondBlock:^{\n"
+ " a = 42;\n"
+ " }];");
+ verifyFormat("[object\n"
+ " firstBlock:^{\n"
+ " a = 42;\n"
+ " }\n"
+ " notBlock:42\n"
+ " secondBlock:^{\n"
+ " a = 42;\n"
+ " }];");
+
Style.ColumnLimit = 70;
verifyFormat(
"void f() {\n"