Kernel-Announcements.st 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. Smalltalk current createPackage: 'Kernel-Announcements'!
  2. Object subclass: #AnnouncementSubscription
  3. instanceVariableNames: 'valuable announcementClass'
  4. package: 'Kernel-Announcements'!
  5. !AnnouncementSubscription commentStamp!
  6. The subscription is a single entry in a subscription registry of an `Announcer`.
  7. Several subscriptions by the same object is possible.!
  8. !AnnouncementSubscription methodsFor: 'accessing'!
  9. announcementClass
  10. ^ announcementClass
  11. !
  12. announcementClass: aClass
  13. announcementClass := aClass
  14. !
  15. block
  16. "Use #valuable instead"
  17. self deprecatedAPI.
  18. ^ self valuable
  19. !
  20. block: aValuable
  21. "Use #valuable instead"
  22. self deprecatedAPI.
  23. self valuable: aValuable
  24. !
  25. receiver
  26. ^ self valuable receiver
  27. !
  28. valuable
  29. ^ valuable
  30. !
  31. valuable: aValuable
  32. valuable := aValuable
  33. ! !
  34. !AnnouncementSubscription methodsFor: 'announcing'!
  35. deliver: anAnnouncement
  36. (self handlesAnnouncement: anAnnouncement)
  37. ifTrue: [self valuable value: anAnnouncement]
  38. !
  39. handlesAnnouncement: anAnnouncement
  40. "anAnnouncement might be announced from within another Amber environment"
  41. ^ (Smalltalk current at: self announcementClass name)
  42. ifNil: [ ^ false ]
  43. ifNotNil: [ :class |
  44. class includesBehavior: (Smalltalk current at: anAnnouncement class theNonMetaClass name) ]
  45. ! !
  46. Object subclass: #Announcer
  47. instanceVariableNames: 'registry subscriptions'
  48. package: 'Kernel-Announcements'!
  49. !Announcer commentStamp!
  50. The code is based on the announcements as [described by Vassili Bykov](http://www.cincomsmalltalk.com/userblogs/vbykov/blogView?searchCategory=Announcements%20Framework).
  51. The Announcer holds annoncement subscriptions (`AnnouncementSubscription`) in a private registry.
  52. Use `#on:do:` to register subscriptions.!
  53. !Announcer methodsFor: 'announcing'!
  54. announce: anAnnouncement
  55. subscriptions do: [ :each |
  56. each deliver: anAnnouncement ]
  57. ! !
  58. !Announcer methodsFor: 'initialization'!
  59. initialize
  60. super initialize.
  61. subscriptions := Array new
  62. ! !
  63. !Announcer methodsFor: 'subscribing'!
  64. on: aClass do: aBlock
  65. subscriptions add: (AnnouncementSubscription new
  66. valuable: aBlock;
  67. announcementClass: aClass;
  68. yourself)
  69. ! !
  70. Announcer subclass: #SystemAnnouncer
  71. instanceVariableNames: ''
  72. package: 'Kernel-Announcements'!
  73. !SystemAnnouncer commentStamp!
  74. My unique instance #current is the global announcer handling all Amber system-related announces!
  75. SystemAnnouncer class instanceVariableNames: 'current'!
  76. !SystemAnnouncer class methodsFor: 'accessing'!
  77. current
  78. ^ current ifNil: [ current := super new ]
  79. ! !
  80. !SystemAnnouncer class methodsFor: 'instance creation'!
  81. new
  82. self shouldNotImplement
  83. ! !
  84. Object subclass: #SystemAnnouncement
  85. instanceVariableNames: 'theClass'
  86. package: 'Kernel-Announcements'!
  87. !SystemAnnouncement commentStamp!
  88. I am the superclass of all system announcements!
  89. !SystemAnnouncement methodsFor: 'accessing'!
  90. theClass
  91. ^ theClass
  92. !
  93. theClass: aClass
  94. theClass := aClass
  95. ! !
  96. SystemAnnouncement subclass: #ClassAnnouncement
  97. instanceVariableNames: 'theClass'
  98. package: 'Kernel-Announcements'!
  99. !ClassAnnouncement methodsFor: 'accessing'!
  100. theClass
  101. ^ theClass
  102. !
  103. theClass: aClass
  104. theClass := aClass
  105. ! !
  106. ClassAnnouncement subclass: #ClassAdded
  107. instanceVariableNames: ''
  108. package: 'Kernel-Announcements'!
  109. !ClassAdded commentStamp!
  110. I am emitted when a class is added to the system.
  111. See ClassBuilder >> #addSubclassOf:... methods!
  112. ClassAnnouncement subclass: #ClassCommentChanged
  113. instanceVariableNames: ''
  114. package: 'Kernel-Announcements'!
  115. !ClassCommentChanged commentStamp!
  116. I am emitted when the comment of a class changes. (Behavior >> #comment)!
  117. ClassAnnouncement subclass: #ClassDefinitionChanged
  118. instanceVariableNames: ''
  119. package: 'Kernel-Announcements'!
  120. !ClassDefinitionChanged commentStamp!
  121. I am emitted when the defintion of a class changes.
  122. See ClassBuilder >> #class:instanceVariableNames:!
  123. ClassAnnouncement subclass: #ClassMigrated
  124. instanceVariableNames: 'oldClass'
  125. package: 'Kernel-Announcements'!
  126. !ClassMigrated methodsFor: 'accessing'!
  127. oldClass
  128. ^ oldClass
  129. !
  130. oldClass: aClass
  131. oldClass := aClass
  132. ! !
  133. ClassAnnouncement subclass: #ClassMoved
  134. instanceVariableNames: 'oldPackage'
  135. package: 'Kernel-Announcements'!
  136. !ClassMoved methodsFor: 'accessing'!
  137. oldPackage
  138. ^ oldPackage
  139. !
  140. oldPackage: aPackage
  141. oldPackage := aPackage
  142. ! !
  143. ClassAnnouncement subclass: #ClassRemoved
  144. instanceVariableNames: ''
  145. package: 'Kernel-Announcements'!
  146. !ClassRemoved commentStamp!
  147. I am emitted when a class is removed.
  148. See Smalltalk >> #removeClass:!
  149. ClassAnnouncement subclass: #ClassRenamed
  150. instanceVariableNames: ''
  151. package: 'Kernel-Announcements'!
  152. !ClassRenamed commentStamp!
  153. I am emitted when a class is renamed.
  154. See ClassBuilder >> #renameClass:to:!
  155. SystemAnnouncement subclass: #MethodAnnouncement
  156. instanceVariableNames: 'method'
  157. package: 'Kernel-Announcements'!
  158. !MethodAnnouncement methodsFor: 'accessing'!
  159. method
  160. ^ method
  161. !
  162. method: aCompiledMethod
  163. method := aCompiledMethod
  164. ! !
  165. MethodAnnouncement subclass: #MethodAdded
  166. instanceVariableNames: ''
  167. package: 'Kernel-Announcements'!
  168. MethodAnnouncement subclass: #MethodModified
  169. instanceVariableNames: 'oldMethod'
  170. package: 'Kernel-Announcements'!
  171. !MethodModified methodsFor: 'accessing'!
  172. oldMethod
  173. ^ oldMethod
  174. !
  175. oldMethod: aMethod
  176. oldMethod := aMethod
  177. ! !
  178. MethodAnnouncement subclass: #MethodMoved
  179. instanceVariableNames: 'oldProtocol'
  180. package: 'Kernel-Announcements'!
  181. !MethodMoved methodsFor: 'accessing'!
  182. oldProtocol
  183. ^ oldProtocol
  184. !
  185. oldProtocol: aString
  186. oldProtocol := aString
  187. ! !
  188. MethodAnnouncement subclass: #MethodRemoved
  189. instanceVariableNames: ''
  190. package: 'Kernel-Announcements'!
  191. SystemAnnouncement subclass: #PackageAnnouncement
  192. instanceVariableNames: 'package'
  193. package: 'Kernel-Announcements'!
  194. !PackageAnnouncement methodsFor: 'accessing'!
  195. package
  196. ^ package
  197. !
  198. package: aPackage
  199. package := aPackage
  200. ! !
  201. PackageAnnouncement subclass: #PackageAdded
  202. instanceVariableNames: ''
  203. package: 'Kernel-Announcements'!
  204. PackageAnnouncement subclass: #PackageRemoved
  205. instanceVariableNames: ''
  206. package: 'Kernel-Announcements'!
  207. SystemAnnouncement subclass: #ProtocolAnnouncement
  208. instanceVariableNames: 'theClass protocol'
  209. package: 'Kernel-Announcements'!
  210. !ProtocolAnnouncement methodsFor: 'accessing'!
  211. protocol
  212. ^ protocol
  213. !
  214. protocol: aString
  215. protocol := aString
  216. !
  217. theClass
  218. ^ theClass
  219. !
  220. theClass: aClass
  221. theClass := aClass
  222. ! !
  223. ProtocolAnnouncement subclass: #ProtocolAdded
  224. instanceVariableNames: ''
  225. package: 'Kernel-Announcements'!
  226. ProtocolAnnouncement subclass: #ProtocolRemoved
  227. instanceVariableNames: ''
  228. package: 'Kernel-Announcements'!