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