const NSAPI &NS, edit::Commit &commit) {
ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property";
- const ParmVarDecl *argDecl = *Setter->param_begin();
- QualType ArgType = Context.getCanonicalType(argDecl->getType());
- Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
- if (ArgType->isObjCRetainableType() &&
- propertyLifetime == Qualifiers::OCL_Strong) {
- if (const ObjCObjectPointerType *ObjPtrTy =
- ArgType->getAs<ObjCObjectPointerType>()) {
- ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
- if (IDecl &&
- IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
- PropertyString += "(copy)";
- }
- }
- else if (propertyLifetime == Qualifiers::OCL_Weak)
- // TODO. More precise determination of 'weak' attribute requires
- // looking into setter's implementation for backing weak ivar.
- PropertyString += "(weak)";
- else
+ std::string PropertyNameString = Getter->getNameAsString();
+ StringRef PropertyName(PropertyNameString);
+ // Short circuit properties that contain the name "delegate" or "dataSource",
+ // or have exact name "target" to have unsafe_unretained attribute.
+ if (PropertyName.equals("target") ||
+ (PropertyName.find("delegate") != StringRef::npos) ||
+ (PropertyName.find("dataSource") != StringRef::npos))
PropertyString += "(unsafe_unretained)";
+ else {
+ const ParmVarDecl *argDecl = *Setter->param_begin();
+ QualType ArgType = Context.getCanonicalType(argDecl->getType());
+ Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
+ bool RetainableObject = ArgType->isObjCRetainableType();
+ if (RetainableObject && propertyLifetime == Qualifiers::OCL_Strong) {
+ if (const ObjCObjectPointerType *ObjPtrTy =
+ ArgType->getAs<ObjCObjectPointerType>()) {
+ ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
+ if (IDecl &&
+ IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
+ PropertyString += "(copy)";
+ else
+ PropertyString += "(retain)";
+ }
+ } else if (propertyLifetime == Qualifiers::OCL_Weak)
+ // TODO. More precise determination of 'weak' attribute requires
+ // looking into setter's implementation for backing weak ivar.
+ PropertyString += "(weak)";
+ else if (RetainableObject)
+ PropertyString += "(retain)";
+ }
// strip off any ARC lifetime qualifier.
QualType CanResultTy = Context.getCanonicalType(Getter->getResultType());
PropertyString += " ";
PropertyString += CanResultTy.getAsString(Context.getPrintingPolicy());
PropertyString += " ";
- PropertyString += Getter->getNameAsString();
+ PropertyString += PropertyNameString;
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
Getter->getDeclaratorEndLoc()),
PropertyString);
@property(weak) NSString * WeakProp;
-@property NSString * StrongProp;
+@property(retain) NSString * StrongProp;
- (NSString *) UnavailProp __attribute__((unavailable));
-@property NSArray * names2;
-@property NSArray * names3;
-@property NSArray * names4;
-@property NSArray * names1;
+@property(retain) NSArray * names2;
+@property(retain) NSArray * names3;
+@property(retain) NSArray * names4;
+@property(retain) NSArray * names1;
+@end
+
+// Properties that contain the name "delegate" or "dataSource",
+// or have exact name "target" have unsafe_unretained attribute.
+@interface NSInvocation
+@property(unsafe_unretained) id target;
+
+
+@property(unsafe_unretained) id dataSource;
+
+@property(unsafe_unretained) id xxxdelegateYYY;
+
+
+
+
+@property(retain) id MYtarget;
+
+
+@property(retain) id targetX;
+
+
+@property int value;
+
@end