[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:38:56 PST 2024


================
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
     return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast<ObjCMethodDecl>(&ND))
+    StrName = MD->getSelector().getNameForSlot(0).str();
----------------
kadircet wrote:

nit: we can rewrite as:
```
auto TokSpelling = clang::Lexer::getSpelling(Tok, SM, LO);
if (const auto *MD = dyn_cast<ObjCMethodDecl>(&ND))
  return TokSpelling == MD->getSelector().getNameForSlot(0);
return TokSpelling == Name.getAsString();
```

(to prevent a string construction)

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


More information about the cfe-commits mailing list