1 //===--- ASTSelectionRequirements.cpp - Clang refactoring library ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
12 using namespace clang;
13 using namespace tooling;
15 Expected<SelectedASTNode>
16 ASTSelectionRequirement::evaluate(RefactoringRuleContext &Context) const {
17 // FIXME: Memoize so that selection is evaluated only once.
18 Expected<SourceRange> Range =
19 SourceRangeSelectionRequirement::evaluate(Context);
21 return Range.takeError();
23 Optional<SelectedASTNode> Selection =
24 findSelectedASTNodes(Context.getASTContext(), *Range);
26 return Context.createDiagnosticError(
27 Range->getBegin(), diag::err_refactor_selection_invalid_ast);
28 return std::move(*Selection);
31 Expected<CodeRangeASTSelection> CodeRangeASTSelectionRequirement::evaluate(
32 RefactoringRuleContext &Context) const {
33 // FIXME: Memoize so that selection is evaluated only once.
34 Expected<SelectedASTNode> ASTSelection =
35 ASTSelectionRequirement::evaluate(Context);
37 return ASTSelection.takeError();
38 std::unique_ptr<SelectedASTNode> StoredSelection =
39 llvm::make_unique<SelectedASTNode>(std::move(*ASTSelection));
40 Optional<CodeRangeASTSelection> CodeRange = CodeRangeASTSelection::create(
41 Context.getSelectionRange(), *StoredSelection);
43 return Context.createDiagnosticError(
44 Context.getSelectionRange().getBegin(),
45 diag::err_refactor_selection_invalid_ast);
46 Context.setASTSelection(std::move(StoredSelection));
47 return std::move(*CodeRange);