Help needed for a spying object
ducasse stephane
ducasse at iam.unibe.ch
Thu Oct 4 08:58:12 UTC 2001
Hi
I'm trying to finish to write a column on using reflection in Squeak.
I wanted to show a little spy that puts on the transcript all the messages
sent to the spied object.
So I subclassed from protoObject redefined DNU.
ProtoObject subclass: #Spy
instanceVariableNames: 'spyedObject '
classVariableNames: ''
poolDictionaries: ''
category: 'Scaffolding'
Spy>> doesNotUnderstand: aMessage
Transcript nextPutAll: '*' ; flush.
^ spyedObject perform: aMessage selector withArguments: aMessage
arguments
Spy>>on: anObject
spyedObject := anObject
Then created the class method on: as follow on Spy
Spy class>>on: anObject
| spy |
spy := self new.
spy become: anObject.
anObject on: spy.
^ anObject
I have now two problems
First problem:
|t |
t := OrderedCollection new.
Spy on: t.
t add: 3.
t add: 5.
t
When I execute the following code everythign works
Then when I open an inspector on t and send messages there are not
captured. I don't understand why. I alreadyplayed a lot with become: and
nasty stuff in VW but here I'm stuck.
Second problem:
I wanted to have a spy on a morph. Crazy me....It was nearly working on
BoucingAtomsMorph but I tried on something simpler liek
RectangleMorph or TextMorph but I got a lot of strange errors or nealry
damage my system
testDamagingThe28System
|t |
t := TextMorph new.
t openInWorld.
Spy on: t.
testWithEventErrorin28
|t |
t := RectangleMorph new.
t openInWorld.
Spy on: t.
Have you any idea or suggestions?
Stef
-------------- next part --------------
'From Squeak2.8 of 13 June 2000 [latest update: #2359] on 4 October 2001 at 10:45:56 am'!
ProtoObject subclass: #Spy
instanceVariableNames: 'spyedObject '
classVariableNames: ''
poolDictionaries: ''
category: 'Scaffolding'!
!Spy methodsFor: 'doesnotuunderstand' stamp: 'SD 10/4/2001 10:32'!
doesNotUnderstand2: aMessage
Transcript nextPutAll: 'sel>> ' ; nextPutAll: aMessage selector printString ;
nextPutAll: ' args>> '; nextPutAll: aMessage arguments printString; cr ; flush.
^ spyedObject perform: aMessage selector withArguments: aMessage arguments! !
!Spy methodsFor: 'doesnotuunderstand' stamp: 'SD 10/4/2001 10:44'!
doesNotUnderstand: aMessage
Transcript nextPutAll: '*' ; flush.
^ spyedObject perform: aMessage selector withArguments: aMessage arguments! !
!Spy methodsFor: 'printing' stamp: 'SD 10/4/2001 10:19'!
printOn: aStream
aStream nextPutAll: 'A Spy on ', spyedObject printString! !
!Spy methodsFor: 'installation' stamp: 'SD 10/4/2001 10:19'!
on: anObject
spyedObject := anObject! !
!Spy methodsFor: 'installation' stamp: 'SD 10/4/2001 10:27'!
uninstall
self become: spyedObject.
spyedObject := nil.! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Spy class
instanceVariableNames: ''!
!Spy class methodsFor: 'accessing' stamp: 'SD 10/4/2001 09:26'!
on: anObject
| spy |
spy := self new.
spy become: anObject.
anObject on: spy.
^ anObject! !
!Spy class methodsFor: 'test working' stamp: 'SD 10/4/2001 10:45'!
testWorking
|t |
t := OrderedCollection new.
Spy on: t.
t add: 3.
t add: 5! !
!Spy class methodsFor: 'test damaging the image' stamp: 'SD 10/4/2001 10:40'!
testDamagingTheSystem
|t |
t := TextMorph new.
t openInWorld.
Spy on: t. ! !
!Spy class methodsFor: 'test damaging the image' stamp: 'SD 10/4/2001 10:42'!
testWithEventError
|t |
t := RectangleMorph new.
t openInWorld.
Spy on: t. ! !
More information about the Squeak-dev
mailing list
|