RefactoringActionRule.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- RefactoringActionRule.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_REFACTORINGACTIONRULE_H
  14. #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTIONRULE_H
  15. #include "clang/Basic/LLVM.h"
  16. #include "llvm/ADT/StringRef.h"
  17. namespace clang {
  18. namespace tooling {
  19. class RefactoringOptionVisitor;
  20. class RefactoringResultConsumer;
  21. class RefactoringRuleContext;
  22. struct RefactoringDescriptor {
  23. /// A unique identifier for the specific refactoring.
  24. StringRef Name;
  25. /// A human readable title for the refactoring.
  26. StringRef Title;
  27. /// A human readable description of what the refactoring does.
  28. StringRef Description;
  29. };
  30. /// A common refactoring action rule interface that defines the 'invoke'
  31. /// function that performs the refactoring operation (either fully or
  32. /// partially).
  33. class RefactoringActionRuleBase {
  34. public:
  35. virtual ~RefactoringActionRuleBase() {}
  36. /// Initiates and performs a specific refactoring action.
  37. ///
  38. /// The specific rule will invoke an appropriate \c handle method on a
  39. /// consumer to propagate the result of the refactoring action.
  40. virtual void invoke(RefactoringResultConsumer &Consumer,
  41. RefactoringRuleContext &Context) = 0;
  42. /// Returns the structure that describes the refactoring.
  43. // static const RefactoringDescriptor &describe() = 0;
  44. };
  45. /// A refactoring action rule is a wrapper class around a specific refactoring
  46. /// action rule (SourceChangeRefactoringRule, etc) that, in addition to invoking
  47. /// the action, describes the requirements that determine when the action can be
  48. /// initiated.
  49. class RefactoringActionRule : public RefactoringActionRuleBase {
  50. public:
  51. /// Returns true when the rule has a source selection requirement that has
  52. /// to be fulfilled before refactoring can be performed.
  53. virtual bool hasSelectionRequirement() = 0;
  54. /// Traverses each refactoring option used by the rule and invokes the
  55. /// \c visit callback in the consumer for each option.
  56. ///
  57. /// Options are visited in the order of use, e.g. if a rule has two
  58. /// requirements that use options, the options from the first requirement
  59. /// are visited before the options in the second requirement.
  60. virtual void visitRefactoringOptions(RefactoringOptionVisitor &Visitor) = 0;
  61. };
  62. } // end namespace tooling
  63. } // end namespace clang
  64. #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGACTIONRULE_H
  65. #ifdef __GNUC__
  66. #pragma GCC diagnostic pop
  67. #endif