1 //===--- ASTSelectionRequirements.cpp - 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 #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
10 #include "clang/AST/Attr.h"
13 using namespace clang
;
14 using namespace tooling
;
16 Expected
<SelectedASTNode
>
17 ASTSelectionRequirement::evaluate(RefactoringRuleContext
&Context
) const {
18 // FIXME: Memoize so that selection is evaluated only once.
19 Expected
<SourceRange
> Range
=
20 SourceRangeSelectionRequirement::evaluate(Context
);
22 return Range
.takeError();
24 std::optional
<SelectedASTNode
> Selection
=
25 findSelectedASTNodes(Context
.getASTContext(), *Range
);
27 return Context
.createDiagnosticError(
28 Range
->getBegin(), diag::err_refactor_selection_invalid_ast
);
29 return std::move(*Selection
);
32 Expected
<CodeRangeASTSelection
> CodeRangeASTSelectionRequirement::evaluate(
33 RefactoringRuleContext
&Context
) const {
34 // FIXME: Memoize so that selection is evaluated only once.
35 Expected
<SelectedASTNode
> ASTSelection
=
36 ASTSelectionRequirement::evaluate(Context
);
38 return ASTSelection
.takeError();
39 std::unique_ptr
<SelectedASTNode
> StoredSelection
=
40 std::make_unique
<SelectedASTNode
>(std::move(*ASTSelection
));
41 std::optional
<CodeRangeASTSelection
> CodeRange
=
42 CodeRangeASTSelection::create(Context
.getSelectionRange(),
45 return Context
.createDiagnosticError(
46 Context
.getSelectionRange().getBegin(),
47 diag::err_refactor_selection_invalid_ast
);
48 Context
.setASTSelection(std::move(StoredSelection
));
49 return std::move(*CodeRange
);