[PATCH] D45526: [clang-format] Do not break after ObjC category open paren
This revision was automatically updated to reflect the committed changes. Closed by commit rL329919: [clang-format] Do not break after ObjC category open paren (authored by benhamilton, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D45526 Files: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestObjC.cpp Index: cfe/trunk/lib/Format/TokenAnnotator.cpp === --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2272,6 +2272,13 @@ if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) return Line.MightBeFunctionDecl ? 50 : 500; + // In Objective-C type declarations, avoid breaking after the category's + // open paren (we'll prefer breaking after the protocol list's opening + // angle bracket, if present). + if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && + Left.Previous->isOneOf(tok::identifier, tok::greater)) +return 500; + if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) return 100; Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp === --- cfe/trunk/unittests/Format/FormatTestObjC.cpp +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp @@ -334,6 +334,9 @@ "c, c,\n" "c, c> {\n" "}"); + verifyFormat("@interface c (ccc) <\n" + "c> {\n" + "}"); Style.ObjCBinPackProtocolList = FormatStyle::BPS_Never; verifyFormat("@interface d () <\n" "d,\n" Index: cfe/trunk/lib/Format/TokenAnnotator.cpp === --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2272,6 +2272,13 @@ if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) return Line.MightBeFunctionDecl ? 50 : 500; + // In Objective-C type declarations, avoid breaking after the category's + // open paren (we'll prefer breaking after the protocol list's opening + // angle bracket, if present). + if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && + Left.Previous->isOneOf(tok::identifier, tok::greater)) +return 500; + if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) return 100; Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp === --- cfe/trunk/unittests/Format/FormatTestObjC.cpp +++ cfe/trunk/unittests/Format/FormatTestObjC.cpp @@ -334,6 +334,9 @@ "c, c,\n" "c, c> {\n" "}"); + verifyFormat("@interface c (ccc) <\n" + "c> {\n" + "}"); Style.ObjCBinPackProtocolList = FormatStyle::BPS_Never; verifyFormat("@interface d () <\n" "d,\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45526: [clang-format] Do not break after ObjC category open paren
benhamilton added inline comments. Comment at: lib/Format/TokenAnnotator.cpp:2276 + // In Objective-C type declarations, prefer breaking after the category's + // close paren instead of after the open paren. + if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && djasper wrote: > This is still using the old wording. Fixed, thanks. Repository: rC Clang https://reviews.llvm.org/D45526 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45526: [clang-format] Do not break after ObjC category open paren
benhamilton updated this revision to Diff 142182. benhamilton marked an inline comment as done. benhamilton added a comment. - Update comment. Repository: rC Clang https://reviews.llvm.org/D45526 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestObjC.cpp Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -334,6 +334,9 @@ "c, c,\n" "c, c> {\n" "}"); + verifyFormat("@interface c (ccc) <\n" + "c> {\n" + "}"); Style.ObjCBinPackProtocolList = FormatStyle::BPS_Never; verifyFormat("@interface d () <\n" "d,\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2272,6 +2272,13 @@ if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) return Line.MightBeFunctionDecl ? 50 : 500; + // In Objective-C type declarations, avoid breaking after the category's + // open paren (we'll prefer breaking after the protocol list's opening + // angle bracket, if present). + if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && + Left.Previous->isOneOf(tok::identifier, tok::greater)) +return 500; + if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) return 100; Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -334,6 +334,9 @@ "c, c,\n" "c, c> {\n" "}"); + verifyFormat("@interface c (ccc) <\n" + "c> {\n" + "}"); Style.ObjCBinPackProtocolList = FormatStyle::BPS_Never; verifyFormat("@interface d () <\n" "d,\n" Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2272,6 +2272,13 @@ if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) return Line.MightBeFunctionDecl ? 50 : 500; + // In Objective-C type declarations, avoid breaking after the category's + // open paren (we'll prefer breaking after the protocol list's opening + // angle bracket, if present). + if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous && + Left.Previous->isOneOf(tok::identifier, tok::greater)) +return 500; + if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) return 100; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits