Skip to content

Commit f84cfc6

Browse files
authored
Add instantiate shortcuts (#422)
Closes #418.
1 parent 000c75c commit f84cfc6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

default-recommendations/class-shortcuts-test.rkt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,32 @@ test: "two-method nested send expression not refactorable to send+"
2727
(define (f obj x y)
2828
(send (send obj m1 x) m2 y))
2929
--------------------
30+
31+
32+
test: "instantiate without by-name arguments refactorable to make-object"
33+
--------------------
34+
(define (f cls x y z)
35+
(instantiate cls (x y z)))
36+
--------------------
37+
--------------------
38+
(define (f cls x y z)
39+
(make-object cls x y z))
40+
--------------------
41+
42+
43+
test: "instantiate without by-position arguments refactorable to new"
44+
--------------------
45+
(define (f cls x y z)
46+
(instantiate cls () [x x] [y y] [z z]))
47+
--------------------
48+
--------------------
49+
(define (f cls x y z)
50+
(new cls [x x] [y y] [z z]))
51+
--------------------
52+
53+
54+
test: "instantiate without any arguments not refactorable"
55+
--------------------
56+
(define (f cls)
57+
(instantiate cls ()))
58+
--------------------

default-recommendations/class-shortcuts.rkt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,23 @@
4242
(send+ chain.initial-object (chain.method chain.arg ...) ...))
4343

4444

45+
(define-refactoring-rule instantiate-to-make-object
46+
#:description "The `instantiate` form is for mixing positional and by-name constructor arguments.\
47+
When no by-name arguments are needed, use `make-object` instead."
48+
#:literals (instantiate)
49+
(instantiate cls (by-position-arg ...+))
50+
(make-object cls by-position-arg ...))
51+
52+
53+
(define-refactoring-rule instantiate-to-new
54+
#:description "The `instantiate` form is for mixing positional and by-name constructor arguments.\
55+
When no positional arguments are needed, use `new` instead."
56+
#:literals (instantiate)
57+
(instantiate cls () by-name-arg ...+)
58+
(new cls by-name-arg ...))
59+
60+
4561
(define-refactoring-suite class-shortcuts
46-
#:rules (send-chain-to-send+))
62+
#:rules (instantiate-to-make-object
63+
instantiate-to-new
64+
send-chain-to-send+))

0 commit comments

Comments
 (0)