[refactor][selection] canonicalize member expr callee to the full
member call expression

We would like to extract the full call when just the callee is selected.

llvm-svn: 318205
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
index 4f1168b..ae8a3cb 100644
--- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp
+++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp
@@ -115,6 +115,11 @@
       return true;
     if (auto *Opaque = dyn_cast<OpaqueValueExpr>(S))
       return TraverseOpaqueValueExpr(Opaque);
+    // Avoid selecting implicit 'this' expressions.
+    if (auto *TE = dyn_cast<CXXThisExpr>(S)) {
+      if (TE->isImplicit())
+        return true;
+    }
     // FIXME (Alex Lorenz): Improve handling for macro locations.
     SourceSelectionKind SelectionKind =
         selectionKindFor(CharSourceRange::getTokenRange(S->getSourceRange()));
@@ -268,9 +273,15 @@
   //      ~~~~~~             ~~~~~~~
   if (isa<StringLiteral>(S) && isa<ObjCStringLiteral>(Parent))
     Node = Parents.pop_back_val();
+  // The entire call should be selected when just the member expression
+  // that refers to the method is selected.
+  //    f.call(args)  becomes  f.call(args)
+  //      ~~~~                 ~~~~~~~~~~~~
+  else if (isa<MemberExpr>(S) && isa<CXXMemberCallExpr>(Parent) &&
+           cast<CXXMemberCallExpr>(Parent)->getCallee() == S)
+    Node = Parents.pop_back_val();
   // FIXME: Syntactic form -> Entire pseudo-object expr.
   // FIXME: Callee -> Call.
-  // FIXME: Callee member expr -> Call.
 }
 
 /// Finds the set of bottom-most selected AST nodes that are in the selection