RefactoringAction.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- RefactoringAction.h - Clang refactoring library ------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H
  14. #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H
  15. #include "clang/Basic/LLVM.h"
  16. #include "clang/Tooling/Refactoring/RefactoringActionRules.h"
  17. #include <vector>
  18. namespace clang {
  19. namespace tooling {
  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. /// Returns the name of the subcommand that's used by clang-refactor for this
  44. /// action.
  45. virtual StringRef getCommand() const = 0;
  46. virtual StringRef getDescription() const = 0;
  47. RefactoringActionRules createActiveActionRules();
  48. protected:
  49. /// Returns a set of refactoring actions rules that are defined by this
  50. /// action.
  51. virtual RefactoringActionRules createActionRules() const = 0;
  52. };
  53. /// Returns the list of all the available refactoring actions.
  54. std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions();
  55. } // end namespace tooling
  56. } // end namespace clang
  57. #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTION_H
  58. #ifdef __GNUC__
  59. #pragma GCC diagnostic pop
  60. #endif