|
|
|||
File indexing completed on 2026-05-10 08:37:11
0001 //===--- RefactoringActionRules.h - Clang refactoring library -------------===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTIONRULES_H 0010 #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTIONRULES_H 0011 0012 #include "clang/Tooling/Refactoring/RefactoringActionRule.h" 0013 #include "clang/Tooling/Refactoring/RefactoringActionRulesInternal.h" 0014 0015 namespace clang { 0016 namespace tooling { 0017 0018 /// Creates a new refactoring action rule that constructs and invokes the 0019 /// \c RuleType rule when all of the requirements are satisfied. 0020 /// 0021 /// This function takes in a list of values whose type derives from 0022 /// \c RefactoringActionRuleRequirement. These values describe the initiation 0023 /// requirements that have to be satisfied by the refactoring engine before 0024 /// the provided action rule can be constructed and invoked. The engine 0025 /// verifies that the requirements are satisfied by evaluating them (using the 0026 /// 'evaluate' member function) and checking that the results don't contain 0027 /// any errors. Once all requirements are satisfied, the provided refactoring 0028 /// rule is constructed by passing in the values returned by the requirements' 0029 /// evaluate functions as arguments to the constructor. The rule is then invoked 0030 /// immediately after construction. 0031 /// 0032 /// The separation of requirements, their evaluation and the invocation of the 0033 /// refactoring action rule allows the refactoring clients to: 0034 /// - Disable refactoring action rules whose requirements are not supported. 0035 /// - Gather the set of options and define a command-line / visual interface 0036 /// that allows users to input these options without ever invoking the 0037 /// action. 0038 template <typename RuleType, typename... RequirementTypes> 0039 std::unique_ptr<RefactoringActionRule> 0040 createRefactoringActionRule(const RequirementTypes &... Requirements); 0041 0042 /// A set of refactoring action rules that should have unique initiation 0043 /// requirements. 0044 using RefactoringActionRules = 0045 std::vector<std::unique_ptr<RefactoringActionRule>>; 0046 0047 /// A type of refactoring action rule that produces source replacements in the 0048 /// form of atomic changes. 0049 /// 0050 /// This action rule is typically used for local refactorings that replace 0051 /// source in a single AST unit. 0052 class SourceChangeRefactoringRule : public RefactoringActionRuleBase { 0053 public: 0054 void invoke(RefactoringResultConsumer &Consumer, 0055 RefactoringRuleContext &Context) final { 0056 Expected<AtomicChanges> Changes = createSourceReplacements(Context); 0057 if (!Changes) 0058 Consumer.handleError(Changes.takeError()); 0059 else 0060 Consumer.handle(std::move(*Changes)); 0061 } 0062 0063 private: 0064 virtual Expected<AtomicChanges> 0065 createSourceReplacements(RefactoringRuleContext &Context) = 0; 0066 }; 0067 0068 /// A type of refactoring action rule that finds a set of symbol occurrences 0069 /// that reference a particular symbol. 0070 /// 0071 /// This action rule is typically used for an interactive rename that allows 0072 /// users to specify the new name and the set of selected occurrences during 0073 /// the refactoring. 0074 class FindSymbolOccurrencesRefactoringRule : public RefactoringActionRuleBase { 0075 public: 0076 void invoke(RefactoringResultConsumer &Consumer, 0077 RefactoringRuleContext &Context) final { 0078 Expected<SymbolOccurrences> Occurrences = findSymbolOccurrences(Context); 0079 if (!Occurrences) 0080 Consumer.handleError(Occurrences.takeError()); 0081 else 0082 Consumer.handle(std::move(*Occurrences)); 0083 } 0084 0085 private: 0086 virtual Expected<SymbolOccurrences> 0087 findSymbolOccurrences(RefactoringRuleContext &Context) = 0; 0088 }; 0089 0090 } // end namespace tooling 0091 } // end namespace clang 0092 0093 #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTIONRULES_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|