Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions default-recommendations/class-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ test: "two-method nested send expression not refactorable to send+"
(define (f obj x y)
(send (send obj m1 x) m2 y))
--------------------


test: "instantiate without by-name arguments refactorable to make-object"
--------------------
(define (f cls x y z)
(instantiate cls (x y z)))
--------------------
--------------------
(define (f cls x y z)
(make-object cls x y z))
--------------------


test: "instantiate without by-position arguments refactorable to new"
--------------------
(define (f cls x y z)
(instantiate cls () [x x] [y y] [z z]))
--------------------
--------------------
(define (f cls x y z)
(new cls [x x] [y y] [z z]))
--------------------


test: "instantiate without any arguments not refactorable"
--------------------
(define (f cls)
(instantiate cls ()))
--------------------
20 changes: 19 additions & 1 deletion default-recommendations/class-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,23 @@
(send+ chain.initial-object (chain.method chain.arg ...) ...))


(define-refactoring-rule instantiate-to-make-object
#:description "The `instantiate` form is for mixing positional and by-name constructor arguments.\
When no by-name arguments are needed, use `make-object` instead."
#:literals (instantiate)
(instantiate cls (by-position-arg ...+))
(make-object cls by-position-arg ...))


(define-refactoring-rule instantiate-to-new
#:description "The `instantiate` form is for mixing positional and by-name constructor arguments.\
When no positional arguments are needed, use `new` instead."
#:literals (instantiate)
(instantiate cls () by-name-arg ...+)
(new cls by-name-arg ...))


(define-refactoring-suite class-shortcuts
#:rules (send-chain-to-send+))
#:rules (instantiate-to-make-object
instantiate-to-new
send-chain-to-send+))
Loading