Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 1 | //===--- RefactoringAction.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 | #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H |
||
10 | #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H |
||
11 | |||
12 | #include "clang/Basic/LLVM.h" |
||
13 | #include "clang/Tooling/Refactoring/RefactoringActionRules.h" |
||
14 | #include <vector> |
||
15 | |||
16 | namespace clang { |
||
17 | namespace tooling { |
||
18 | |||
19 | /// A refactoring action is a class that defines a set of related refactoring |
||
20 | /// action rules. These rules get grouped under a common umbrella - a single |
||
21 | /// clang-refactor subcommand. |
||
22 | /// |
||
23 | /// A subclass of \c RefactoringAction is responsible for creating the set of |
||
24 | /// grouped refactoring action rules that represent one refactoring operation. |
||
25 | /// Although the rules in one action may have a number of different |
||
26 | /// implementations, they should strive to produce a similar result. It should |
||
27 | /// be easy for users to identify which refactoring action produced the result |
||
28 | /// regardless of which refactoring action rule was used. |
||
29 | /// |
||
30 | /// The distinction between actions and rules enables the creation of action |
||
31 | /// that uses very different rules, for example: |
||
32 | /// - local vs global: a refactoring operation like |
||
33 | /// "add missing switch cases" can be applied to one switch when it's |
||
34 | /// selected in an editor, or to all switches in a project when an enum |
||
35 | /// constant is added to an enum. |
||
36 | /// - tool vs editor: some refactoring operation can be initiated in the |
||
37 | /// editor when a declaration is selected, or in a tool when the name of |
||
38 | /// the declaration is passed using a command-line argument. |
||
39 | class RefactoringAction { |
||
40 | public: |
||
41 | virtual ~RefactoringAction() {} |
||
42 | |||
43 | /// Returns the name of the subcommand that's used by clang-refactor for this |
||
44 | /// action. |
||
45 | virtual StringRef getCommand() const = 0; |
||
46 | |||
47 | virtual StringRef getDescription() const = 0; |
||
48 | |||
49 | RefactoringActionRules createActiveActionRules(); |
||
50 | |||
51 | protected: |
||
52 | /// Returns a set of refactoring actions rules that are defined by this |
||
53 | /// action. |
||
54 | virtual RefactoringActionRules createActionRules() const = 0; |
||
55 | }; |
||
56 | |||
57 | /// Returns the list of all the available refactoring actions. |
||
58 | std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions(); |
||
59 | |||
60 | } // end namespace tooling |
||
61 | } // end namespace clang |
||
62 | |||
63 | #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H |