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"
11 using namespace clang;
12 using namespace tooling;
14 Expected<SelectedASTNode>
15 ASTSelectionRequirement::evaluate(RefactoringRuleContext &Context) const {
16 // FIXME: Memoize so that selection is evaluated only once.
17 Expected<SourceRange> Range =
18 SourceRangeSelectionRequirement::evaluate(Context);
20 return Range.takeError();
22 Optional<SelectedASTNode> Selection =
23 findSelectedASTNodes(Context.getASTContext(), *Range);
25 return Context.createDiagnosticError(
26 Range->getBegin(), diag::err_refactor_selection_invalid_ast);
27 return std::move(*Selection);
30 Expected<CodeRangeASTSelection> CodeRangeASTSelectionRequirement::evaluate(
31 RefactoringRuleContext &Context) const {
32 // FIXME: Memoize so that selection is evaluated only once.
33 Expected<SelectedASTNode> ASTSelection =
34 ASTSelectionRequirement::evaluate(Context);
36 return ASTSelection.takeError();
37 std::unique_ptr<SelectedASTNode> StoredSelection =
38 llvm::make_unique<SelectedASTNode>(std::move(*ASTSelection));
39 Optional<CodeRangeASTSelection> CodeRange = CodeRangeASTSelection::create(
40 Context.getSelectionRange(), *StoredSelection);
42 return Context.createDiagnosticError(
43 Context.getSelectionRange().getBegin(),
44 diag::err_refactor_selection_invalid_ast);
45 Context.setASTSelection(std::move(StoredSelection));
46 return std::move(*CodeRange);