[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 5 02:39:00 PST 2024


================
@@ -569,8 +571,43 @@ renameWithinFile(ParsedAST &AST, const NamedDecl &RenameDecl,
     //   }
     if (!isInsideMainFile(RenameLoc, SM))
       continue;
+    Locs.push_back(RenameLoc);
+  }
+  if (const auto *MD = dyn_cast<ObjCMethodDecl>(&RenameDecl)) {
+    auto Code = SM.getBufferData(SM.getMainFileID());
+    auto RenameIdentifier = MD->getSelector().getNameForSlot(0).str();
+    llvm::SmallVector<llvm::StringRef, 8> NewNames;
+    NewName.split(NewNames, ":");
+    if (NewNames.empty())
+      NewNames.push_back(NewName);
+    std::vector<Range> Ranges;
+    const auto &LangOpts = RenameDecl.getASTContext().getLangOpts();
+    for (const auto &Loc : Locs)
+      Ranges.push_back(tokenRangeForLoc(Loc, SM, LangOpts));
----------------
kadircet wrote:

instead of re-lexing, you can use tokenbuffer inside AST and call `spelledTokenAt`, then convert it into a range

https://github.com/llvm/llvm-project/pull/76466


More information about the cfe-commits mailing list