1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H |
15 | #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H |
16 | |
17 | #include "clang/Tooling/Refactoring.h" |
18 | #include "clang/Tooling/Refactoring/AtomicChange.h" |
19 | #include "clang/Tooling/Refactoring/RefactoringActionRules.h" |
20 | #include "clang/Tooling/Refactoring/RefactoringOptions.h" |
21 | #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h" |
22 | #include "llvm/Support/Error.h" |
23 | |
24 | namespace clang { |
25 | class ASTConsumer; |
26 | class CompilerInstance; |
27 | |
28 | namespace tooling { |
29 | |
30 | class RenamingAction { |
31 | public: |
32 | RenamingAction(const std::vector<std::string> &NewNames, |
33 | const std::vector<std::string> &PrevNames, |
34 | const std::vector<std::vector<std::string>> &USRList, |
35 | std::map<std::string, tooling::Replacements> &FileToReplaces, |
36 | bool PrintLocations = false) |
37 | : NewNames(NewNames), PrevNames(PrevNames), USRList(USRList), |
38 | FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {} |
39 | |
40 | std::unique_ptr<ASTConsumer> newASTConsumer(); |
41 | |
42 | private: |
43 | const std::vector<std::string> &NewNames, &PrevNames; |
44 | const std::vector<std::vector<std::string>> &USRList; |
45 | std::map<std::string, tooling::Replacements> &FileToReplaces; |
46 | bool PrintLocations; |
47 | }; |
48 | |
49 | class RenameOccurrences final : public SourceChangeRefactoringRule { |
50 | public: |
51 | static Expected<RenameOccurrences> initiate(RefactoringRuleContext &Context, |
52 | SourceRange SelectionRange, |
53 | std::string NewName); |
54 | |
55 | static const RefactoringDescriptor &describe(); |
56 | |
57 | private: |
58 | RenameOccurrences(const NamedDecl *ND, std::string NewName) |
59 | : ND(ND), NewName(std::move(NewName)) {} |
60 | |
61 | Expected<AtomicChanges> |
62 | createSourceReplacements(RefactoringRuleContext &Context) override; |
63 | |
64 | const NamedDecl *ND; |
65 | std::string NewName; |
66 | }; |
67 | |
68 | class QualifiedRenameRule final : public SourceChangeRefactoringRule { |
69 | public: |
70 | static Expected<QualifiedRenameRule> initiate(RefactoringRuleContext &Context, |
71 | std::string OldQualifiedName, |
72 | std::string NewQualifiedName); |
73 | |
74 | static const RefactoringDescriptor &describe(); |
75 | |
76 | private: |
77 | QualifiedRenameRule(const NamedDecl *ND, |
78 | std::string NewQualifiedName) |
79 | : ND(ND), NewQualifiedName(std::move(NewQualifiedName)) {} |
80 | |
81 | Expected<AtomicChanges> |
82 | createSourceReplacements(RefactoringRuleContext &Context) override; |
83 | |
84 | |
85 | const NamedDecl *ND; |
86 | |
87 | std::string NewQualifiedName; |
88 | }; |
89 | |
90 | |
91 | |
92 | llvm::Expected<std::vector<AtomicChange>> |
93 | createRenameReplacements(const SymbolOccurrences &Occurrences, |
94 | const SourceManager &SM, const SymbolName &NewName); |
95 | |
96 | |
97 | class QualifiedRenamingAction { |
98 | public: |
99 | QualifiedRenamingAction( |
100 | const std::vector<std::string> &NewNames, |
101 | const std::vector<std::vector<std::string>> &USRList, |
102 | std::map<std::string, tooling::Replacements> &FileToReplaces) |
103 | : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {} |
104 | |
105 | std::unique_ptr<ASTConsumer> newASTConsumer(); |
106 | |
107 | private: |
108 | |
109 | const std::vector<std::string> &NewNames; |
110 | |
111 | |
112 | const std::vector<std::vector<std::string>> &USRList; |
113 | |
114 | |
115 | std::map<std::string, tooling::Replacements> &FileToReplaces; |
116 | }; |
117 | |
118 | } |
119 | } |
120 | |
121 | #endif |
122 | |