RefactoringOption.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- RefactoringOption.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_REFACTORINGOPTION_H
  14. #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H
  15. #include "clang/Basic/LLVM.h"
  16. #include <memory>
  17. #include <type_traits>
  18. namespace clang {
  19. namespace tooling {
  20. class RefactoringOptionVisitor;
  21. /// A refactoring option is an interface that describes a value that
  22. /// has an impact on the outcome of a refactoring.
  23. ///
  24. /// Refactoring options can be specified using command-line arguments when
  25. /// the clang-refactor tool is used.
  26. class RefactoringOption {
  27. public:
  28. virtual ~RefactoringOption() {}
  29. /// Returns the name of the refactoring option.
  30. ///
  31. /// Each refactoring option must have a unique name.
  32. virtual StringRef getName() const = 0;
  33. virtual StringRef getDescription() const = 0;
  34. /// True when this option must be specified before invoking the refactoring
  35. /// action.
  36. virtual bool isRequired() const = 0;
  37. /// Invokes the \c visit method in the option consumer that's appropriate
  38. /// for the option's value type.
  39. ///
  40. /// For example, if the option stores a string value, this method will
  41. /// invoke the \c visit method with a reference to an std::string value.
  42. virtual void passToVisitor(RefactoringOptionVisitor &Visitor) = 0;
  43. };
  44. /// Constructs a refactoring option of the given type.
  45. ///
  46. /// The ownership of options is shared among requirements that use it because
  47. /// one option can be used by multiple rules in a refactoring action.
  48. template <typename OptionType>
  49. std::shared_ptr<OptionType> createRefactoringOption() {
  50. static_assert(std::is_base_of<RefactoringOption, OptionType>::value,
  51. "invalid option type");
  52. return std::make_shared<OptionType>();
  53. }
  54. } // end namespace tooling
  55. } // end namespace clang
  56. #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H
  57. #ifdef __GNUC__
  58. #pragma GCC diagnostic pop
  59. #endif