Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 1 | //===--- RefactoringOption.h - Clang refactoring library ------------------===// |
| 2 | // |
||
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
||
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
||
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
||
| 6 | // |
||
| 7 | //===----------------------------------------------------------------------===// |
||
| 8 | |||
| 9 | #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H |
||
| 10 | #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H |
||
| 11 | |||
| 12 | #include "clang/Basic/LLVM.h" |
||
| 13 | #include <memory> |
||
| 14 | #include <type_traits> |
||
| 15 | |||
| 16 | namespace clang { |
||
| 17 | namespace tooling { |
||
| 18 | |||
| 19 | class RefactoringOptionVisitor; |
||
| 20 | |||
| 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 | |||
| 30 | /// Returns the name of the refactoring option. |
||
| 31 | /// |
||
| 32 | /// Each refactoring option must have a unique name. |
||
| 33 | virtual StringRef getName() const = 0; |
||
| 34 | |||
| 35 | virtual StringRef getDescription() const = 0; |
||
| 36 | |||
| 37 | /// True when this option must be specified before invoking the refactoring |
||
| 38 | /// action. |
||
| 39 | virtual bool isRequired() const = 0; |
||
| 40 | |||
| 41 | /// Invokes the \c visit method in the option consumer that's appropriate |
||
| 42 | /// for the option's value type. |
||
| 43 | /// |
||
| 44 | /// For example, if the option stores a string value, this method will |
||
| 45 | /// invoke the \c visit method with a reference to an std::string value. |
||
| 46 | virtual void passToVisitor(RefactoringOptionVisitor &Visitor) = 0; |
||
| 47 | }; |
||
| 48 | |||
| 49 | /// Constructs a refactoring option of the given type. |
||
| 50 | /// |
||
| 51 | /// The ownership of options is shared among requirements that use it because |
||
| 52 | /// one option can be used by multiple rules in a refactoring action. |
||
| 53 | template <typename OptionType> |
||
| 54 | std::shared_ptr<OptionType> createRefactoringOption() { |
||
| 55 | static_assert(std::is_base_of<RefactoringOption, OptionType>::value, |
||
| 56 | "invalid option type"); |
||
| 57 | return std::make_shared<OptionType>(); |
||
| 58 | } |
||
| 59 | |||
| 60 | } // end namespace tooling |
||
| 61 | } // end namespace clang |
||
| 62 | |||
| 63 | #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H |