Skip to content

Commit

Permalink
Add support for ObjC property name to be a single acronym.
Browse files Browse the repository at this point in the history
Summary:
This change will support cases like:

```
@Property(assign, nonatomic) int ID;
```

Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D46374

llvm-svn: 331545
  • Loading branch information
ynzhang0509 committed May 4, 2018
1 parent bf4c41c commit 4f9ead2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
assert(MatchedDecl->getName().size() > 0);
auto *DeclContext = MatchedDecl->getDeclContext();
auto *CategoryDecl = llvm::dyn_cast<ObjCCategoryDecl>(DeclContext);

auto AcronymsRegex =
llvm::Regex("^" + AcronymsGroupRegex(EscapedAcronyms) + "$");
if (AcronymsRegex.match(MatchedDecl->getName())) {
return;
}
if (CategoryDecl != nullptr &&
hasCategoryPropertyPrefix(MatchedDecl->getName())) {
if (!prefixedPropertyNameValid(MatchedDecl->getName(), EscapedAcronyms) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ @interface Foo
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
@property(assign, nonatomic) int GIFIgnoreStandardAcronym;
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'GIFIgnoreStandardAcronym' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
@property(strong, nonatomic) NSString *TGIF;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ @interface Foo
@property(assign, nonatomic) int enable2GBackgroundFetch;
@property(assign, nonatomic) int shouldUseCFPreferences;
@property(assign, nonatomic) int enableGLAcceleration;
@property(assign, nonatomic) int ID;
@end

@interface Foo (Bar)
Expand Down

0 comments on commit 4f9ead2

Please sign in to comment.