Path: blob/main/contrib/llvm-project/clang/lib/Tooling/Refactoring/RefactoringActions.cpp
35271 views
//===--- RefactoringActions.cpp - Constructs refactoring actions ----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Tooling/Refactoring/Extract/Extract.h"9#include "clang/Tooling/Refactoring/RefactoringAction.h"10#include "clang/Tooling/Refactoring/RefactoringOptions.h"11#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"1213namespace clang {14namespace tooling {1516namespace {1718class DeclNameOption final : public OptionalRefactoringOption<std::string> {19public:20StringRef getName() const override { return "name"; }21StringRef getDescription() const override {22return "Name of the extracted declaration";23}24};2526// FIXME: Rewrite the Actions to avoid duplication of descriptions/names with27// rules.28class ExtractRefactoring final : public RefactoringAction {29public:30StringRef getCommand() const override { return "extract"; }3132StringRef getDescription() const override {33return "(WIP action; use with caution!) Extracts code into a new function";34}3536/// Returns a set of refactoring actions rules that are defined by this37/// action.38RefactoringActionRules createActionRules() const override {39RefactoringActionRules Rules;40Rules.push_back(createRefactoringActionRule<ExtractFunction>(41CodeRangeASTSelectionRequirement(),42OptionRequirement<DeclNameOption>()));43return Rules;44}45};4647class OldQualifiedNameOption : public RequiredRefactoringOption<std::string> {48public:49StringRef getName() const override { return "old-qualified-name"; }50StringRef getDescription() const override {51return "The old qualified name to be renamed";52}53};5455class NewQualifiedNameOption : public RequiredRefactoringOption<std::string> {56public:57StringRef getName() const override { return "new-qualified-name"; }58StringRef getDescription() const override {59return "The new qualified name to change the symbol to";60}61};6263class NewNameOption : public RequiredRefactoringOption<std::string> {64public:65StringRef getName() const override { return "new-name"; }66StringRef getDescription() const override {67return "The new name to change the symbol to";68}69};7071// FIXME: Rewrite the Actions to avoid duplication of descriptions/names with72// rules.73class LocalRename final : public RefactoringAction {74public:75StringRef getCommand() const override { return "local-rename"; }7677StringRef getDescription() const override {78return "Finds and renames symbols in code with no indexer support";79}8081/// Returns a set of refactoring actions rules that are defined by this82/// action.83RefactoringActionRules createActionRules() const override {84RefactoringActionRules Rules;85Rules.push_back(createRefactoringActionRule<RenameOccurrences>(86SourceRangeSelectionRequirement(), OptionRequirement<NewNameOption>()));87// FIXME: Use NewNameOption.88Rules.push_back(createRefactoringActionRule<QualifiedRenameRule>(89OptionRequirement<OldQualifiedNameOption>(),90OptionRequirement<NewQualifiedNameOption>()));91return Rules;92}93};9495} // end anonymous namespace9697std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions() {98std::vector<std::unique_ptr<RefactoringAction>> Actions;99100Actions.push_back(std::make_unique<LocalRename>());101Actions.push_back(std::make_unique<ExtractRefactoring>());102103return Actions;104}105106RefactoringActionRules RefactoringAction::createActiveActionRules() {107// FIXME: Filter out rules that are not supported by a particular client.108return createActionRules();109}110111} // end namespace tooling112} // end namespace clang113114115