clang  6.0.0svn
RefactoringActions.cpp
Go to the documentation of this file.
1 //===--- RefactoringActions.cpp - Constructs refactoring actions ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
14 
15 namespace clang {
16 namespace tooling {
17 
18 namespace {
19 
20 class DeclNameOption final : public OptionalRefactoringOption<std::string> {
21 public:
22  StringRef getName() const { return "name"; }
23  StringRef getDescription() const {
24  return "Name of the extracted declaration";
25  }
26 };
27 
28 // FIXME: Rewrite the Actions to avoid duplication of descriptions/names with
29 // rules.
30 class ExtractRefactoring final : public RefactoringAction {
31 public:
32  StringRef getCommand() const override { return "extract"; }
33 
34  StringRef getDescription() const override {
35  return "(WIP action; use with caution!) Extracts code into a new function";
36  }
37 
38  /// Returns a set of refactoring actions rules that are defined by this
39  /// action.
40  RefactoringActionRules createActionRules() const override {
42  Rules.push_back(createRefactoringActionRule<ExtractFunction>(
43  CodeRangeASTSelectionRequirement(),
44  OptionRequirement<DeclNameOption>()));
45  return Rules;
46  }
47 };
48 
49 class OldQualifiedNameOption : public RequiredRefactoringOption<std::string> {
50 public:
51  StringRef getName() const override { return "old-qualified-name"; }
52  StringRef getDescription() const override {
53  return "The old qualified name to be renamed";
54  }
55 };
56 
57 class NewQualifiedNameOption : public RequiredRefactoringOption<std::string> {
58 public:
59  StringRef getName() const override { return "new-qualified-name"; }
60  StringRef getDescription() const override {
61  return "The new qualified name to change the symbol to";
62  }
63 };
64 
65 class NewNameOption : public RequiredRefactoringOption<std::string> {
66 public:
67  StringRef getName() const override { return "new-name"; }
68  StringRef getDescription() const override {
69  return "The new name to change the symbol to";
70  }
71 };
72 
73 // FIXME: Rewrite the Actions to avoid duplication of descriptions/names with
74 // rules.
75 class LocalRename final : public RefactoringAction {
76 public:
77  StringRef getCommand() const override { return "local-rename"; }
78 
79  StringRef getDescription() const override {
80  return "Finds and renames symbols in code with no indexer support";
81  }
82 
83  /// Returns a set of refactoring actions rules that are defined by this
84  /// action.
85  RefactoringActionRules createActionRules() const override {
87  Rules.push_back(createRefactoringActionRule<RenameOccurrences>(
88  SourceRangeSelectionRequirement(), OptionRequirement<NewNameOption>()));
89  // FIXME: Use NewNameOption.
90  Rules.push_back(createRefactoringActionRule<QualifiedRenameRule>(
91  OptionRequirement<OldQualifiedNameOption>(),
92  OptionRequirement<NewQualifiedNameOption>()));
93  return Rules;
94  }
95 };
96 
97 } // end anonymous namespace
98 
99 std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions() {
100  std::vector<std::unique_ptr<RefactoringAction>> Actions;
101 
102  Actions.push_back(llvm::make_unique<LocalRename>());
103  Actions.push_back(llvm::make_unique<ExtractRefactoring>());
104 
105  return Actions;
106 }
107 
109  // FIXME: Filter out rules that are not supported by a particular client.
110  return createActionRules();
111 }
112 
113 } // end namespace tooling
114 } // end namespace clang
std::vector< std::unique_ptr< RefactoringActionRule > > RefactoringActionRules
A set of refactoring action rules that should have unique initiation requirements.
Dataflow Directional Tag Classes.
RefactoringActionRules createActiveActionRules()
std::vector< std::unique_ptr< RefactoringAction > > createRefactoringActions()
Returns the list of all the available refactoring actions.
Provides an action to rename every symbol at a point.