r195550 - clang-format: Fix bug in ObjC method declaration formatting.
Daniel Jasper
djasper at google.com
Sat Nov 23 06:27:27 PST 2013
Author: djasper
Date: Sat Nov 23 08:27:27 2013
New Revision: 195550
URL: http://llvm.org/viewvc/llvm-project?rev=195550&view=rev
Log:
clang-format: Fix bug in ObjC method declaration formatting.
Also disallow breaking between "@" and "{" or "[".
Before:
- (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
index:(NSUInteger)index
attributes:(NSDictionary *)attributes
nonDigitAttributes:(NSDictionary *)
nonDigitAttributes;
[mailComposeViewController
setToRecipients:@
[ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];
After:
- (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment
index:(NSUInteger)index
attributes:(NSDictionary *)attributes
nonDigitAttributes:
(NSDictionary *)nonDigitAttributes;
[mailComposeViewController
setToRecipients:
@[ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]];
This fixes llvm.org/PR18030.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=195550&r1=195549&r2=195550&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Nov 23 08:27:27 2013
@@ -1181,7 +1181,7 @@ unsigned TokenAnnotator::splitPenalty(co
if (Right.Type == TT_ObjCSelectorName)
return 0;
if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
- return 500;
+ return Line.MightBeFunctionDecl ? 50 : 500;
if (Left.is(tok::l_paren) && InFunctionDecl)
return 100;
@@ -1416,6 +1416,8 @@ bool TokenAnnotator::mustBreakBefore(con
bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
const FormatToken &Right) {
const FormatToken &Left = *Right.Previous;
+ if (Left.is(tok::at))
+ return false;
if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator))
return true;
if (Right.isTrailingComment())
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195550&r1=195549&r2=195550&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Nov 23 08:27:27 2013
@@ -5751,6 +5751,14 @@ TEST_F(FormatTest, ObjCArrayLiterals) {
" @\"aaaaaaaaaaaaaaaaa\",\n"
" @\"aaaaaaaaaaaaaaaaa\",\n"
"];");
+ verifyFormat(
+ "- (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment\n"
+ " index:(NSUInteger)index\n"
+ " nonDigitAttributes:\n"
+ " (NSDictionary *)noDigitAttributes;");
+ verifyFormat(
+ "[someFunction someLooooooooooooongParameter:\n"
+ " @[ NSBundle.mainBundle.infoDictionary[@\"a\"] ]];");
}
TEST_F(FormatTest, ReformatRegionAdjustsIndent) {
More information about the cfe-commits
mailing list