1 //===--- RefactoringOption.h - Clang refactoring library ------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_H
10 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_H
12 #include "clang/Basic/LLVM.h"
14 #include <type_traits>
19 class RefactoringOptionVisitor;
21 /// A refactoring option is an interface that describes a value that
22 /// has an impact on the outcome of a refactoring.
24 /// Refactoring options can be specified using command-line arguments when
25 /// the clang-refactor tool is used.
26 class RefactoringOption {
28 virtual ~RefactoringOption() {}
30 /// Returns the name of the refactoring option.
32 /// Each refactoring option must have a unique name.
33 virtual StringRef getName() const = 0;
35 virtual StringRef getDescription() const = 0;
37 /// True when this option must be specified before invoking the refactoring
39 virtual bool isRequired() const = 0;
41 /// Invokes the \c visit method in the option consumer that's appropriate
42 /// for the option's value type.
44 /// For example, if the option stores a string value, this method will
45 /// invoke the \c visit method with a reference to an std::string value.
46 virtual void passToVisitor(RefactoringOptionVisitor &Visitor) = 0;
49 /// Constructs a refactoring option of the given type.
51 /// The ownership of options is shared among requirements that use it because
52 /// one option can be used by multiple rules in a refactoring action.
53 template <typename OptionType>
54 std::shared_ptr<OptionType> createRefactoringOption() {
55 static_assert(std::is_base_of<RefactoringOption, OptionType>::value,
56 "invalid option type");
57 return std::make_shared<OptionType>();
60 } // end namespace tooling
61 } // end namespace clang
63 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_OPTION_H