Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:11

0001 //===--- RefactoringOption.h - Clang refactoring library ------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H
0010 #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H
0011 
0012 #include "clang/Basic/LLVM.h"
0013 #include <memory>
0014 #include <type_traits>
0015 
0016 namespace clang {
0017 namespace tooling {
0018 
0019 class RefactoringOptionVisitor;
0020 
0021 /// A refactoring option is an interface that describes a value that
0022 /// has an impact on the outcome of a refactoring.
0023 ///
0024 /// Refactoring options can be specified using command-line arguments when
0025 /// the clang-refactor tool is used.
0026 class RefactoringOption {
0027 public:
0028   virtual ~RefactoringOption() {}
0029 
0030   /// Returns the name of the refactoring option.
0031   ///
0032   /// Each refactoring option must have a unique name.
0033   virtual StringRef getName() const = 0;
0034 
0035   virtual StringRef getDescription() const = 0;
0036 
0037   /// True when this option must be specified before invoking the refactoring
0038   /// action.
0039   virtual bool isRequired() const = 0;
0040 
0041   /// Invokes the \c visit method in the option consumer that's appropriate
0042   /// for the option's value type.
0043   ///
0044   /// For example, if the option stores a string value, this method will
0045   /// invoke the \c visit method with a reference to an std::string value.
0046   virtual void passToVisitor(RefactoringOptionVisitor &Visitor) = 0;
0047 };
0048 
0049 /// Constructs a refactoring option of the given type.
0050 ///
0051 /// The ownership of options is shared among requirements that use it because
0052 /// one option can be used by multiple rules in a refactoring action.
0053 template <typename OptionType>
0054 std::shared_ptr<OptionType> createRefactoringOption() {
0055   static_assert(std::is_base_of<RefactoringOption, OptionType>::value,
0056                 "invalid option type");
0057   return std::make_shared<OptionType>();
0058 }
0059 
0060 } // end namespace tooling
0061 } // end namespace clang
0062 
0063 #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTION_H