Skip to content

Commit

Permalink
Reflected methods of the MetalinkChanged system announcement onto the…
Browse files Browse the repository at this point in the history
… BreakpointAnnoucement (and subclasses) system announcement.

Tests of breakpoint notifications updated to use SystemAnnouncer instead of the old ad-hoc observer pattern of the Breakpoint class.
  • Loading branch information
dupriezt committed Oct 30, 2020
1 parent 7dc4099 commit 3535540
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 29 deletions.
@@ -0,0 +1,8 @@
Extension { #name : #BreakpointAnnouncement }

{ #category : #'*Calypso-SystemPlugins-Reflectivity-Queries' }
BreakpointAnnouncement >> canAffectResultOfMethodQuery: aMethodQuery [

^ self link methods anySatisfy: [:each |
aMethodQuery isAffectedByChangedMethod: each ]
]
39 changes: 11 additions & 28 deletions src/Reflectivity-Tools-Tests/BreakpointObserverTest.class.st
Expand Up @@ -6,7 +6,8 @@ Class {
'breakpoint',
'cls',
'previousBreakpoints',
'observer'
'observer',
'oldSystemAnnouncer'
],
#category : #'Reflectivity-Tools-Tests'
}
Expand All @@ -26,8 +27,8 @@ BreakpointObserverTest >> setUp [

super setUp.
previousBreakpoints := Breakpoint all copy.
oldObservers := Breakpoint observers copy.
Breakpoint observers removeAll.
oldSystemAnnouncer := SystemAnnouncer uniqueInstance.
SystemAnnouncer announcer: nil.
cls := self newDummyClass.
breakpoint := Breakpoint new.
cls compile: 'dummy ^42'.
Expand All @@ -40,31 +41,30 @@ BreakpointObserverTest >> setUp [
{ #category : #running }
BreakpointObserverTest >> tearDown [
|pkg|
Breakpoint observers removeAll.
Breakpoint observers addAll: oldObservers.
cls ifNotNil: [ cls isObsolete ifFalse: [ cls removeFromSystem ] ].
pkg := 'DummyPackage' asPackageIfAbsent: [ ].
pkg ifNotNil: [ pkg removeFromSystem ].
Breakpoint removeAll.
Breakpoint all addAll: previousBreakpoints.
SystemAnnouncer announcer: oldSystemAnnouncer.
super tearDown
]

{ #category : #tests }
BreakpointObserverTest >> testNotifyBreakpointAdded [
Breakpoint registerObserver: observer.
SystemAnnouncer uniqueInstance when: BreakpointAdded send: #update: to: observer.
breakpoint install.
self assert: observer tag class equals: BreakpointAddedNotification.
self assert: observer tag class equals: BreakpointAdded.
self assert: observer tag breakpoint identicalTo: breakpoint.
self assertCollection: observer tag nodes equals: { (cls >> #dummy) ast } asSet
]

{ #category : #tests }
BreakpointObserverTest >> testNotifyBreakpointHit [
Breakpoint registerObserver: observer.
SystemAnnouncer uniqueInstance when: BreakpointHit send: #update: to: observer.
breakpoint install.
self should: [cls new dummy] raise: Break.
self assert: observer tag class equals: BreakpointHitNotification.
self assert: observer tag class equals: BreakpointHit.
self assert: observer tag breakpoint identicalTo: breakpoint.
self assert: observer tag valueOrNil isNil

Expand All @@ -73,26 +73,9 @@ BreakpointObserverTest >> testNotifyBreakpointHit [
{ #category : #tests }
BreakpointObserverTest >> testNotifyBreakpointRemoved [
breakpoint install.
Breakpoint registerObserver: observer.
SystemAnnouncer uniqueInstance when: BreakpointRemoved send: #update: to: observer.
breakpoint remove.
self assert: observer tag class equals: BreakpointRemovedNotification.
self assert: observer tag class equals: BreakpointRemoved.
self assert: observer tag breakpoint identicalTo: breakpoint.
self assertCollection: observer tag nodes equals: { (cls >> #dummy) ast } asSet
]

{ #category : #tests }
BreakpointObserverTest >> testRegisterObserver [
|obs|
obs := DummyBreakpointObserver new.
Breakpoint registerObserver: obs.
self assertCollection: Breakpoint observers includesAll: {obs}
]

{ #category : #tests }
BreakpointObserverTest >> testUnregisterObserver [
|obs|
obs := DummyBreakpointObserver new.
Breakpoint registerObserver: obs.
Breakpoint unregisterObserver: obs.
self assertEmpty: Breakpoint observers
]
2 changes: 2 additions & 0 deletions src/Reflectivity/BreakpointAddedNotification.class.st
@@ -1,4 +1,6 @@
"
DEPRECATED: use BreakpointAnnouncement and its subclasses instead
A trivial breakpoint added notification.
"
Class {
Expand Down
29 changes: 29 additions & 0 deletions src/Reflectivity/BreakpointAnnouncement.class.st
Expand Up @@ -16,6 +16,30 @@ BreakpointAnnouncement class >> on: aBreakpoint nodes: nodes [
yourself
]

{ #category : #accessing }
BreakpointAnnouncement >> affectsMethod: aMethod [

^ self link methods anySatisfy: [:each | each compiledMethod == aMethod compiledMethod ]
]

{ #category : #accessing }
BreakpointAnnouncement >> affectsMethods [
^true
]

{ #category : #accessing }
BreakpointAnnouncement >> affectsMethodsDefinedInClass: aClass [
^ self link methods
anySatisfy: [ :each | each methodClass isNotNil and: [ each origin == aClass ] ]
]

{ #category : #accessing }
BreakpointAnnouncement >> affectsMethodsDefinedInPackage: aPackage [
^ self link methods
anySatisfy:
[ :each | each methodClass isNotNil and: [ each package == aPackage ] ]
]

{ #category : #accessing }
BreakpointAnnouncement >> breakpoint [
^ breakpoint
Expand All @@ -26,6 +50,11 @@ BreakpointAnnouncement >> breakpoint: anObject [
breakpoint := anObject
]

{ #category : #accessing }
BreakpointAnnouncement >> link [
^ self breakpoint link
]

{ #category : #accessing }
BreakpointAnnouncement >> nodes [
^ nodes
Expand Down
2 changes: 2 additions & 0 deletions src/Reflectivity/BreakpointHitNotification.class.st
@@ -1,4 +1,6 @@
"
DEPRECATED: use BreakpointAnnouncement and its subclasses instead
I am a notification sent to Breakpoint observers when a breakpoint is hit.
I can hold a value from the execution context the breakpoint was hit.
"
Expand Down
4 changes: 3 additions & 1 deletion src/Reflectivity/BreakpointNotification.class.st
@@ -1,4 +1,6 @@
"
DEPRECATED: use BreakpointAnnouncement and its subclasses instead
Trivial abtract breakpoint notification.
I hold the affected breakpoint and a collection of nodes on which it is installed or removed from.
"
Expand All @@ -14,7 +16,7 @@ Class {

{ #category : #testing }
BreakpointNotification class >> isDeprecated [
"Replaed by BreakpointAnnouncement and its subclasses"
"Replaced by BreakpointAnnouncement and its subclasses"
^ true
]

Expand Down
2 changes: 2 additions & 0 deletions src/Reflectivity/BreakpointRemovedNotification.class.st
@@ -1,4 +1,6 @@
"
DEPRECATED: use BreakpointAnnouncement and its subclasses instead
A trivial breakpoint removed notification.
"
Class {
Expand Down

0 comments on commit 3535540

Please sign in to comment.