[Objective-C migrator] replace candidate user setter/getter with
their equivalent property declaration. wip.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185873 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp
index 9af5303..05abbed 100644
--- a/lib/Edit/RewriteObjCFoundationAPI.cpp
+++ b/lib/Edit/RewriteObjCFoundationAPI.cpp
@@ -358,7 +358,33 @@
 bool edit::rewriteToObjCProperty(const ObjCMethodDecl *Getter,
                                  const ObjCMethodDecl *Setter,
                                  const NSAPI &NS, Commit &commit) {
-  return false;
+  std::string PropertyString = "@property";
+  const ParmVarDecl *argDecl = *Setter->param_begin();
+  QualType ArgType = argDecl->getType();
+  Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
+  if (propertyLifetime != Qualifiers::OCL_None) {
+    PropertyString += "(";
+    if (propertyLifetime == Qualifiers::OCL_Strong)
+      PropertyString += "strong";
+    else if (propertyLifetime == Qualifiers::OCL_Weak)
+      PropertyString += "weak";
+    else
+      PropertyString += "unsafe_unretained";
+    PropertyString += ")";
+  }
+  QualType PropQT = Getter->getResultType();
+  PropertyString += " ";
+  PropertyString += PropQT.getAsString(NS.getASTContext().getPrintingPolicy());
+  PropertyString += " ";
+  PropertyString += Getter->getNameAsString();
+  commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
+                                               Getter->getDeclaratorEndLoc()),
+                 PropertyString);
+  SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
+  // Get location past ';'
+  EndLoc = EndLoc.getLocWithOffset(1);
+  commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc));
+  return true;
 }
 
 /// \brief Returns true if the immediate message arguments of \c Msg should not