summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/RefactoringActionRulesTest.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-10-27 18:19:11 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-10-27 18:19:11 +0000
commit0beca4d1ecd6b20abd8be8ee4f46783128a009b4 (patch)
treeecf2e7402ff710bb7816bfbd4ddb935776019785 /clang/unittests/Tooling/RefactoringActionRulesTest.cpp
parent1bfaa453a32189e6b570ab9ac9781f0101dca66d (diff)
downloadbcm5719-llvm-0beca4d1ecd6b20abd8be8ee4f46783128a009b4.tar.gz
bcm5719-llvm-0beca4d1ecd6b20abd8be8ee4f46783128a009b4.zip
[refactor] Describe refactorings in the operation classes
This commit changes the way that the refactoring operation classes are structured: - Users have to call `initiate` instead of constructing an instance of the class. The `initiate` is now supposed to have custom initiation logic, and you don't need to subclass the builtin requirements. - A new `describe` function returns a structure with the id, title and the description of the refactoring operation. The refactoring action classes are now placed into one common place in RefactoringActions.cpp instead of being separate. Differential Revision: https://reviews.llvm.org/D38985 llvm-svn: 316780
Diffstat (limited to 'clang/unittests/Tooling/RefactoringActionRulesTest.cpp')
-rw-r--r--clang/unittests/Tooling/RefactoringActionRulesTest.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/RefactoringActionRulesTest.cpp b/clang/unittests/Tooling/RefactoringActionRulesTest.cpp
index 132a3a44963..f0b6466fec4 100644
--- a/clang/unittests/Tooling/RefactoringActionRulesTest.cpp
+++ b/clang/unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -10,7 +10,8 @@
#include "ReplacementTest.h"
#include "RewriterTestContext.h"
#include "clang/Tooling/Refactoring.h"
-#include "clang/Tooling/Refactoring/RefactoringActionRules.h"
+#include "clang/Tooling/Refactoring/Extract/Extract.h"
+#include "clang/Tooling/Refactoring/RefactoringAction.h"
#include "clang/Tooling/Refactoring/RefactoringDiagnostic.h"
#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
#include "clang/Tooling/Tooling.h"
@@ -63,6 +64,12 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
ReplaceAWithB(std::pair<SourceRange, int> Selection)
: Selection(Selection) {}
+ static Expected<ReplaceAWithB>
+ initiate(RefactoringRuleContext &Cotnext,
+ std::pair<SourceRange, int> Selection) {
+ return ReplaceAWithB(Selection);
+ }
+
Expected<AtomicChanges>
createSourceReplacements(RefactoringRuleContext &Context) {
const SourceManager &SM = Context.getSources();
@@ -141,6 +148,11 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
TEST_F(RefactoringActionRulesTest, ReturnError) {
class ErrorRule : public SourceChangeRefactoringRule {
public:
+ static Expected<ErrorRule> initiate(RefactoringRuleContext &,
+ SourceRange R) {
+ return ErrorRule(R);
+ }
+
ErrorRule(SourceRange R) {}
Expected<AtomicChanges> createSourceReplacements(RefactoringRuleContext &) {
return llvm::make_error<llvm::StringError>(
@@ -191,6 +203,11 @@ TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) {
public:
FindOccurrences(SourceRange Selection) : Selection(Selection) {}
+ static Expected<FindOccurrences> initiate(RefactoringRuleContext &,
+ SourceRange Selection) {
+ return FindOccurrences(Selection);
+ }
+
Expected<SymbolOccurrences>
findSymbolOccurrences(RefactoringRuleContext &) override {
SymbolOccurrences Occurrences;
@@ -219,4 +236,13 @@ TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) {
SourceRange(Cursor, Cursor.getLocWithOffset(strlen("test"))));
}
+TEST_F(RefactoringActionRulesTest, EditorCommandBinding) {
+ const RefactoringDescriptor &Descriptor = ExtractFunction::describe();
+ EXPECT_EQ(Descriptor.Name, "extract-function");
+ EXPECT_EQ(
+ Descriptor.Description,
+ "(WIP action; use with caution!) Extracts code into a new function");
+ EXPECT_EQ(Descriptor.Title, "Extract Function");
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud