clang  6.0.0svn
RefactoringOption.h
Go to the documentation of this file.
1 //===--- RefactoringOption.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_OPTION_H
11 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_H
12 
13 #include "clang/Basic/LLVM.h"
14 #include <memory>
15 #include <type_traits>
16 
17 namespace clang {
18 namespace tooling {
19 
20 class RefactoringOptionVisitor;
21 
22 /// A refactoring option is an interface that describes a value that
23 /// has an impact on the outcome of a refactoring.
24 ///
25 /// Refactoring options can be specified using command-line arguments when
26 /// the clang-refactor tool is used.
28 public:
29  virtual ~RefactoringOption() {}
30 
31  /// Returns the name of the refactoring option.
32  ///
33  /// Each refactoring option must have a unique name.
34  virtual StringRef getName() const = 0;
35 
36  virtual StringRef getDescription() const = 0;
37 
38  /// True when this option must be specified before invoking the refactoring
39  /// action.
40  virtual bool isRequired() const = 0;
41 
42  /// Invokes the \c visit method in the option consumer that's appropriate
43  /// for the option's value type.
44  ///
45  /// For example, if the option stores a string value, this method will
46  /// invoke the \c visit method with a reference to an std::string value.
47  virtual void passToVisitor(RefactoringOptionVisitor &Visitor) = 0;
48 };
49 
50 /// Constructs a refactoring option of the given type.
51 ///
52 /// The ownership of options is shared among requirements that use it because
53 /// one option can be used by multiple rules in a refactoring action.
54 template <typename OptionType>
55 std::shared_ptr<OptionType> createRefactoringOption() {
56  static_assert(std::is_base_of<RefactoringOption, OptionType>::value,
57  "invalid option type");
58  return std::make_shared<OptionType>();
59 }
60 
61 } // end namespace tooling
62 } // end namespace clang
63 
64 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_H
An interface that declares functions that handle different refactoring option types.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
virtual bool isRequired() const =0
True when this option must be specified before invoking the refactoring action.
virtual StringRef getName() const =0
Returns the name of the refactoring option.
virtual StringRef getDescription() const =0
virtual void passToVisitor(RefactoringOptionVisitor &Visitor)=0
Invokes the visit method in the option consumer that&#39;s appropriate for the option&#39;s value type...
A refactoring option is an interface that describes a value that has an impact on the outcome of a re...
Dataflow Directional Tag Classes.
std::shared_ptr< OptionType > createRefactoringOption()
Constructs a refactoring option of the given type.