[PATCH] D75230: [clangd] Get rid of lexer usage in ObjCLocalizeStringLiteral tweak
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 28 01:04:44 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG48fad110e08a: [clangd] Get rid of lexer usage in ObjCLocalizeStringLiteral tweak (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75230/new/
https://reviews.llvm.org/D75230
Files:
clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp
Index: clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp
@@ -63,15 +63,19 @@
Expected<Tweak::Effect>
ObjCLocalizeStringLiteral::apply(const Selection &Inputs) {
- auto &SM = Inputs.AST->getSourceManager();
- auto &LangOpts = Inputs.AST->getASTContext().getLangOpts();
+ auto *AST = Inputs.AST;
+ auto &SM = AST->getSourceManager();
+ const auto &TB = AST->getTokens();
+ auto Toks = TB.spelledForExpanded(TB.expandedTokens(Str->getSourceRange()));
+ if (!Toks || Toks->empty())
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Failed to find tokens to replace.");
+ // Insert `NSLocalizedString(` before the literal.
auto Reps = tooling::Replacements(tooling::Replacement(
- SM, CharSourceRange::getCharRange(Str->getBeginLoc()),
- "NSLocalizedString(", LangOpts));
- SourceLocation EndLoc = Lexer::getLocForEndOfToken(
- Str->getEndLoc(), 0, Inputs.AST->getSourceManager(), LangOpts);
- if (auto Err = Reps.add(tooling::Replacement(
- SM, CharSourceRange::getCharRange(EndLoc), ", @\"\")", LangOpts)))
+ SM, Toks->front().location(), 0, "NSLocalizedString("));
+ // Insert `, @"")` after the literal.
+ if (auto Err = Reps.add(
+ tooling::Replacement(SM, Toks->back().endLocation(), 0, ", @\"\")")))
return std::move(Err);
return Effect::mainFileEdit(SM, std::move(Reps));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75230.247182.patch
Type: text/x-patch
Size: 1637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200228/a48ac620/attachment.bin>
More information about the cfe-commits
mailing list