@@ -6105,6 +6105,35 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
61056105 return false ;
61066106 }
61076107
6108+ // We can break before an r_brace if there was a corresponding break after
6109+ // the l_brace, which is tracked by BreakBeforeClosingBrace, or if we are
6110+ // in a block indented initialization list.
6111+ if (Right.is (tok::r_brace)) {
6112+ return Right.MatchingParen && (Right.MatchingParen ->is (BK_Block) ||
6113+ (Right.isBlockIndentedInitRBrace (Style)));
6114+ }
6115+
6116+ // We only break before r_paren if we're in a block indented context.
6117+ if (Right.is (tok::r_paren)) {
6118+ if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
6119+ !Right.MatchingParen ) {
6120+ return false ;
6121+ }
6122+ auto Next = Right.Next ;
6123+ if (Next && Next->is (tok::r_paren))
6124+ Next = Next->Next ;
6125+ if (Next && Next->is (tok::l_paren))
6126+ return false ;
6127+ const FormatToken *Previous = Right.MatchingParen ->Previous ;
6128+ return !(Previous && (Previous->is (tok::kw_for) || Previous->isIf ()));
6129+ }
6130+
6131+ if (Left.isOneOf (tok::r_paren, TT_TrailingAnnotation) &&
6132+ Right.is (TT_TrailingAnnotation) &&
6133+ Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
6134+ return false ;
6135+ }
6136+
61086137 if (Left.is (tok::at))
61096138 return false ;
61106139 if (Left.Tok .getObjCKeywordID () == tok::objc_interface)
@@ -6260,34 +6289,6 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62606289 return false ;
62616290 }
62626291
6263- // We only break before r_brace if there was a corresponding break before
6264- // the l_brace, which is tracked by BreakBeforeClosingBrace.
6265- if (Right.is (tok::r_brace)) {
6266- return Right.MatchingParen && (Right.MatchingParen ->is (BK_Block) ||
6267- (Right.isBlockIndentedInitRBrace (Style)));
6268- }
6269-
6270- // We only break before r_paren if we're in a block indented context.
6271- if (Right.is (tok::r_paren)) {
6272- if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
6273- !Right.MatchingParen ) {
6274- return false ;
6275- }
6276- auto Next = Right.Next ;
6277- if (Next && Next->is (tok::r_paren))
6278- Next = Next->Next ;
6279- if (Next && Next->is (tok::l_paren))
6280- return false ;
6281- const FormatToken *Previous = Right.MatchingParen ->Previous ;
6282- return !(Previous && (Previous->is (tok::kw_for) || Previous->isIf ()));
6283- }
6284-
6285- if (Left.isOneOf (tok::r_paren, TT_TrailingAnnotation) &&
6286- Right.is (TT_TrailingAnnotation) &&
6287- Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
6288- return false ;
6289- }
6290-
62916292 // Allow breaking after a trailing annotation, e.g. after a method
62926293 // declaration.
62936294 if (Left.is (TT_TrailingAnnotation)) {
0 commit comments