AnnotatedLine &Line = **I;
// Don't merge ObjC @ keywords and methods.
+ // FIXME: If an option to allow short exception handling clauses on a single
+ // line is added, change this to not return for @try and friends.
if (Style.Language != FormatStyle::LK_Java &&
Line.First->isOneOf(tok::at, tok::minus, tok::plus))
return 0;
nextToken();
addUnwrappedLine();
return;
+ case tok::objc_try:
+ // This branch isn't strictly necessary (the kw_try case below would
+ // do this too after the tok::at is parsed above). But be explicit.
+ parseTryCatch();
+ return;
default:
break;
}
parseStructuralElement();
--Line->Level;
}
- while (FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except,
- tok::kw___finally) ||
- ((Style.Language == FormatStyle::LK_Java ||
- Style.Language == FormatStyle::LK_JavaScript) &&
- FormatTok->is(Keywords.kw_finally))) {
+ while (1) {
+ if (FormatTok->is(tok::at))
+ nextToken();
+ if (!(FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except,
+ tok::kw___finally) ||
+ ((Style.Language == FormatStyle::LK_Java ||
+ Style.Language == FormatStyle::LK_JavaScript) &&
+ FormatTok->is(Keywords.kw_finally)) ||
+ (FormatTok->Tok.isObjCAtKeyword(tok::objc_catch) ||
+ FormatTok->Tok.isObjCAtKeyword(tok::objc_finally))))
+ break;
nextToken();
while (FormatTok->isNot(tok::l_brace)) {
if (FormatTok->is(tok::l_paren)) {
" // something\n"
"}",
Style);
+ verifyFormat("@try {\n"
+ " // something\n"
+ "}\n"
+ "@finally {\n"
+ " // something\n"
+ "}",
+ Style);
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
verifyFormat("try\n"
"{\n"
TEST_F(FormatTest, FormatObjCTryCatch) {
verifyFormat("@try {\n"
" f();\n"
- "}\n"
- "@catch (NSException e) {\n"
+ "} @catch (NSException e) {\n"
" @throw;\n"
- "}\n"
- "@finally {\n"
+ "} @finally {\n"
" exit(42);\n"
"}");
+ verifyFormat("DEBUG({\n"
+ " @try {\n"
+ " } @finally {\n"
+ " }\n"
+ "});\n");
}
TEST_F(FormatTest, StaticInitializers) {