Skip to content

Commit

Permalink
Add #isSuperSendTo: to simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Apr 12, 2020
1 parent 46a06ba commit 8cd0dca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Chanel/ChanelEnsureSuperIsCalledCleaner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ChanelEnsureSuperIsCalledCleaner >> ensureSuperInitializeForMethods: methods [
method methodClass isInstanceSide
and: [ method selector = #initialize
and: [ method ast sendNodes
ifNotEmpty: [ :nodes | (nodes anySatisfy: [ :node | node isSuperSend and: [ node selector = #initialize ] ]) not ]
ifNotEmpty: [ :nodes | (nodes anySatisfy: [ :node | node isSuperSendTo: #initialize ]) not ]
ifEmpty: [ false ] ] ] ]
thenDo: [ :method |
| ast |
Expand All @@ -52,12 +52,12 @@ ChanelEnsureSuperIsCalledCleaner >> ensureSuperSetUpForMethods: methods [
method methodClass isTestCase
and: [ method selector = #setUp
and: [ method ast sendNodes
ifNotEmpty: [ :nodes | (nodes first isSuperSend and: [ nodes first selector = #setUp ]) not ]
ifNotEmpty: [ :nodes | (nodes first isSuperSendTo: #setUp) not ]
ifEmpty: [ false ] ] ] ]
thenDo: [ :method |
| ast |
ast := method ast.
ast sendNodes select: [ :each | each isSuperSend and: [ each selector = #setUp ] ] thenDo: #removeFromTree.
ast sendNodes select: [ :each | each isSuperSendTo: #setUp ] thenDo: #removeFromTree.
ast body addNodeFirst: (RBMessageNode receiver: (RBVariableNode named: #super) selector: #setUp).
method methodClass compile: ast formattedCode ]
]
Expand All @@ -69,12 +69,12 @@ ChanelEnsureSuperIsCalledCleaner >> ensureSuperTearDownForMethods: methods [
method methodClass isTestCase
and: [ method selector = #tearDown
and: [ method ast sendNodes
ifNotEmpty: [ :nodes | (nodes last isSuperSend and: [ nodes last selector = #tearDown ]) not ]
ifNotEmpty: [ :nodes | (nodes last isSuperSendTo: #tearDown) not ]
ifEmpty: [ false ] ] ] ]
thenDo: [ :method |
| ast |
ast := method ast.
ast sendNodes select: [ :each | each isSuperSend and: [ each selector = #tearDown ] ] thenDo: #removeFromTree.
ast sendNodes select: [ :each | each isSuperSendTo: #tearDown ] thenDo: #removeFromTree.
ast body addNodeLast: (RBMessageNode receiver: (RBVariableNode named: #super) selector: #tearDown).
method methodClass compile: ast formattedCode ]
]
6 changes: 6 additions & 0 deletions src/Chanel/RBMessageNode.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #RBMessageNode }

{ #category : #'*Chanel' }
RBMessageNode >> isSuperSendTo: aSelector [
^ self isSuperSend and: [ self selector = aSelector ]
]

0 comments on commit 8cd0dca

Please sign in to comment.