This is an attempt to format an objective-C method declaration using the new
clang formatter.
Please review.
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp (revision 169678)
+++ unittests/Format/FormatTest.cpp (working copy)
@@ -63,6 +63,11 @@
// Basic function tests.
//===----------------------------------------------------------------------===//
+TEST_F(FormatTest, FormatForObjectiveCMethods) {
+ EXPECT_EQ("- (NSUInteger) indexOfObject : (id) anObject;",
+ format("-(NSUInteger)indexOfObject:(id)anObject;"));
+}
+
TEST_F(FormatTest, DoesNotChangeCorrectlyFormatedCode) {
EXPECT_EQ(";", format(";"));
}
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp (revision 169678)
+++ lib/Format/Format.cpp (working copy)
@@ -38,7 +38,8 @@
TT_PointerOrReference,
TT_ConditionalExpr,
TT_LineComment,
- TT_BlockComment
+ TT_BlockComment,
+ TT_ObjectiveCMethodDecl
};
TokenType Type;
@@ -545,6 +546,9 @@
if (Line.Tokens[i].Tok.is(tok::colon)) {
Annotation.SpaceRequiredBefore =
Line.Tokens[0].Tok.isNot(tok::kw_case) && i != e - 1;
+ } else if (Annotations[i - 1].Type ==
+ TokenAnnotation::TT_ObjectiveCMethodDecl) {
+ Annotation.SpaceRequiredBefore = true;
} else if (Annotations[i - 1].Type == TokenAnnotation::TT_UnaryOperator)
{
Annotation.SpaceRequiredBefore = false;
} else if (Annotation.Type == TokenAnnotation::TT_UnaryOperator) {
@@ -603,6 +607,9 @@
if (Tok.Tok.is(tok::star) || Tok.Tok.is(tok::amp))
Annotation.Type = determineStarAmpUsage(i, AssignmentEncountered);
+ else if ((i == 0) &&
+ (Tok.Tok.is(tok::minus) || Tok.Tok.is(tok::plus)))
+ Annotation.Type = TokenAnnotation::TT_ObjectiveCMethodDecl;
else if (isUnaryOperator(i))
Annotation.Type = TokenAnnotation::TT_UnaryOperator;
else if (isBinaryOperator(Line.Tokens[i]))
- Thanks, Fariborz
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits