]> granicus.if.org Git - clang/commitdiff
ObjectiveC migration: Method candidates for
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 24 Jul 2013 18:31:42 +0000 (18:31 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 24 Jul 2013 18:31:42 +0000 (18:31 +0000)
migrating to instancetype can have implicit 'id'
type too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187062 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-instancetype.m
test/ARCMT/objcmt-instancetype.m.result

index 5d5383002283f49dd094efa45d3931e1bc71cd70..bd6e97c781bee13c72906ab49c1022f3360bdfb6 100644 (file)
@@ -585,11 +585,19 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
            !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSDictionary")))
     return;
   
-  TypeSourceInfo *TSInfo =  OM->getResultTypeSourceInfo();
-  TypeLoc TL = TSInfo->getTypeLoc();
-  SourceRange R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
+  SourceRange R;
+  std::string ClassString;
+  if (TypeSourceInfo *TSInfo =  OM->getResultTypeSourceInfo()) {
+    TypeLoc TL = TSInfo->getTypeLoc();
+    R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
+    ClassString = "instancetype";
+  }
+  else {
+    R = SourceRange(OM->getLocStart(), OM->getLocStart());
+    ClassString = OM->isInstanceMethod() ? '-' : '+';
+    ClassString += " (instancetype)";
+  }
   edit::Commit commit(*Editor);
-  std::string ClassString = "instancetype";
   commit.replace(R, ClassString);
   Editor->commit(commit);
 }
index 5e4f886893a375af36cf6057a0226f679023b28c..32f84d52dbfa5371eeb744a43dc1eae3939b9806 100644 (file)
@@ -25,7 +25,7 @@ typedef signed char BOOL;
 + (id)arrayWithObject:(id)anObject;
 + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
 + (id)arrayWithObjects:(id)firstObj, ...;
-+ (id)arrayWithArray:(NSArray *)array;
++ arrayWithArray:(NSArray *)array;
 
 - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
 - (id)initWithObjects:(id)firstObj, ...;
@@ -47,7 +47,7 @@ typedef signed char BOOL;
 + (id)dictionary;
 + (id)dictionaryWithObject:(id)object forKey:(id)key;
 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
-+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
++ dictionaryWithObjectsAndKeys:(id)firstObject, ...;
 + (id)dictionaryWithDictionary:(NSDictionary *)dict;
 + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
 
index 3b3ee8bcc69de6ff64ad872e2559cde12b4222d7..af06e67e2adff995ce9ca18d0307a43bebd71888 100644 (file)
@@ -25,7 +25,7 @@ typedef signed char BOOL;
 + (instancetype)arrayWithObject:(id)anObject;
 + (instancetype)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
 + (instancetype)arrayWithObjects:(id)firstObj, ...;
-+ (instancetype)arrayWithArray:(NSArray *)array;
++ (instancetype) arrayWithArray:(NSArray *)array;
 
 - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
 - (id)initWithObjects:(id)firstObj, ...;
@@ -47,7 +47,7 @@ typedef signed char BOOL;
 + (instancetype)dictionary;
 + (instancetype)dictionaryWithObject:(id)object forKey:(id)key;
 + (instancetype)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
-+ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
++ (instancetype) dictionaryWithObjectsAndKeys:(id)firstObject, ...;
 + (instancetype)dictionaryWithDictionary:(NSDictionary *)dict;
 + (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;