[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)
Alex Hoppen via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 16:12:29 PST 2024
================
@@ -538,11 +564,222 @@ std::optional<InvalidName> checkName(const NamedDecl &RenameDecl,
Conflict->getLocation().printToString(ASTCtx.getSourceManager())};
}
}
- if (Result)
+ if (Result) {
InvalidNameMetric.record(1, toString(Result->K));
+ return makeError(*Result);
+ }
+ return llvm::Error::success();
+}
+
+bool isSelectorLike(const syntax::Token &Cur, const syntax::Token &Next) {
+ return Cur.kind() == tok::identifier && Next.kind() == tok::colon &&
+ // We require the selector name and : to be contiguous.
+ // e.g. support `foo:` but not `foo :`.
+ Cur.endLocation() == Next.location();
+}
+
+bool isMatchingSelectorName(const syntax::Token &Cur, const syntax::Token &Next,
+ const SourceManager &SM,
+ llvm::StringRef SelectorName) {
+ if (SelectorName.empty())
+ return Cur.kind() == tok::colon;
+ return isSelectorLike(Cur, Next) && Cur.text(SM) == SelectorName;
+}
+
+// Scan through Tokens to find ranges for each selector fragment in Sel at the
+// top level (not nested in any () or {} or []). The search will terminate upon
----------------
ahoppen wrote:
I think the `not nested in any () or {} or []` is quite misleading. Based on this comment, I would have expected `doStuff` in `[someObject someArgLabel: [foo doStuff: 1]]` or
```objectivec
- (void) test {
[foo doStuff: 1];
}
```
to not be found because it’s nested in `{}` or `[]`.
https://github.com/llvm/llvm-project/pull/76466
More information about the cfe-commits
mailing list