clang 19.0.0git
Extract.h
Go to the documentation of this file.
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
14#include <optional>
15
16namespace clang {
17namespace 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.
22public:
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.
30 std::optional<std::string> DeclName);
31
32 static const RefactoringDescriptor &describe();
33
34private:
36 std::optional<std::string> DeclName)
37 : Code(std::move(Code)),
38 DeclName(DeclName ? std::move(*DeclName) : "extracted") {}
39
41 createSourceReplacements(RefactoringRuleContext &Context) override;
42
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
An AST selection value that corresponds to a selection of a set of statements that belong to one body...
Definition: ASTSelection.h:96
An "Extract Function" refactoring moves code into a new function that's then called from the place wh...
Definition: Extract.h:21
static Expected< ExtractFunction > initiate(RefactoringRuleContext &Context, CodeRangeASTSelection Code, std::optional< std::string > DeclName)
Initiates the extract function refactoring operation.
Definition: Extract.cpp:70
static const RefactoringDescriptor & describe()
Definition: Extract.cpp:60
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
A type of refactoring action rule that produces source replacements in the form of atomic changes.
The JSON file list parser is used to communicate input to InstallAPI.