aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-01-10 21:30:42 +0000
committerNico Weber <nicolasweber@gmx.de>2013-01-10 21:30:42 +0000
commit7084823f8ec4367019940b26245e01684b62c7e1 (patch)
tree77181246daae0f425cc9b16e953dee250816c587
parentb1fc673783dd0215a1426b2c411779cd05a16a07 (diff)
Formatter: No spaces around '=' in @property lines.
Before: @property(assign, getter = isEditable) BOOL editable; Now: @property(assign, getter=isEditable) BOOL editable; It'd be nice if some Apple person could let me know if spaces are preferred around '=' in @synthesize lines (see FIXME in the test). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172110 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/Format.cpp13
-rw-r--r--unittests/Format/FormatTest.cpp9
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index d721536c76..f84d3c5bc7 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -39,6 +39,7 @@ enum TokenType {
TT_ObjCBlockLParen,
TT_ObjCDecl,
TT_ObjCMethodSpecifier,
+ TT_ObjCProperty,
TT_OverloadedOperator,
TT_PointerOrReference,
TT_PureVirtualSpecifier,
@@ -55,7 +56,8 @@ enum LineType {
LT_PreprocessorDirective,
LT_VirtualFunctionDecl,
LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
- LT_ObjCMethodDecl
+ LT_ObjCMethodDecl,
+ LT_ObjCProperty // An @property line.
};
class AnnotatedToken {
@@ -841,6 +843,8 @@ public:
CurrentLineType = LT_ObjCMethodDecl;
else if (RootToken.Type == TT_ObjCDecl)
CurrentLineType = LT_ObjCDecl;
+ else if (RootToken.Type == TT_ObjCProperty)
+ CurrentLineType = LT_ObjCProperty;
if (!RootToken.Children.empty())
calculateExtraInformation(RootToken.Children[0]);
@@ -891,6 +895,10 @@ private:
case tok::objc_implementation:
case tok::objc_protocol:
Current.Type = TT_ObjCDecl;
+ break;
+ case tok::objc_property:
+ Current.Type = TT_ObjCProperty;
+ break;
default:
break;
}
@@ -1044,6 +1052,9 @@ private:
// Don't space between ':' and '('
return false;
}
+ if (CurrentLineType == LT_ObjCProperty &&
+ (Tok.is(tok::equal) || Tok.Parent->is(tok::equal)))
+ return false;
if (Tok.Type == TT_CtorInitializerColon || Tok.Type == TT_ObjCBlockLParen)
return true;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 5844853e05..deb668d984 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1430,7 +1430,6 @@ TEST_F(FormatTest, ObjCAt) {
verifyFormat("@[");
verifyFormat("@{");
-
EXPECT_EQ("@interface", format("@ interface"));
// The precise formatting of this doesn't matter, nobody writes code like
@@ -1452,10 +1451,16 @@ TEST_F(FormatTest, ObjCSnippets) {
verifyFormat("@synchronized(self) {\n"
" f();\n"
"}");
+
+ // FIXME: Some Apple code examples don't have spaces around '=' for
+ // @synthesize, decide if that's desired or not in LLVM style. Google style
+ // definitely wants spaces.
verifyFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
+ verifyGoogleFormat("@synthesize dropArrowPosition = dropArrowPosition_;");
- // FIXME: "getter=bar" should not be surround by spaces in @property.
verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
+ verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
+ verifyGoogleFormat("@property(assign, getter=isEditable) BOOL editable;");
}
} // end namespace tooling