Skip to content

Commit fac1a52

Browse files
committed
[IDE] Tweak replace.bodies.with.fatalError.
The menu item should be capitalised, and it's nicer if the fatalError is on its own line in the new function body.
1 parent d3ab36f commit fac1a52

File tree

10 files changed

+65
-23
lines changed

10 files changed

+65
-23
lines changed

include/swift/IDE/RefactoringKinds.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ RANGE_REFACTORING(ExpandTernaryExpr, "Expand Ternary Expression", expand.ternary
6060

6161
RANGE_REFACTORING(ConvertToTernaryExpr, "Convert To Ternary Expression", convert.ternary.expr)
6262

63-
RANGE_REFACTORING(ReplaceBodiesWithFatalError, "Replace function bodies with fatalError", replace.bodies.with.fatalError)
63+
RANGE_REFACTORING(ReplaceBodiesWithFatalError, "Replace Function Bodies With 'fatalError()'", replace.bodies.with.fatalError)
6464

6565
#undef CURSOR_REFACTORING
6666
#undef RANGE_REFACTORING

lib/IDE/Refactoring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ bool RefactoringActionReplaceBodiesWithFatalError::isApplicable(
16391639
}
16401640

16411641
bool RefactoringActionReplaceBodiesWithFatalError::performChange() {
1642-
const StringRef replacement = "{ fatalError() }";
1642+
const StringRef replacement = "{\nfatalError()\n}";
16431643
llvm::SmallPtrSet<Decl *, 16> Found;
16441644
for (auto decl : RangeInfo.DeclaredDecls) {
16451645
FindAllSubDecls(Found).walk(decl.VD);

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L12-14.swift.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ var qux: Int = 0 {
99
didSet { print("bye") }
1010
}
1111

12-
func generic<T>(_: T) -> Int { fatalError() }
12+
func generic<T>(_: T) -> Int {
13+
fatalError()
14+
}
1315

1416
class Foo {
1517
var foo: Int

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L16-49.swift.expected

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,43 @@ func generic<T>(_: T) -> Int {
1616
class Foo {
1717
var foo: Int
1818

19-
var bar: Int { fatalError() }
19+
var bar: Int {
20+
fatalError()
21+
}
2022

2123
var baz: Int {
22-
get { fatalError() }
23-
set { fatalError() }
24+
get {
25+
fatalError()
26+
}
27+
set {
28+
fatalError()
29+
}
2430
}
2531

2632
var qux: Int {
27-
willSet { fatalError() }
28-
didSet { fatalError() }
33+
willSet {
34+
fatalError()
35+
}
36+
didSet {
37+
fatalError()
38+
}
2939
}
3040

31-
init() { fatalError() }
41+
init() {
42+
fatalError()
43+
}
3244

33-
func nonGeneric() -> Int { fatalError() }
45+
func nonGeneric() -> Int {
46+
fatalError()
47+
}
3448

35-
func generic<T>(_: T) -> Int { fatalError() }
49+
func generic<T>(_: T) -> Int {
50+
fatalError()
51+
}
3652

37-
deinit { fatalError() }
53+
deinit {
54+
fatalError()
55+
}
3856
}
3957

4058
extension Foo {

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L19-22.swift.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ func generic<T>(_: T) -> Int {
1616
class Foo {
1717
var foo: Int
1818

19-
var bar: Int { fatalError() }
19+
var bar: Int {
20+
fatalError()
21+
}
2022

2123
var baz: Int {
2224
get { return 0 }

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L3-5.swift.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var foo: Int = 0
22

3-
var bar: Int { fatalError() }
3+
var bar: Int {
4+
fatalError()
5+
}
46

57
var qux: Int = 0 {
68
willSet { print("hi") }

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L30-44.swift.expected

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ class Foo {
2727

2828
var qux: Int {
2929
willSet { print("hi") }
30-
didSet { fatalError() }
30+
didSet {
31+
fatalError()
32+
}
3133
}
3234

33-
init() { fatalError() }
35+
init() {
36+
fatalError()
37+
}
3438

35-
func nonGeneric() -> Int { fatalError() }
39+
func nonGeneric() -> Int {
40+
fatalError()
41+
}
3642

37-
func generic<T>(_: T) -> Int { fatalError() }
43+
func generic<T>(_: T) -> Int {
44+
fatalError()
45+
}
3846

3947
deinit {
4048
print("bye")

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L51-59.swift.expected

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ class Foo {
4949
}
5050

5151
extension Foo {
52-
func nonGeneric2() -> Int { fatalError() }
52+
func nonGeneric2() -> Int {
53+
fatalError()
54+
}
5355

54-
func generic2<T>(_: T) -> Int { fatalError() }
56+
func generic2<T>(_: T) -> Int {
57+
fatalError()
58+
}
5559
}
5660

5761

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L7-10.swift.expected

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ var bar: Int {
55
}
66

77
var qux: Int = 0 {
8-
willSet { fatalError() }
9-
didSet { fatalError() }
8+
willSet {
9+
fatalError()
10+
}
11+
didSet {
12+
fatalError()
13+
}
1014
}
1115

1216
func generic<T>(_: T) -> Int {

test/refactoring/ReplaceBodiesWithFatalError/Outputs/basic/L8.swift.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ var bar: Int {
55
}
66

77
var qux: Int = 0 {
8-
willSet { fatalError() }
8+
willSet {
9+
fatalError()
10+
}
911
didSet { print("bye") }
1012
}
1113

0 commit comments

Comments
 (0)