From 3fa42e8f26195c62e1e7953b2ffee0aaa57cad51 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sat, 11 Oct 2014 08:24:56 +0000 Subject: [PATCH] clang-format: [ObjC] Wrap ObjC method declarations before annotations. Before: - (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id)x y:(id) y NS_DESIGNATED_INITIALIZER; After: - (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id)x y:(id)y NS_DESIGNATED_INITIALIZER; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219564 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 5 +++++ unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 4a964ed41d..1f8ac5ee10 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1432,6 +1432,11 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.Type == TT_TrailingAnnotation && (!Right.Next || Right.Next->isNot(tok::l_paren))) { + // Moving trailing annotations to the next line is fine for ObjC method + // declarations. + if (Line.First->Type == TT_ObjCMethodSpecifier) + + return 10; // Generally, breaking before a trailing annotation is bad unless it is // function-like. It seems to be especially preferable to keep standard // annotations (i.e. "const", "final" and "override") on the same line. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 4091cd5c10..758e504226 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6452,6 +6452,10 @@ TEST_F(FormatTest, FormatObjCMethodDeclarations) { " evenLongerKeyword:(float)theInterval\n" " error:(NSError **)theError {\n" "}"); + verifyFormat("- (instancetype)initXxxxxx:(id)x\n" + " y:(id)y\n" + " NS_DESIGNATED_INITIALIZER;", + getLLVMStyleWithColumns(60)); } TEST_F(FormatTest, FormatObjCMethodExpr) { -- 2.40.0