hokein created this revision. Herald added a subscriber: klimek. 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. https://reviews.llvm.org/D39796 Files: lib/Tooling/Refactoring/Rename/RenamingAction.cpp Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp =================================================================== --- lib/Tooling/Refactoring/Rename/RenamingAction.cpp +++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp @@ -43,22 +43,14 @@ 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 @@ 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.
Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp =================================================================== --- lib/Tooling/Refactoring/Rename/RenamingAction.cpp +++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp @@ -43,22 +43,14 @@ 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 @@ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits