clang-format: Add support for a space after @property

Mozilla and WebKit seem to use a space after @property (verified by
grepping their codebases) so we turn this on there as well.

Change by Christian Legnitto. Thank you!

llvm-svn: 200320
This commit is contained in:
Daniel Jasper 2014-01-28 15:20:33 +00:00
parent b0930f5c04
commit e9beea24ef
4 changed files with 20 additions and 0 deletions

View File

@ -163,6 +163,10 @@ struct FormatStyle {
/// line.
bool AllowShortFunctionsOnASingleLine;
/// \brief Add a space after \c @property in Objective-C, i.e. use
/// <tt>@property (readonly)</tt> instead of <tt>@property(readonly)</tt>.
bool ObjCSpaceAfterProperty;
/// \brief Add a space in front of an Objective-C protocol list, i.e. use
/// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>.
bool ObjCSpaceBeforeProtocolList;
@ -329,6 +333,7 @@ struct FormatStyle {
IndentWidth == R.IndentWidth && Language == R.Language &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
NamespaceIndentation == R.NamespaceIndentation &&
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
PenaltyBreakComment == R.PenaltyBreakComment &&
PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&

View File

@ -164,6 +164,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
IO.mapOptional("ObjCSpaceBeforeProtocolList",
Style.ObjCSpaceBeforeProtocolList);
IO.mapOptional("PenaltyBreakBeforeFirstCallParameter",
@ -267,6 +268,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.TabWidth = 8;
LLVMStyle.MaxEmptyLinesToKeep = 1;
LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
LLVMStyle.ObjCSpaceAfterProperty = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.PointerBindsToType = false;
LLVMStyle.SpacesBeforeTrailingComments = 1;
@ -305,6 +307,7 @@ FormatStyle getGoogleStyle() {
GoogleStyle.DerivePointerBinding = true;
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.IndentFunctionDeclarationAfterType = true;
GoogleStyle.ObjCSpaceAfterProperty = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.PointerBindsToType = true;
GoogleStyle.SpacesBeforeTrailingComments = 2;
@ -349,6 +352,7 @@ FormatStyle getMozillaStyle() {
MozillaStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
MozillaStyle.DerivePointerBinding = true;
MozillaStyle.IndentCaseLabels = true;
MozillaStyle.ObjCSpaceAfterProperty = true;
MozillaStyle.ObjCSpaceBeforeProtocolList = false;
MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
MozillaStyle.PointerBindsToType = true;
@ -365,6 +369,7 @@ FormatStyle getWebKitStyle() {
Style.ColumnLimit = 0;
Style.IndentWidth = 4;
Style.NamespaceIndentation = FormatStyle::NI_Inner;
Style.ObjCSpaceAfterProperty = true;
Style.PointerBindsToType = true;
return Style;
}

View File

@ -1260,6 +1260,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
(Left.TokenText == "returns" || Left.TokenText == "option"))
return true;
}
if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
Left.Tok.getObjCKeywordID() == tok::objc_property)
return true;
if (Right.is(tok::hashhash))
return Left.is(tok::hash);
if (Left.isOneOf(tok::hashhash, tok::hash))

View File

@ -5872,6 +5872,12 @@ TEST_F(FormatTest, ObjCSnippets) {
verifyFormat("@property(assign, nonatomic) CGFloat hoverAlpha;");
verifyFormat("@property(assign, getter=isEditable) BOOL editable;");
verifyGoogleFormat("@property(assign, getter=isEditable) BOOL editable;");
verifyFormat("@property (assign, getter=isEditable) BOOL editable;",
getMozillaStyle());
verifyFormat("@property BOOL editable;", getMozillaStyle());
verifyFormat("@property (assign, getter=isEditable) BOOL editable;",
getWebKitStyle());
verifyFormat("@property BOOL editable;", getWebKitStyle());
verifyFormat("@import foo.bar;\n"
"@import baz;");
@ -7323,6 +7329,7 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
CHECK_PARSE_BOOL(DerivePointerBinding);
CHECK_PARSE_BOOL(IndentCaseLabels);
CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
CHECK_PARSE_BOOL(PointerBindsToType);
CHECK_PARSE_BOOL(Cpp11BracedListStyle);