clang 8.0.0

RefactoringOptions.h
Go to the documentation of this file.
1 //===--- RefactoringOptions.h - Clang refactoring library -----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
11 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTIONS_H
12
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
15 #include "clang/Tooling/Refactoring/RefactoringOption.h"
16 #include "clang/Tooling/Refactoring/RefactoringOptionVisitor.h"
17 #include "llvm/Support/Error.h"
18 #include <type_traits>
19
20 namespace clang {
21 namespace tooling {
22
23 /// A refactoring option that stores a value of type \c T.
24 template <typename T, typename = typename std::enable_if<
25 traits::IsValidOptionType<T>::value>::type>
26 class OptionalRefactoringOption : public RefactoringOption {
27 public:
28 void passToVisitor(RefactoringOptionVisitor &Visitor) final override {
29 Visitor.visit(*this, Value);
30 }
31
32 bool isRequired() const override { return false; }
33
34 using ValueType = Optional<T>;
35
36 const ValueType &getValue() const { return Value; }
37
38 protected:
39 Optional<T> Value;
40 };
41
42 /// A required refactoring option that stores a value of type \c T.
43 template <typename T, typename = typename std::enable_if<
44 traits::IsValidOptionType<T>::value>::type>
45 class RequiredRefactoringOption : public OptionalRefactoringOption<T> {
46 public:
47 using ValueType = T;
48
49 const ValueType &getValue() const {
50 return *OptionalRefactoringOption<T>::Value;
51 }
52 bool isRequired() const final override { return true; }
53 };
54
55 } // end namespace tooling
56 } // end namespace clang
57
58 #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:26
clang::tooling::RequiredRefactoringOption::isRequired
bool isRequired() const final override
True when this option must be specified before invoking the refactoring action.
Definition: RefactoringOptions.h:52
clang::tooling::OptionalRefactoringOption< T >::ValueType
Optional< T > ValueType
Definition: RefactoringOptions.h:34
clang::tooling::OptionalRefactoringOption::isRequired
bool isRequired() const override
True when this option must be specified before invoking the refactoring action.
Definition: RefactoringOptions.h:32
Value
Value
Definition: UninitializedValues.cpp:102
llvm::Optional
Definition: LLVM.h:38
RefactoringOption.h
clang::tooling::OptionalRefactoringOption::getValue
const ValueType & getValue() const
Definition: RefactoringOptions.h:36
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:26
clang::tooling::RequiredRefactoringOption::getValue
const ValueType & getValue() const
Definition: RefactoringOptions.h:49
clang::tooling::OptionalRefactoringOption::Value
Optional< T > Value
Definition: RefactoringOptions.h:39
clang::tooling::RequiredRefactoringOption::ValueType
T ValueType
Definition: RefactoringOptions.h:47
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:56
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:27
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
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:28
clang::tooling::RequiredRefactoringOption
A required refactoring option that stores a value of type T.
Definition: RefactoringOptions.h:45
RefactoringActionRuleRequirements.h