clang  6.0.0svn
RefactoringActionRules.h
Go to the documentation of this file.
1 //===--- RefactoringActionRules.h - Clang refactoring library -------------===//
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 
10 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULES_H
11 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULES_H
12 
15 
16 namespace clang {
17 namespace tooling {
18 
19 /// Creates a new refactoring action rule that constructs and invokes the
20 /// \c RuleType rule when all of the requirements are satisfied.
21 ///
22 /// This function takes in a list of values whose type derives from
23 /// \c RefactoringActionRuleRequirement. These values describe the initiation
24 /// requirements that have to be satisfied by the refactoring engine before
25 /// the provided action rule can be constructed and invoked. The engine
26 /// verifies that the requirements are satisfied by evaluating them (using the
27 /// 'evaluate' member function) and checking that the results don't contain
28 /// any errors. Once all requirements are satisfied, the provided refactoring
29 /// rule is constructed by passing in the values returned by the requirements'
30 /// evaluate functions as arguments to the constructor. The rule is then invoked
31 /// immediately after construction.
32 ///
33 /// The separation of requirements, their evaluation and the invocation of the
34 /// refactoring action rule allows the refactoring clients to:
35 /// - Disable refactoring action rules whose requirements are not supported.
36 /// - Gather the set of options and define a command-line / visual interface
37 /// that allows users to input these options without ever invoking the
38 /// action.
39 template <typename RuleType, typename... RequirementTypes>
40 std::unique_ptr<RefactoringActionRule>
41 createRefactoringActionRule(const RequirementTypes &... Requirements);
42 
43 /// A set of refactoring action rules that should have unique initiation
44 /// requirements.
46  std::vector<std::unique_ptr<RefactoringActionRule>>;
47 
48 /// A type of refactoring action rule that produces source replacements in the
49 /// form of atomic changes.
50 ///
51 /// This action rule is typically used for local refactorings that replace
52 /// source in a single AST unit.
54 public:
56  RefactoringRuleContext &Context) final override {
57  Expected<AtomicChanges> Changes = createSourceReplacements(Context);
58  if (!Changes)
59  Consumer.handleError(Changes.takeError());
60  else
61  Consumer.handle(std::move(*Changes));
62  }
63 
64 private:
66  createSourceReplacements(RefactoringRuleContext &Context) = 0;
67 };
68 
69 /// A type of refactoring action rule that finds a set of symbol occurrences
70 /// that reference a particular symbol.
71 ///
72 /// This action rule is typically used for an interactive rename that allows
73 /// users to specify the new name and the set of selected occurrences during
74 /// the refactoring.
76 public:
78  RefactoringRuleContext &Context) final override {
79  Expected<SymbolOccurrences> Occurrences = findSymbolOccurrences(Context);
80  if (!Occurrences)
81  Consumer.handleError(Occurrences.takeError());
82  else
83  Consumer.handle(std::move(*Occurrences));
84  }
85 
86 private:
88  findSymbolOccurrences(RefactoringRuleContext &Context) = 0;
89 };
90 
91 } // end namespace tooling
92 } // end namespace clang
93 
94 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULES_H
std::vector< std::unique_ptr< RefactoringActionRule > > RefactoringActionRules
A set of refactoring action rules that should have unique initiation requirements.
void invoke(RefactoringResultConsumer &Consumer, RefactoringRuleContext &Context) final override
Initiates and performs a specific refactoring action.
A common refactoring action rule interface that defines the &#39;invoke&#39; function that performs the refac...
AvailabilityChange Changes[NumAvailabilitySlots]
Definition: AttributeList.h:57
A type of refactoring action rule that finds a set of symbol occurrences that reference a particular ...
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
std::unique_ptr< RefactoringActionRule > createRefactoringActionRule(const RequirementTypes &... Requirements)
Creates a new refactoring action rule that constructs and invokes the RuleType rule when all of the r...
An abstract interface that consumes the various refactoring results that can be produced by refactori...
void invoke(RefactoringResultConsumer &Consumer, RefactoringRuleContext &Context) final override
Initiates and performs a specific refactoring action.
Dataflow Directional Tag Classes.
A type of refactoring action rule that produces source replacements in the form of atomic changes...