clang 10.0.0git

RefactoringOptions.h
Go to the documentation of this file.
1 //===--- RefactoringOptions.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_OPTIONS_H
10 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
11
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>
18
19 namespace clang {
20 namespace tooling {
21
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 {
26 public:
27 void passToVisitor(RefactoringOptionVisitor &Visitor) final override {
28 Visitor.visit(*this, Value);
29 }
30
31 bool isRequired() const override { return false; }
32
33 using ValueType = Optional<T>;
34
35 const ValueType &getValue() const { return Value; }
36
37 protected:
38 Optional<T> Value;
39 };
40
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> {
45 public:
46 using ValueType = T;
47
48 const ValueType &getValue() const {
49 return *OptionalRefactoringOption<T>::Value;
50 }
51 bool isRequired() const final override { return true; }
52 };
53
54 } // end namespace tooling
55 } // end namespace clang
56
57 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
clang::tooling::RefactoringOptionVisitor
An interface that declares functions that handle different refactoring option types.
Definition: RefactoringOptionVisitor.h:25
clang::tooling::RequiredRefactoringOption::isRequired
bool isRequired() const final override
True when this option must be specified before invoking the refactoring action.
Definition: RefactoringOptions.h:51
clang::tooling::OptionalRefactoringOption< T >::ValueType
Optional< T > ValueType
Definition: RefactoringOptions.h:33
clang::tooling::OptionalRefactoringOption::isRequired
bool isRequired() const override
True when this option must be specified before invoking the refactoring action.
Definition: RefactoringOptions.h:31
Value
Value
Definition: UninitializedValues.cpp:101
llvm::Optional
Definition: LLVM.h:37
RefactoringOption.h
clang::tooling::OptionalRefactoringOption::getValue
const ValueType & getValue() const
Definition: RefactoringOptions.h:35
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::tooling::OptionalRefactoringOption
A refactoring option that stores a value of type T.
Definition: RefactoringOptions.h:25
clang::tooling::RequiredRefactoringOption::getValue
const ValueType & getValue() const
Definition: RefactoringOptions.h:48
clang::tooling::OptionalRefactoringOption::Value
Optional< T > Value
Definition: RefactoringOptions.h:38
clang::tooling::RequiredRefactoringOption::ValueType
T ValueType
Definition: RefactoringOptions.h:46
RefactoringOptionVisitor.h
clang::tooling::traits::IsValidOptionType
A type trait that returns true iff the given type is a type that can be stored in a refactoring optio...
Definition: RefactoringOptionVisitor.h:55
clang::tooling::RefactoringOption
A refactoring option is an interface that describes a value that has an impact on the outcome of a re...
Definition: RefactoringOption.h:26
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
type
clang::tooling::OptionalRefactoringOption::passToVisitor
void passToVisitor(RefactoringOptionVisitor &Visitor) final override
Invokes the visit method in the option consumer that&#39;s appropriate for the option&#39;s value type...
Definition: RefactoringOptions.h:27
clang::tooling::RequiredRefactoringOption
A required refactoring option that stores a value of type T.
Definition: RefactoringOptions.h:44
RefactoringActionRuleRequirements.h