clang  15.0.0git
RenamingAction.h
Go to the documentation of this file.
1 //===--- RenamingAction.h - Clang refactoring library ---------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Provides an action to rename every symbol at a point.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_TOOLING_REFACTORING_RENAME_RENAMINGACTION_H
15 #define LLVM_CLANG_TOOLING_REFACTORING_RENAME_RENAMINGACTION_H
16 
22 #include "llvm/Support/Error.h"
23 
24 namespace clang {
25 class ASTConsumer;
26 
27 namespace tooling {
28 
30 public:
31  RenamingAction(const std::vector<std::string> &NewNames,
32  const std::vector<std::string> &PrevNames,
33  const std::vector<std::vector<std::string>> &USRList,
34  std::map<std::string, tooling::Replacements> &FileToReplaces,
35  bool PrintLocations = false)
36  : NewNames(NewNames), PrevNames(PrevNames), USRList(USRList),
37  FileToReplaces(FileToReplaces), PrintLocations(PrintLocations) {}
38 
39  std::unique_ptr<ASTConsumer> newASTConsumer();
40 
41 private:
42  const std::vector<std::string> &NewNames, &PrevNames;
43  const std::vector<std::vector<std::string>> &USRList;
44  std::map<std::string, tooling::Replacements> &FileToReplaces;
45  bool PrintLocations;
46 };
47 
49 public:
51  SourceRange SelectionRange,
52  std::string NewName);
53 
54  static const RefactoringDescriptor &describe();
55 
56  const NamedDecl *getRenameDecl() const;
57 
58 private:
59  RenameOccurrences(const NamedDecl *ND, std::string NewName)
60  : ND(ND), NewName(std::move(NewName)) {}
61 
63  createSourceReplacements(RefactoringRuleContext &Context) override;
64 
65  const NamedDecl *ND;
66  std::string NewName;
67 };
68 
70 public:
72  std::string OldQualifiedName,
73  std::string NewQualifiedName);
74 
75  static const RefactoringDescriptor &describe();
76 
77 private:
79  std::string NewQualifiedName)
80  : ND(ND), NewQualifiedName(std::move(NewQualifiedName)) {}
81 
83  createSourceReplacements(RefactoringRuleContext &Context) override;
84 
85  // A NamedDecl which identifies the symbol being renamed.
86  const NamedDecl *ND;
87  // The new qualified name to change the symbol to.
88  std::string NewQualifiedName;
89 };
90 
91 /// Returns source replacements that correspond to the rename of the given
92 /// symbol occurrences.
95  const SourceManager &SM, const SymbolName &NewName);
96 
97 /// Rename all symbols identified by the given USRs.
99 public:
101  const std::vector<std::string> &NewNames,
102  const std::vector<std::vector<std::string>> &USRList,
103  std::map<std::string, tooling::Replacements> &FileToReplaces)
104  : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {}
105 
106  std::unique_ptr<ASTConsumer> newASTConsumer();
107 
108 private:
109  /// New symbol names.
110  const std::vector<std::string> &NewNames;
111 
112  /// A list of USRs. Each element represents USRs of a symbol being renamed.
113  const std::vector<std::vector<std::string>> &USRList;
114 
115  /// A file path to replacements map.
116  std::map<std::string, tooling::Replacements> &FileToReplaces;
117 };
118 
119 } // end namespace tooling
120 } // end namespace clang
121 
122 #endif // LLVM_CLANG_TOOLING_REFACTORING_RENAME_RENAMINGACTION_H
clang::tooling::QualifiedRenameRule::initiate
static Expected< QualifiedRenameRule > initiate(RefactoringRuleContext &Context, std::string OldQualifiedName, std::string NewQualifiedName)
Definition: RenamingAction.cpp:91
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::tooling::SourceChangeRefactoringRule
A type of refactoring action rule that produces source replacements in the form of atomic changes.
Definition: RefactoringActionRules.h:52
RefactoringActionRules.h
clang::tooling::RenameOccurrences::getRenameDecl
const NamedDecl * getRenameDecl() const
Definition: RenamingAction.cpp:77
llvm::Expected
Definition: LLVM.h:41
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
AtomicChange.h
clang::tooling::RefactoringDescriptor
Definition: RefactoringActionRule.h:23
clang::tooling::RefactoringRuleContext
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
Definition: RefactoringRuleContext.h:33
clang::tooling::QualifiedRenamingAction
Rename all symbols identified by the given USRs.
Definition: RenamingAction.h:98
clang::tooling::RenameOccurrences
Definition: RenamingAction.h:48
clang::tooling::RenameOccurrences::describe
static const RefactoringDescriptor & describe()
Definition: RenamingAction.cpp:56
Refactoring.h
clang::tooling::RenamingAction::newASTConsumer
std::unique_ptr< ASTConsumer > newASTConsumer()
Definition: RenamingAction.cpp:246
clang::tooling::RenameOccurrences::initiate
static Expected< RenameOccurrences > initiate(RefactoringRuleContext &Context, SourceRange SelectionRange, std::string NewName)
Definition: RenamingAction.cpp:66
RefactoringOptions.h
clang::tooling::QualifiedRenameRule::describe
static const RefactoringDescriptor & describe()
Definition: RenamingAction.cpp:103
SymbolOccurrences.h
clang::tooling::SymbolName
A name of a symbol.
Definition: SymbolName.h:29
clang
Definition: CalledOnceCheck.h:17
clang::tooling::QualifiedRenamingAction::newASTConsumer
std::unique_ptr< ASTConsumer > newASTConsumer()
Definition: RenamingAction.cpp:251
clang::tooling::RenamingAction
Definition: RenamingAction.h:29
clang::tooling::SymbolOccurrences
std::vector< SymbolOccurrence > SymbolOccurrences
Definition: SymbolOccurrences.h:86
clang::tooling::QualifiedRenamingAction::QualifiedRenamingAction
QualifiedRenamingAction(const std::vector< std::string > &NewNames, const std::vector< std::vector< std::string >> &USRList, std::map< std::string, tooling::Replacements > &FileToReplaces)
Definition: RenamingAction.h:100
clang::tooling::QualifiedRenameRule
Definition: RenamingAction.h:69
SM
#define SM(sm)
Definition: Cuda.cpp:81
clang::tooling::RenamingAction::RenamingAction
RenamingAction(const std::vector< std::string > &NewNames, const std::vector< std::string > &PrevNames, const std::vector< std::vector< std::string >> &USRList, std::map< std::string, tooling::Replacements > &FileToReplaces, bool PrintLocations=false)
Definition: RenamingAction.h:31
clang::tooling::createRenameReplacements
llvm::Expected< std::vector< AtomicChange > > createRenameReplacements(const SymbolOccurrences &Occurrences, const SourceManager &SM, const SymbolName &NewName)
Returns source replacements that correspond to the rename of the given symbol occurrences.
Definition: RenamingAction.cpp:122