generated from jackfirth/racket-package-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #390.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#lang resyntax/test | ||
|
||
|
||
require: resyntax/default-recommendations class-shortcuts | ||
|
||
|
||
header: | ||
-------------------- | ||
#lang racket/base | ||
(require racket/class) | ||
-------------------- | ||
|
||
|
||
test: "nested send expressions refactorable to flat send+ expression" | ||
-------------------- | ||
(define (f obj x y z) | ||
(send (send (send obj m1 x) m2 y) m3 z)) | ||
-------------------- | ||
-------------------- | ||
(define (f obj x y z) | ||
(send+ obj (m1 x) (m2 y) (m3 z))) | ||
-------------------- | ||
|
||
|
||
test: "two-method nested send expression not refactorable to send+" | ||
-------------------- | ||
(define (f obj x y) | ||
(send (send obj m1 x) m2 y)) | ||
-------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#lang racket/base | ||
|
||
|
||
(require racket/contract/base) | ||
|
||
|
||
(provide | ||
(contract-out | ||
[class-shortcuts refactoring-suite?])) | ||
|
||
|
||
(require racket/class | ||
resyntax/base | ||
syntax/parse) | ||
|
||
|
||
;@---------------------------------------------------------------------------------------------------- | ||
|
||
|
||
(define-syntax-class manual-method-chain | ||
#:attributes (initial-object [method 1] [arg 2]) | ||
#:literals (send) | ||
|
||
(pattern (send inner-chain:manual-method-chain last-method:id last-method-arg ...) | ||
#:attr initial-object (attribute inner-chain.initial-object) | ||
#:attr [method 1] (append (attribute inner-chain.method) (list #'last-method)) | ||
#:attr [arg 2] (append (attribute inner-chain.arg) (list (attribute last-method-arg)))) | ||
|
||
(pattern (send (~and initial-object (~not _:manual-method-chain)) | ||
first-method:id | ||
first-method-arg ...) | ||
#:attr [method 1] (list #'first-method) | ||
#:attr [arg 2] (list (attribute first-method-arg)))) | ||
|
||
|
||
(define-refactoring-rule send-chain-to-send+ | ||
#:description | ||
"This method chain made of nested `send` expressions can be written more clearly as a `send+`\ | ||
expression." | ||
chain:manual-method-chain | ||
#:when (>= (length (attribute chain.method)) 3) | ||
(send+ chain.initial-object (chain.method chain.arg ...) ...)) | ||
|
||
|
||
(define-refactoring-suite class-shortcuts | ||
#:rules (send-chain-to-send+)) |