1 //===--- RefactoringAction.h - Clang refactoring library ------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H
10 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H
12 #include "clang/Basic/LLVM.h"
13 #include "clang/Tooling/Refactoring/RefactoringActionRules.h"
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.
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.
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 {
41 virtual ~RefactoringAction() {}
43 /// Returns the name of the subcommand that's used by clang-refactor for this
45 virtual StringRef getCommand() const = 0;
47 virtual StringRef getDescription() const = 0;
49 RefactoringActionRules createActiveActionRules();
52 /// Returns a set of refactoring actions rules that are defined by this
54 virtual RefactoringActionRules createActionRules() const = 0;
57 /// Returns the list of all the available refactoring actions.
58 std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions();
60 } // end namespace tooling
61 } // end namespace clang
63 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H