[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 21 20:26:39 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328174: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D44692
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
@@ -2615,8 +2615,10 @@
if (Line.Type == LT_ObjCMethodDecl) {
if (Left.is(TT_ObjCMethodSpecifier))
return true;
- if (Left.is(tok::r_paren) && Right.is(tok::identifier))
- // Don't space between ')' and <id>
+ if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new))
+ // Don't space between ')' and <id> or ')' and 'new'. 'new' is not a
+ // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
+ // method declaration.
return false;
}
if (Line.Type == LT_ObjCProperty &&
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -514,6 +514,7 @@
" evenLongerKeyword:(float)theInterval\n"
" error:(NSError **)theError {\n"
"}");
+ verifyFormat("+ (instancetype)new;\n");
Style.ColumnLimit = 60;
verifyFormat("- (instancetype)initXxxxxx:(id<x>)x\n"
" y:(id<yyyyyyyyyyyyyyyyyyyy>)y\n"
@@ -914,6 +915,17 @@
" }]) {\n}");
}
+TEST_F(FormatTestObjC, ObjCNew) {
+ verifyFormat("+ (instancetype)new {\n"
+ " return nil;\n"
+ "}\n");
+ verifyFormat("+ (instancetype)myNew {\n"
+ " return [self new];\n"
+ "}\n");
+ verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
+ verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+}
+
TEST_F(FormatTestObjC, ObjCLiterals) {
verifyFormat("@\"String\"");
verifyFormat("@1");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44692.139409.patch
Type: text/x-patch
Size: 1898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180322/cbd41bc0/attachment.bin>
More information about the cfe-commits
mailing list