[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl
This revision was automatically updated to reflect the committed changes. Closed by commit rL328174: [clang-format] Dont 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 +if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new)) + // Don't space between ')' and 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)initXx:(id)x\n" " y:(id)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"); 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 +if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new)) + // Don't space between ')' and 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)initXx:(id)x\n" " y:(id)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"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl
djasper accepted this revision. djasper added a comment. Looks good. Repository: rC Clang https://reviews.llvm.org/D44692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl
stephanemoore accepted this revision. stephanemoore added a comment. This revision is now accepted and ready to land. Makes sense to me. Repository: rC Clang https://reviews.llvm.org/D44692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44692: [clang-format] Don't insert space between r_paren and 'new' in ObjC decl
benhamilton created this revision. benhamilton added reviewers: djasper, jolesiak. Herald added subscribers: cfe-commits, klimek. Previously, clang-format would insert a space between the closing parenthesis and 'new' in the following valid Objective-C declaration: + (instancetype)new; This was because 'new' is treated as a keyword, not an identifier. TokenAnnotator::spaceRequiredBefore() already handled the case where r_paren came before an identifier, so this diff extends it to handle r_paren before 'new'. Test Plan: New tests added. Ran tests with: % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests Repository: rC Clang https://reviews.llvm.org/D44692 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestObjC.cpp Index: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ 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)initXx:(id)x\n" " y:(id)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"); Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ 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 +if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new)) + // Don't space between ')' and 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: unittests/Format/FormatTestObjC.cpp === --- unittests/Format/FormatTestObjC.cpp +++ 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)initXx:(id)x\n" " y:(id)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"); Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ 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 +if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new)) + // Don't space between ')' and 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 && ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits