Skip to content

Commit dcd6c5d

Browse files
authored
Merge pull request #40 from FedeLoch/handling-long-methods
Can handle method
2 parents 72cc7df + f33b8d5 commit dcd6c5d

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Class {
2+
#name : 'MpHandlerTest',
3+
#superclass : 'TestCase',
4+
#category : 'MethodProxies-Tests',
5+
#package : 'MethodProxies-Tests'
6+
}
7+
8+
{ #category : 'tests' }
9+
MpHandlerTest >> testCanHandleMethodWithArity [
10+
11+
self assert: (MpHandler new canHandle: 5).
12+
self deny: (MpHandler new canHandle: 6)
13+
]

src/MethodProxies/MpHandler.class.st

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ MpHandler >> beforeMethod [
114114

115115
]
116116

117+
{ #category : 'as yet unclassified' }
118+
MpHandler >> canHandle: arity [
119+
120+
^ arity < 6
121+
]
122+
117123
{ #category : 'evaluating' }
118124
MpHandler >> insteadExecutionWithReceiver: anObject [
119125
^ self insteadExecutionWithReceiver: anObject arguments: {}
@@ -149,10 +155,12 @@ MpHandler >> insteadExecutionWithReceiver: anObject with: arg1 with: arg2 with:
149155
]
150156

151157
{ #category : 'as yet unclassified' }
152-
MpHandler >> overridesAfterMethodFor: anInteger [
158+
MpHandler >> overridesAfterMethodFor: arity [
153159

154160
| argKeywords |
155-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
161+
162+
(self canHandle: arity) ifFalse: [ ^ false ].
163+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
156164

157165
^ (self class lookupSelector:
158166
(#afterExecutionWithReceiver: , argKeywords, 'returnValue:') asSymbol)
@@ -167,21 +175,25 @@ MpHandler >> overridesBeforeMethod [
167175
]
168176

169177
{ #category : 'as yet unclassified' }
170-
MpHandler >> overridesBeforeMethodFor: anInteger [
178+
MpHandler >> overridesBeforeMethodFor: arity [
171179

172180
| argKeywords |
173-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
181+
182+
(self canHandle: arity) ifFalse: [ ^ false ].
183+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
174184

175185
^ (self class lookupSelector:
176186
(#beforeExecutionWithReceiver: , argKeywords) asSymbol)
177187
methodClass ~= MpHandler
178188
]
179189

180190
{ #category : 'as yet unclassified' }
181-
MpHandler >> overridesInsteadMethodFor: anInteger [
191+
MpHandler >> overridesInsteadMethodFor: arity [
182192

183193
| argKeywords |
184-
argKeywords := '' join: ((1 to: anInteger) collect: [ :i | 'with:' ]).
194+
195+
(self canHandle: arity) ifFalse: [ ^ false ].
196+
argKeywords := '' join: ((1 to: arity) collect: [ :i | 'with:' ]).
185197

186198
^ (self class lookupSelector:
187199
(#insteadExecutionWithReceiver: , argKeywords) asSymbol)

0 commit comments

Comments
 (0)