Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Refactoring/RefactoringActions.cpp
Line
Count
Source
1
//===--- RefactoringActions.cpp - Constructs refactoring actions ----------===//
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
#include "clang/Tooling/Refactoring/Extract/Extract.h"
10
#include "clang/Tooling/Refactoring/RefactoringAction.h"
11
#include "clang/Tooling/Refactoring/RefactoringOptions.h"
12
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
13
14
namespace clang {
15
namespace tooling {
16
17
namespace {
18
19
class DeclNameOption final : public OptionalRefactoringOption<std::string> {
20
public:
21
38
  StringRef getName() const override { return "name"; }
22
19
  StringRef getDescription() const override {
23
19
    return "Name of the extracted declaration";
24
19
  }
25
};
26
27
// FIXME: Rewrite the Actions to avoid duplication of descriptions/names with
28
// rules.
29
class ExtractRefactoring final : public RefactoringAction {
30
public:
31
38
  StringRef getCommand() const override { return "extract"; }
32
33
19
  StringRef getDescription() const override {
34
19
    return "(WIP action; use with caution!) Extracts code into a new function";
35
19
  }
36
37
  /// Returns a set of refactoring actions rules that are defined by this
38
  /// action.
39
19
  RefactoringActionRules createActionRules() const override {
40
19
    RefactoringActionRules Rules;
41
19
    Rules.push_back(createRefactoringActionRule<ExtractFunction>(
42
19
        CodeRangeASTSelectionRequirement(),
43
19
        OptionRequirement<DeclNameOption>()));
44
19
    return Rules;
45
19
  }
46
};
47
48
class OldQualifiedNameOption : public RequiredRefactoringOption<std::string> {
49
public:
50
49
  StringRef getName() const override { return "old-qualified-name"; }
51
19
  StringRef getDescription() const override {
52
19
    return "The old qualified name to be renamed";
53
19
  }
54
};
55
56
class NewQualifiedNameOption : public RequiredRefactoringOption<std::string> {
57
public:
58
49
  StringRef getName() const override { return "new-qualified-name"; }
59
19
  StringRef getDescription() const override {
60
19
    return "The new qualified name to change the symbol to";
61
19
  }
62
};
63
64
class NewNameOption : public RequiredRefactoringOption<std::string> {
65
public:
66
39
  StringRef getName() const override { return "new-name"; }
67
19
  StringRef getDescription() const override {
68
19
    return "The new name to change the symbol to";
69
19
  }
70
};
71
72
// FIXME: Rewrite the Actions to avoid duplication of descriptions/names with
73
// rules.
74
class LocalRename final : public RefactoringAction {
75
public:
76
38
  StringRef getCommand() const override { return "local-rename"; }
77
78
19
  StringRef getDescription() const override {
79
19
    return "Finds and renames symbols in code with no indexer support";
80
19
  }
81
82
  /// Returns a set of refactoring actions rules that are defined by this
83
  /// action.
84
19
  RefactoringActionRules createActionRules() const override {
85
19
    RefactoringActionRules Rules;
86
19
    Rules.push_back(createRefactoringActionRule<RenameOccurrences>(
87
19
        SourceRangeSelectionRequirement(), OptionRequirement<NewNameOption>()));
88
    // FIXME: Use NewNameOption.
89
19
    Rules.push_back(createRefactoringActionRule<QualifiedRenameRule>(
90
19
        OptionRequirement<OldQualifiedNameOption>(),
91
19
        OptionRequirement<NewQualifiedNameOption>()));
92
19
    return Rules;
93
19
  }
94
};
95
96
} // end anonymous namespace
97
98
19
std::vector<std::unique_ptr<RefactoringAction>> createRefactoringActions() {
99
19
  std::vector<std::unique_ptr<RefactoringAction>> Actions;
100
19
101
19
  Actions.push_back(std::make_unique<LocalRename>());
102
19
  Actions.push_back(std::make_unique<ExtractRefactoring>());
103
19
104
19
  return Actions;
105
19
}
106
107
38
RefactoringActionRules RefactoringAction::createActiveActionRules() {
108
  // FIXME: Filter out rules that are not supported by a particular client.
109
38
  return createActionRules();
110
38
}
111
112
} // end namespace tooling
113
} // end namespace clang