File indexing completed on 2026-05-10 08:37:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_TOOLING_REFACTORING_RENAME_RENAMINGACTION_H
0015 #define LLVM_CLANG_TOOLING_REFACTORING_RENAME_RENAMINGACTION_H
0016
0017 #include "clang/Tooling/Refactoring.h"
0018 #include "clang/Tooling/Refactoring/AtomicChange.h"
0019 #include "clang/Tooling/Refactoring/RefactoringActionRules.h"
0020 #include "clang/Tooling/Refactoring/RefactoringOptions.h"
0021 #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
0022 #include "llvm/Support/Error.h"
0023
0024 namespace clang {
0025 class ASTConsumer;
0026
0027 namespace tooling {
0028
0029 class RenamingAction {
0030 public:
0031 RenamingAction(const std::vector<std::string> &NewNames,
0032 const std::vector<std::string> &PrevNames,
0033 const std::vector<std::vector<std::string>> &USRList,
0034 std::map<std::string, tooling::Replacements> &FileToReplaces,
0035 bool PrintLocations = false)
0036 : NewNames(NewNames), PrevNames(PrevNames), USRList(USRList),
0037 FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {}
0038
0039 std::unique_ptr<ASTConsumer> newASTConsumer();
0040
0041 private:
0042 const std::vector<std::string> &NewNames, &PrevNames;
0043 const std::vector<std::vector<std::string>> &USRList;
0044 std::map<std::string, tooling::Replacements> &FileToReplaces;
0045 bool PrintLocations;
0046 };
0047
0048 class RenameOccurrences final : public SourceChangeRefactoringRule {
0049 public:
0050 static Expected<RenameOccurrences> initiate(RefactoringRuleContext &Context,
0051 SourceRange SelectionRange,
0052 std::string NewName);
0053
0054 static const RefactoringDescriptor &describe();
0055
0056 const NamedDecl *getRenameDecl() const;
0057
0058 private:
0059 RenameOccurrences(const NamedDecl *ND, std::string NewName)
0060 : ND(ND), NewName(std::move(NewName)) {}
0061
0062 Expected<AtomicChanges>
0063 createSourceReplacements(RefactoringRuleContext &Context) override;
0064
0065 const NamedDecl *ND;
0066 std::string NewName;
0067 };
0068
0069 class QualifiedRenameRule final : public SourceChangeRefactoringRule {
0070 public:
0071 static Expected<QualifiedRenameRule> initiate(RefactoringRuleContext &Context,
0072 std::string OldQualifiedName,
0073 std::string NewQualifiedName);
0074
0075 static const RefactoringDescriptor &describe();
0076
0077 private:
0078 QualifiedRenameRule(const NamedDecl *ND,
0079 std::string NewQualifiedName)
0080 : ND(ND), NewQualifiedName(std::move(NewQualifiedName)) {}
0081
0082 Expected<AtomicChanges>
0083 createSourceReplacements(RefactoringRuleContext &Context) override;
0084
0085
0086 const NamedDecl *ND;
0087
0088 std::string NewQualifiedName;
0089 };
0090
0091
0092
0093 llvm::Expected<std::vector<AtomicChange>>
0094 createRenameReplacements(const SymbolOccurrences &Occurrences,
0095 const SourceManager &SM, const SymbolName &NewName);
0096
0097
0098 class QualifiedRenamingAction {
0099 public:
0100 QualifiedRenamingAction(
0101 const std::vector<std::string> &NewNames,
0102 const std::vector<std::vector<std::string>> &USRList,
0103 std::map<std::string, tooling::Replacements> &FileToReplaces)
0104 : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {}
0105
0106 std::unique_ptr<ASTConsumer> newASTConsumer();
0107
0108 private:
0109
0110 const std::vector<std::string> &NewNames;
0111
0112
0113 const std::vector<std::vector<std::string>> &USRList;
0114
0115
0116 std::map<std::string, tooling::Replacements> &FileToReplaces;
0117 };
0118
0119 }
0120 }
0121
0122 #endif