1 //===--- RefactoringOptions.h - Clang refactoring library -----------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
10 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
12 #include "clang/Basic/LLVM.h"
13 #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
14 #include "clang/Tooling/Refactoring/RefactoringOption.h"
15 #include "clang/Tooling/Refactoring/RefactoringOptionVisitor.h"
16 #include "llvm/Support/Error.h"
17 #include <type_traits>
22 /// A refactoring option that stores a value of type \c T.
23 template <typename T, typename = typename std::enable_if<
24 traits::IsValidOptionType<T>::value>::type>
25 class OptionalRefactoringOption : public RefactoringOption {
27 void passToVisitor(RefactoringOptionVisitor &Visitor) final override {
28 Visitor.visit(*this, Value);
31 bool isRequired() const override { return false; }
33 using ValueType = Optional<T>;
35 const ValueType &getValue() const { return Value; }
41 /// A required refactoring option that stores a value of type \c T.
42 template <typename T, typename = typename std::enable_if<
43 traits::IsValidOptionType<T>::value>::type>
44 class RequiredRefactoringOption : public OptionalRefactoringOption<T> {
48 const ValueType &getValue() const {
49 return *OptionalRefactoringOption<T>::Value;
51 bool isRequired() const final override { return true; }
54 } // end namespace tooling
55 } // end namespace clang
57 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H