Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 1 | //===--- Extract.h - Clang refactoring library ----------------------------===// |
| 2 | // |
||
| 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 |
||
| 6 | // |
||
| 7 | //===----------------------------------------------------------------------===// |
||
| 8 | |||
| 9 | #ifndef LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_EXTRACT_H |
||
| 10 | #define LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_EXTRACT_H |
||
| 11 | |||
| 12 | #include "clang/Tooling/Refactoring/ASTSelection.h" |
||
| 13 | #include "clang/Tooling/Refactoring/RefactoringActionRules.h" |
||
| 14 | #include <optional> |
||
| 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 of the extract function. If None, |
||
| 27 | /// "extracted" is used. |
||
| 28 | static Expected<ExtractFunction> |
||
| 29 | initiate(RefactoringRuleContext &Context, CodeRangeASTSelection Code, |
||
| 30 | std::optional<std::string> DeclName); |
||
| 31 | |||
| 32 | static const RefactoringDescriptor &describe(); |
||
| 33 | |||
| 34 | private: |
||
| 35 | ExtractFunction(CodeRangeASTSelection Code, |
||
| 36 | std::optional<std::string> DeclName) |
||
| 37 | : Code(std::move(Code)), |
||
| 38 | DeclName(DeclName ? std::move(*DeclName) : "extracted") {} |
||
| 39 | |||
| 40 | Expected<AtomicChanges> |
||
| 41 | createSourceReplacements(RefactoringRuleContext &Context) override; |
||
| 42 | |||
| 43 | CodeRangeASTSelection Code; |
||
| 44 | |||
| 45 | // FIXME: Account for naming collisions: |
||
| 46 | // - error when name is specified by user. |
||
| 47 | // - rename to "extractedN" when name is implicit. |
||
| 48 | std::string DeclName; |
||
| 49 | }; |
||
| 50 | |||
| 51 | } // end namespace tooling |
||
| 52 | } // end namespace clang |
||
| 53 | |||
| 54 | #endif // LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_EXTRACT_H |