@@ -6110,6 +6110,35 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
61106110 return false ;
61116111 }
61126112
6113+ // We can break before an r_brace if there was a break after the matching
6114+ // l_brace, which is tracked by BreakBeforeClosingBrace, or if we are in a
6115+ // block-indented initialization list.
6116+ if (Right.is (tok::r_brace)) {
6117+ return Right.MatchingParen && (Right.MatchingParen ->is (BK_Block) ||
6118+ (Right.isBlockIndentedInitRBrace (Style)));
6119+ }
6120+
6121+ // We only break before r_paren if we're in a block indented context.
6122+ if (Right.is (tok::r_paren)) {
6123+ if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
6124+ !Right.MatchingParen ) {
6125+ return false ;
6126+ }
6127+ auto Next = Right.Next ;
6128+ if (Next && Next->is (tok::r_paren))
6129+ Next = Next->Next ;
6130+ if (Next && Next->is (tok::l_paren))
6131+ return false ;
6132+ const FormatToken *Previous = Right.MatchingParen ->Previous ;
6133+ return !(Previous && (Previous->is (tok::kw_for) || Previous->isIf ()));
6134+ }
6135+
6136+ if (Left.isOneOf (tok::r_paren, TT_TrailingAnnotation) &&
6137+ Right.is (TT_TrailingAnnotation) &&
6138+ Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
6139+ return false ;
6140+ }
6141+
61136142 if (Left.is (tok::at))
61146143 return false ;
61156144 if (Left.Tok .getObjCKeywordID () == tok::objc_interface)
@@ -6265,34 +6294,6 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62656294 return false ;
62666295 }
62676296
6268- // We only break before r_brace if there was a corresponding break before
6269- // the l_brace, which is tracked by BreakBeforeClosingBrace.
6270- if (Right.is (tok::r_brace)) {
6271- return Right.MatchingParen && (Right.MatchingParen ->is (BK_Block) ||
6272- (Right.isBlockIndentedInitRBrace (Style)));
6273- }
6274-
6275- // We only break before r_paren if we're in a block indented context.
6276- if (Right.is (tok::r_paren)) {
6277- if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
6278- !Right.MatchingParen ) {
6279- return false ;
6280- }
6281- auto Next = Right.Next ;
6282- if (Next && Next->is (tok::r_paren))
6283- Next = Next->Next ;
6284- if (Next && Next->is (tok::l_paren))
6285- return false ;
6286- const FormatToken *Previous = Right.MatchingParen ->Previous ;
6287- return !(Previous && (Previous->is (tok::kw_for) || Previous->isIf ()));
6288- }
6289-
6290- if (Left.isOneOf (tok::r_paren, TT_TrailingAnnotation) &&
6291- Right.is (TT_TrailingAnnotation) &&
6292- Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
6293- return false ;
6294- }
6295-
62966297 // Allow breaking after a trailing annotation, e.g. after a method
62976298 // declaration.
62986299 if (Left.is (TT_TrailingAnnotation)) {
0 commit comments