void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM);
void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM);
+ ObjCMethodDecl *OM,
+ ObjCInstanceTypeFamily OIT_Family = OIT_None);
public:
std::string MigrateDir;
ObjCMethodDecl *OM) {
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
- if (OIT_Family == OIT_None) {
- migrateFactoryMethod(Ctx, CDecl, OM);
- return;
- }
+
std::string ClassName;
switch (OIT_Family) {
+ case OIT_None:
+ migrateFactoryMethod(Ctx, CDecl, OM);
+ return;
case OIT_Array:
ClassName = "NSArray";
break;
case OIT_MemManage:
ClassName = "NSObject";
break;
- default:
+ case OIT_Singleton:
+ migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton);
return;
}
if (!OM->getResultType()->isObjCIdType())
void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
- ObjCMethodDecl *OM) {
+ ObjCMethodDecl *OM,
+ ObjCInstanceTypeFamily OIT_Family) {
if (OM->isInstanceMethod() || !OM->getResultType()->isObjCIdType())
return;
IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0);
std::string MethodName = MethodIdName->getName();
+ if (OIT_Family == OIT_Singleton) {
+ StringRef STRefMethodName(MethodName);
+ size_t len = 0;
+ if (STRefMethodName.startswith("standard"))
+ len = strlen("standard");
+ else if (STRefMethodName.startswith("shared"))
+ len = strlen("shared");
+ else if (STRefMethodName.startswith("default"))
+ len = strlen("default");
+ else
+ return;
+ MethodName = STRefMethodName.substr(len);
+ }
std::string MethodNameSubStr = MethodName.substr(0, 3);
StringRef MethodNamePrefix(MethodNameSubStr);
std::string StringLoweredMethodNamePrefix = MethodNamePrefix.lower();
break;
case 'd':
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
+ if (startsWithWord(name, "default")) return OIT_Singleton;
break;
case 'i':
if (startsWithWord(name, "init")) return OIT_MemManage;
case 'r':
if (startsWithWord(name, "retain")) return OIT_MemManage;
break;
+ case 's':
+ if (startsWithWord(name, "shared") ||
+ startsWithWord(name, "standard"))
+ return OIT_Singleton;
default:
break;
}
+ (id)dateWithYear:(NSInteger)year month:(NSUInteger)month day:(NSUInteger)day hour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second timeZone:(NSTimeZone *)aTimeZone __attribute__((availability(macosx,introduced=10.4)));
@end
+@interface NSUserDefaults
++ (id) standardUserDefaults;
+@end
+
+@interface NSNotificationCenter
++ (id) defaultCenter;
+@end
+
+@interface UIApplication
++ (id)sharedApplication;
+@end
+ (instancetype)dateWithYear:(NSInteger)year month:(NSUInteger)month day:(NSUInteger)day hour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second timeZone:(NSTimeZone *)aTimeZone __attribute__((availability(macosx,introduced=10.4)));
@end
+@interface NSUserDefaults
++ (instancetype) standardUserDefaults;
+@end
+
+@interface NSNotificationCenter
++ (instancetype) defaultCenter;
+@end
+
+@interface UIApplication
++ (instancetype)sharedApplication;
+@end