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_REFACTOR_REFACTORING_OPTION_VISITOR_H
10#define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_VISITOR_H
11
12#include "clang/Basic/LLVM.h"
13#include <type_traits>
14
15namespace clang {
16namespace tooling {
17
18class 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.
25class RefactoringOptionVisitor {
26public:
27  virtual ~RefactoringOptionVisitor() {}
28
29  virtual void visit(const RefactoringOption &Opt,
30                     Optional<std::string> &Value) = 0;
31};
32
33namespace traits {
34namespace internal {
35
36template <typename T> struct HasHandle {
37private:
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
46public:
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.
54template <typename T>
55struct IsValidOptionType : internal::HasHandle<T>::Type {};
56
57} // end namespace traits
58} // end namespace tooling
59} // end namespace clang
60
61#endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_VISITOR_H
62