Skip to content

Commit 563674f

Browse files
committed
[Refactoring] Move ExtractExpr to its own file
1 parent 98f4019 commit 563674f

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

lib/Refactoring/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ add_swift_host_library(swiftRefactoring STATIC
55
ConvertIfLetExprToGuardExpr.cpp
66
ConvertToSwitchStmt.cpp
77
ConvertToTernaryExpr.cpp
8+
ExtractExpr.cpp
9+
ExtractExprBase.cpp
810
ExtractRepeatedExpr.cpp
911
ExtractFunction.cpp
1012
MoveMembersToExtension.cpp
1113
Refactoring.cpp
1214
Renamer.cpp
13-
ExtractExprBase.cpp
1415
ReplaceBodiesWithFatalError.cpp
1516
Utils.cpp
1617
)

lib/Refactoring/ExtractExpr.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "ExtractExprBase.h"
14+
#include "RefactoringActions.h"
15+
16+
using namespace swift::refactoring;
17+
18+
bool RefactoringActionExtractExpr::isApplicable(const ResolvedRangeInfo &Info,
19+
DiagnosticEngine &Diag) {
20+
switch (Info.Kind) {
21+
case RangeKind::SingleExpression:
22+
// We disallow extract literal expression for two reasons:
23+
// (1) since we print the type for extracted expression, the type of a
24+
// literal may print as "int2048" where it is not typically users' choice;
25+
// (2) Extracting one literal provides little value for users.
26+
return checkExtractConditions(Info, Diag).success();
27+
case RangeKind::PartOfExpression:
28+
case RangeKind::SingleDecl:
29+
case RangeKind::MultiTypeMemberDecl:
30+
case RangeKind::SingleStatement:
31+
case RangeKind::MultiStatement:
32+
case RangeKind::Invalid:
33+
return false;
34+
}
35+
llvm_unreachable("unhandled kind");
36+
}
37+
38+
bool RefactoringActionExtractExpr::performChange() {
39+
return RefactoringActionExtractExprBase(TheFile, RangeInfo, DiagEngine, false,
40+
PreferredName, EditConsumer)
41+
.performChange();
42+
}

lib/Refactoring/Refactoring.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -545,32 +545,6 @@ StringRef getDefaultPreferredName(RefactoringKind Kind) {
545545
}
546546
}
547547

548-
bool RefactoringActionExtractExpr::
549-
isApplicable(const ResolvedRangeInfo &Info, DiagnosticEngine &Diag) {
550-
switch (Info.Kind) {
551-
case RangeKind::SingleExpression:
552-
// We disallow extract literal expression for two reasons:
553-
// (1) since we print the type for extracted expression, the type of a
554-
// literal may print as "int2048" where it is not typically users' choice;
555-
// (2) Extracting one literal provides little value for users.
556-
return checkExtractConditions(Info, Diag).success();
557-
case RangeKind::PartOfExpression:
558-
case RangeKind::SingleDecl:
559-
case RangeKind::MultiTypeMemberDecl:
560-
case RangeKind::SingleStatement:
561-
case RangeKind::MultiStatement:
562-
case RangeKind::Invalid:
563-
return false;
564-
}
565-
llvm_unreachable("unhandled kind");
566-
}
567-
568-
bool RefactoringActionExtractExpr::performChange() {
569-
return RefactoringActionExtractExprBase(TheFile, RangeInfo,
570-
DiagEngine, false, PreferredName,
571-
EditConsumer).performChange();
572-
}
573-
574548
/// Abstract helper class containing info about a TernaryExpr
575549
/// that can be expanded into an IfStmt.
576550
class ExpandableTernaryExprInfo {

0 commit comments

Comments
 (0)