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