1 //===--- Extract.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_EXTRACT_EXTRACT_H 11 #define LLVM_CLANG_TOOLING_REFACTOR_EXTRACT_EXTRACT_H 12 13 #include "clang/Tooling/Refactoring/ASTSelection.h" 14 #include "clang/Tooling/Refactoring/RefactoringActionRules.h" 15 16 namespace clang { 17 namespace tooling { 18 19 /// An "Extract Function" refactoring moves code into a new function that's 20 /// then called from the place where the original code was. 21 class ExtractFunction final : public SourceChangeRefactoringRule { 22 public: 23 /// Initiates the extract function refactoring operation. 24 /// 25 /// \param Code The selected set of statements. 26 /// \param DeclName The name name of the extract function. If None, 27 /// "extracted" is used. 28 static Expected<ExtractFunction> initiate(RefactoringRuleContext &Context, 29 CodeRangeASTSelection Code, 30 Optional<std::string> DeclName); 31 32 static const RefactoringDescriptor &describe(); 33 34 private: ExtractFunction(CodeRangeASTSelection Code,Optional<std::string> DeclName)35 ExtractFunction(CodeRangeASTSelection Code, Optional<std::string> DeclName) 36 : Code(std::move(Code)), 37 DeclName(DeclName ? std::move(*DeclName) : "extracted") {} 38 39 Expected<AtomicChanges> 40 createSourceReplacements(RefactoringRuleContext &Context) override; 41 42 CodeRangeASTSelection Code; 43 44 // FIXME: Account for naming collisions: 45 // - error when name is specified by user. 46 // - rename to "extractedN" when name is implicit. 47 std::string DeclName; 48 }; 49 50 } // end namespace tooling 51 } // end namespace clang 52 53 #endif // LLVM_CLANG_TOOLING_REFACTOR_EXTRACT_EXTRACT_H 54