1 //===--- RefactoringOptionVisitor.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_REFACTORINGOPTIONVISITOR_H
10 #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTIONVISITOR_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include <type_traits>
14 
15 namespace clang {
16 namespace tooling {
17 
18 class RefactoringOption;
19 
20 /// An interface that declares functions that handle different refactoring
21 /// option types.
22 ///
23 /// A valid refactoring option type must have a corresponding \c visit
24 /// declaration in this interface.
25 class RefactoringOptionVisitor {
26 public:
27   virtual ~RefactoringOptionVisitor() {}
28 
29   virtual void visit(const RefactoringOption &Opt,
30                      Optional<std::string> &Value) = 0;
31 };
32 
33 namespace traits {
34 namespace internal {
35 
36 template <typename T> struct HasHandle {
37 private:
38   template <typename ClassT>
39   static auto check(ClassT *) -> typename std::is_same<
40       decltype(std::declval<RefactoringOptionVisitor>().visit(
41           std::declval<RefactoringOption>(), *std::declval<Optional<T> *>())),
42       void>::type;
43 
44   template <typename> static std::false_type check(...);
45 
46 public:
47   using Type = decltype(check<RefactoringOptionVisitor>(nullptr));
48 };
49 
50 } // end namespace internal
51 
52 /// A type trait that returns true iff the given type is a type that can be
53 /// stored in a refactoring option.
54 template <typename T>
55 struct IsValidOptionType : internal::HasHandle<T>::Type {};
56 
57 } // end namespace traits
58 } // end namespace tooling
59 } // end namespace clang
60 
61 #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTIONVISITOR_H
62