clang  14.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_REFACTOR_RENAME_RENAMING_ACTION_H
15 #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H
16 
22 #include "llvm/Support/Error.h"
23 
24 namespace clang {
25 class ASTConsumer;
26 class CompilerInstance;
27 
28 namespace tooling {
29 
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 
50 public:
52  SourceRange SelectionRange,
53  std::string NewName);
54 
55  static const RefactoringDescriptor &describe();
56 
57  const NamedDecl *getRenameDecl() const;
58 
59 private:
60  RenameOccurrences(const NamedDecl *ND, std::string NewName)
61  : ND(ND), NewName(std::move(NewName)) {}
62 
64  createSourceReplacements(RefactoringRuleContext &Context) override;
65 
66  const NamedDecl *ND;
67  std::string NewName;
68 };
69 
71 public:
73  std::string OldQualifiedName,
74  std::string NewQualifiedName);
75 
76  static const RefactoringDescriptor &describe();
77 
78 private:
80  std::string NewQualifiedName)
81  : ND(ND), NewQualifiedName(std::move(NewQualifiedName)) {}
82 
84  createSourceReplacements(RefactoringRuleContext &Context) override;
85 
86  // A NamedDecl which identifies the symbol being renamed.
87  const NamedDecl *ND;
88  // The new qualified name to change the symbol to.
89  std::string NewQualifiedName;
90 };
91 
92 /// Returns source replacements that correspond to the rename of the given
93 /// symbol occurrences.
96  const SourceManager &SM, const SymbolName &NewName);
97 
98 /// Rename all symbols identified by the given USRs.
100 public:
102  const std::vector<std::string> &NewNames,
103  const std::vector<std::vector<std::string>> &USRList,
104  std::map<std::string, tooling::Replacements> &FileToReplaces)
105  : NewNames(NewNames), USRList(USRList), FileToReplaces(FileToReplaces) {}
106 
107  std::unique_ptr<ASTConsumer> newASTConsumer();
108 
109 private:
110  /// New symbol names.
111  const std::vector<std::string> &NewNames;
112 
113  /// A list of USRs. Each element represents USRs of a symbol being renamed.
114  const std::vector<std::vector<std::string>> &USRList;
115 
116  /// A file path to replacements map.
117  std::map<std::string, tooling::Replacements> &FileToReplaces;
118 };
119 
120 } // end namespace tooling
121 } // end namespace clang
122 
123 #endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_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:212
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:249
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:626
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:99
clang::tooling::RenameOccurrences
Definition: RenamingAction.h:49
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:30
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:101
clang::tooling::QualifiedRenameRule
Definition: RenamingAction.h:70
SM
#define SM(sm)
Definition: Cuda.cpp:78
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:32
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