1326941Sdim//===--- RefactoringAction.h - Clang refactoring library ------------------===//
2326941Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6326941Sdim//
7326941Sdim//===----------------------------------------------------------------------===//
8326941Sdim
9326941Sdim#ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H
10326941Sdim#define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H
11326941Sdim
12326941Sdim#include "clang/Basic/LLVM.h"
13326941Sdim#include "clang/Tooling/Refactoring/RefactoringActionRules.h"
14326941Sdim#include <vector>
15326941Sdim
16326941Sdimnamespace clang {
17326941Sdimnamespace tooling {
18326941Sdim
19326941Sdim/// A refactoring action is a class that defines a set of related refactoring
20326941Sdim/// action rules. These rules get grouped under a common umbrella - a single
21326941Sdim/// clang-refactor subcommand.
22326941Sdim///
23326941Sdim/// A subclass of \c RefactoringAction is responsible for creating the set of
24326941Sdim/// grouped refactoring action rules that represent one refactoring operation.
25326941Sdim/// Although the rules in one action may have a number of different
26326941Sdim/// implementations, they should strive to produce a similar result. It should
27326941Sdim/// be easy for users to identify which refactoring action produced the result
28326941Sdim/// regardless of which refactoring action rule was used.
29326941Sdim///
30326941Sdim/// The distinction between actions and rules enables the creation of action
31326941Sdim/// that uses very different rules, for example:
32326941Sdim///   - local vs global: a refactoring operation like
33326941Sdim///     "add missing switch cases" can be applied to one switch when it's
34326941Sdim///     selected in an editor, or to all switches in a project when an enum
35326941Sdim///     constant is added to an enum.
36326941Sdim///   - tool vs editor: some refactoring operation can be initiated in the
37326941Sdim///     editor when a declaration is selected, or in a tool when the name of
38326941Sdim///     the declaration is passed using a command-line argument.
39326941Sdimclass RefactoringAction {
40326941Sdimpublic:
41326941Sdim  virtual ~RefactoringAction() {}
42326941Sdim
43326941Sdim  /// Returns the name of the subcommand that's used by clang-refactor for this
44326941Sdim  /// action.
45326941Sdim  virtual StringRef getCommand() const = 0;
46326941Sdim
47326941Sdim  virtual StringRef getDescription() const = 0;
48326941Sdim
49326941Sdim  RefactoringActionRules createActiveActionRules();
50326941Sdim
51326941Sdimprotected:
52326941Sdim  /// Returns a set of refactoring actions rules that are defined by this
53326941Sdim  /// action.
54326941Sdim  virtual RefactoringActionRules createActionRules() const = 0;
55326941Sdim};
56326941Sdim
57326941Sdim/// Returns the list of all the available refactoring actions.
58326941Sdimstd::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions();
59326941Sdim
60326941Sdim} // end namespace tooling
61326941Sdim} // end namespace clang
62326941Sdim
63326941Sdim#endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_H
64