]> granicus.if.org Git - clang/commitdiff
[clang-refactor] Get rid of OccurrencesFinder in RenamingAction, NFC
authorHaojian Wu <hokein@google.com>
Wed, 8 Nov 2017 14:53:08 +0000 (14:53 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 8 Nov 2017 14:53:08 +0000 (14:53 +0000)
Summary:
The OccurrencesFinder is only used in RenameOccurrences to find symbol
occurrences, there is no need to inherit RefactoringRule.

Replace it with a single utility function to avoid code misleading.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D39796

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317696 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/Refactoring/Rename/RenamingAction.cpp

index e2d5d4c3d4cb55b48346489642b5715e49a0a847..c8ed9dd19a8e8915dbf33b3a50bcd5965854468a 100644 (file)
@@ -43,22 +43,14 @@ namespace tooling {
 
 namespace {
 
-class OccurrenceFinder final : public FindSymbolOccurrencesRefactoringRule {
-public:
-  OccurrenceFinder(const NamedDecl *ND) : ND(ND) {}
-
-  Expected<SymbolOccurrences>
-  findSymbolOccurrences(RefactoringRuleContext &Context) override {
-    std::vector<std::string> USRs =
-        getUSRsForDeclaration(ND, Context.getASTContext());
-    std::string PrevName = ND->getNameAsString();
-    return getOccurrencesOfUSRs(
-        USRs, PrevName, Context.getASTContext().getTranslationUnitDecl());
-  }
-
-private:
-  const NamedDecl *ND;
-};
+Expected<SymbolOccurrences>
+findSymbolOccurrences(const NamedDecl *ND, RefactoringRuleContext &Context) {
+  std::vector<std::string> USRs =
+      getUSRsForDeclaration(ND, Context.getASTContext());
+  std::string PrevName = ND->getNameAsString();
+  return getOccurrencesOfUSRs(USRs, PrevName,
+                              Context.getASTContext().getTranslationUnitDecl());
+}
 
 } // end anonymous namespace
 
@@ -85,8 +77,7 @@ RenameOccurrences::initiate(RefactoringRuleContext &Context,
 
 Expected<AtomicChanges>
 RenameOccurrences::createSourceReplacements(RefactoringRuleContext &Context) {
-  Expected<SymbolOccurrences> Occurrences =
-      OccurrenceFinder(ND).findSymbolOccurrences(Context);
+  Expected<SymbolOccurrences> Occurrences = findSymbolOccurrences(ND, Context);
   if (!Occurrences)
     return Occurrences.takeError();
   // FIXME: Verify that the new name is valid.