Helios-Browser.st 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. Smalltalk current createPackage: 'Helios-Browser'!
  2. HLWidget subclass: #HLBrowser
  3. instanceVariableNames: 'model packagesListWidget classesListWidget protocolsListWidget methodsListWidget sourceWidget'
  4. package: 'Helios-Browser'!
  5. !HLBrowser methodsFor: 'accessing'!
  6. announcer
  7. ^ self model announcer
  8. !
  9. environment
  10. ^ self model environment
  11. !
  12. model
  13. ^ model ifNil: [ model := HLBrowserModel new ]
  14. !
  15. model: aModel
  16. model := aModel
  17. ! !
  18. !HLBrowser methodsFor: 'keybindings'!
  19. registerBindingsOn: aBindingGroup
  20. aBindingGroup
  21. addGroupKey: 66 labelled: 'Browse';
  22. addGroupKey: 71 labelled: 'Go to';
  23. addGroupKey: 84 labelled: 'Toggle'.
  24. HLBrowserCommand withAllSubclasses do: [ :each |
  25. each key ifNotNil: [
  26. (aBindingGroup at: each bindingGroup)
  27. add: (each on: self model) asBinding ] ]
  28. ! !
  29. !HLBrowser methodsFor: 'rendering'!
  30. renderContentOn: html
  31. html with: (HLContainer with: (HLHorizontalSplitter
  32. with: (HLVerticalSplitter
  33. with: (HLVerticalSplitter
  34. with: self packagesListWidget
  35. with: self classesListWidget)
  36. with: (HLVerticalSplitter
  37. with: self protocolsListWidget
  38. with: self methodsListWidget))
  39. with: self sourceWidget))
  40. ! !
  41. !HLBrowser methodsFor: 'widgets'!
  42. classesListWidget
  43. ^ classesListWidget ifNil: [
  44. classesListWidget := HLClassesListWidget on: self model.
  45. classesListWidget next: self protocolsListWidget ]
  46. !
  47. methodsListWidget
  48. ^ methodsListWidget ifNil: [
  49. methodsListWidget := HLMethodsListWidget on: self model ]
  50. !
  51. packagesListWidget
  52. ^ packagesListWidget ifNil: [
  53. packagesListWidget := HLPackagesListWidget on: self model.
  54. packagesListWidget next: self classesListWidget ]
  55. !
  56. protocolsListWidget
  57. ^ protocolsListWidget ifNil: [
  58. protocolsListWidget := HLProtocolsListWidget on: self model.
  59. protocolsListWidget next: self methodsListWidget ]
  60. !
  61. sourceWidget
  62. ^ sourceWidget ifNil: [
  63. sourceWidget := HLBrowserSourceWidget on: self model ]
  64. ! !
  65. HLBrowser class instanceVariableNames: 'nextId'!
  66. !HLBrowser class methodsFor: 'accessing'!
  67. nextId
  68. nextId ifNil: [ nextId := 0 ].
  69. ^ 'browser_', (nextId + 1) asString
  70. !
  71. tabLabel
  72. ^ 'Browser'
  73. !
  74. tabPriority
  75. ^ 0
  76. ! !
  77. !HLBrowser class methodsFor: 'testing'!
  78. canBeOpenAsTab
  79. ^ true
  80. ! !
  81. HLNavigationListWidget subclass: #HLBrowserListWidget
  82. instanceVariableNames: 'model'
  83. package: 'Helios-Browser'!
  84. !HLBrowserListWidget methodsFor: 'accessing'!
  85. model
  86. ^ model
  87. !
  88. model: aBrowserModel
  89. model := aBrowserModel.
  90. self observeModel
  91. ! !
  92. !HLBrowserListWidget methodsFor: 'actions'!
  93. observeModel
  94. !
  95. observeSystem
  96. ! !
  97. !HLBrowserListWidget methodsFor: 'initialization'!
  98. initialize
  99. super initialize.
  100. self observeSystem
  101. ! !
  102. !HLBrowserListWidget class methodsFor: 'instance creation'!
  103. on: aModel
  104. ^ self new
  105. model: aModel;
  106. yourself
  107. ! !
  108. HLBrowserListWidget subclass: #HLClassesListWidget
  109. instanceVariableNames: ''
  110. package: 'Helios-Browser'!
  111. !HLClassesListWidget methodsFor: 'accessing'!
  112. getChildrenOf: aClass
  113. ^ self items select: [ :each | each superclass = aClass ]
  114. !
  115. getRootClassesOf: aCollection
  116. ^ aCollection select: [ :each |
  117. (aCollection includes: each superclass) not ]
  118. !
  119. iconForItem: aClass
  120. ^ aClass theNonMetaClass comment isEmpty
  121. ifFalse: [ 'icon-none' ]
  122. ifTrue: [ 'icon-question-sign' ]
  123. !
  124. showInstance
  125. ^ self model showInstance
  126. ! !
  127. !HLClassesListWidget methodsFor: 'actions'!
  128. focusMethodsListWidget
  129. self model announcer announce: HLMethodsListFocus new
  130. !
  131. focusProtocolsListWidget
  132. self model announcer announce: HLProtocolsListFocus new
  133. !
  134. observeModel
  135. self model announcer
  136. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  137. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  138. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ]
  139. !
  140. observeSystem
  141. SystemAnnouncer current
  142. on: ClassAdded
  143. do: [ :ann | self onClassAdded: ann theClass ];
  144. on: ClassRemoved
  145. do: [ :ann | self onClassRemoved: ann theClass ]
  146. !
  147. selectItem: aClass
  148. self model selectedClass: aClass
  149. !
  150. showInstance: aBoolean
  151. self model showInstance: aBoolean
  152. ! !
  153. !HLClassesListWidget methodsFor: 'private'!
  154. setItemsForPackage: aPackage
  155. self items: (aPackage
  156. ifNil: [ #() ]
  157. ifNotNil: [ (aPackage classes
  158. collect: [ :each | each theNonMetaClass ]) asSet asArray ]).
  159. !
  160. setItemsForSelectedPackage
  161. self setItemsForPackage: self model selectedPackage
  162. ! !
  163. !HLClassesListWidget methodsFor: 'reactions'!
  164. onClassAdded: aClass
  165. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  166. self setItemsForSelectedPackage.
  167. self refresh
  168. !
  169. onClassRemoved: aClass
  170. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  171. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  172. self setItemsForSelectedPackage.
  173. self refresh
  174. !
  175. onClassSelected: aClass
  176. self selectedItem: aClass.
  177. aClass ifNil: [ ^ self ].
  178. self focus
  179. !
  180. onPackageSelected: aPackage
  181. self selectedItem: nil.
  182. self setItemsForSelectedPackage.
  183. self refresh
  184. !
  185. onShowInstanceToggled
  186. self refresh
  187. ! !
  188. !HLClassesListWidget methodsFor: 'rendering'!
  189. renderButtonsOn: html
  190. html div
  191. class: 'btn-group';
  192. at: 'data-toggle' put: 'buttons-radio';
  193. with: [
  194. html button
  195. class: (String streamContents: [ :str |
  196. str nextPutAll: 'btn'.
  197. self showInstance ifTrue: [
  198. str nextPutAll: ' active'] ]);
  199. with: 'Instance';
  200. onClick: [ self showInstance: true ].
  201. html button
  202. class: (String streamContents: [ :str |
  203. str nextPutAll: 'btn'.
  204. self model showInstance ifFalse: [
  205. str nextPutAll: ' active'] ]);
  206. with: 'Class';
  207. onClick: [ self model showInstance: false ] ].
  208. html button
  209. class: 'btn';
  210. at: 'data-toggle' put: 'button';
  211. with: 'Comment'
  212. !
  213. renderItem: aClass level: anInteger on: html
  214. | li |
  215. li := html li.
  216. li
  217. at: 'list-data' put: (self items indexOf: aClass);
  218. class: (self cssClassForItem: aClass);
  219. with: [
  220. html a
  221. with: [
  222. (html tag: 'i') class: (self iconForItem: aClass).
  223. self renderItemLabel: aClass level: anInteger on: html ];
  224. onClick: [
  225. self activateListItem: li asJQuery ] ].
  226. (self getChildrenOf: aClass) do: [ :each |
  227. self renderItem: each level: anInteger + 1 on: html ]
  228. !
  229. renderItem: aClass on: html
  230. super renderItem: aClass on: html.
  231. (self getChildrenOf: aClass) do: [ :each |
  232. self renderItem: each level: 1 on: html ]
  233. !
  234. renderItemLabel: aClass level: anInteger on: html
  235. html span asJQuery html: (String streamContents: [ :str |
  236. anInteger timesRepeat: [
  237. str nextPutAll: '    '].
  238. str nextPutAll: aClass name ])
  239. !
  240. renderItemLabel: aClass on: html
  241. self renderItemLabel: aClass level: 0 on: html
  242. !
  243. renderListOn: html
  244. (self getRootClassesOf: self items)
  245. do: [ :each | self renderItem: each on: html ]
  246. ! !
  247. HLBrowserListWidget subclass: #HLMethodsListWidget
  248. instanceVariableNames: ''
  249. package: 'Helios-Browser'!
  250. !HLMethodsListWidget methodsFor: 'accessing'!
  251. allProtocol
  252. ^ self model allProtocol
  253. !
  254. iconForItem: aSelector
  255. | override overriden method |
  256. method := self methodForSelector: aSelector.
  257. override := self isOverride: method.
  258. overriden := self isOverridden: method.
  259. ^ override
  260. ifTrue: [ overriden
  261. ifTrue: [ 'icon-resize-vertical' ]
  262. ifFalse: [ 'icon-arrow-up' ] ]
  263. ifFalse: [
  264. overriden
  265. ifTrue: [ 'icon-arrow-down' ]
  266. ifFalse: [ 'icon-none' ] ]
  267. !
  268. methodForSelector: aSelector
  269. ^ self model selectedClass
  270. methodDictionary at: aSelector
  271. !
  272. methodsInProtocol: aString
  273. ^ aString = self allProtocol
  274. ifTrue: [ self model selectedClass methods ]
  275. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  276. !
  277. overrideSelectors
  278. ^ self selectorsCache
  279. at: 'override'
  280. ifAbsentPut: [
  281. self model selectedClass allSuperclasses
  282. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  283. !
  284. overridenSelectors
  285. ^ self selectorsCache
  286. at: 'overriden'
  287. ifAbsentPut: [
  288. self model selectedClass allSubclasses
  289. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  290. !
  291. selectorsCache
  292. ^ self class selectorsCache
  293. !
  294. selectorsInProtocol: aString
  295. ^ (self methodsInProtocol: aString)
  296. collect: [ :each | each selector ]
  297. ! !
  298. !HLMethodsListWidget methodsFor: 'actions'!
  299. observeModel
  300. self model announcer on: HLProtocolSelected do: [ :ann |
  301. self onProtocolSelected: ann item ].
  302. self model announcer on: HLShowInstanceToggled do: [ :ann |
  303. self onProtocolSelected: nil ].
  304. self model announcer on: HLMethodSelected do: [ :ann |
  305. self onMethodSelected: ann item ]
  306. !
  307. observeSystem
  308. SystemAnnouncer current
  309. on: MethodAdded
  310. do: [ :ann | self onMethodAdded: ann method ];
  311. on: MethodRemoved
  312. do: [ :ann | self onMethodRemoved: ann method ]
  313. !
  314. selectItem: aSelector
  315. self model selectedMethod: (self methodForSelector: aSelector)
  316. ! !
  317. !HLMethodsListWidget methodsFor: 'cache'!
  318. flushSelectorsCache
  319. selectorsCache := Dictionary new
  320. ! !
  321. !HLMethodsListWidget methodsFor: 'initialization'!
  322. initialize
  323. super initialize.
  324. self flushSelectorsCache
  325. ! !
  326. !HLMethodsListWidget methodsFor: 'reactions'!
  327. onMethodAdded: aMethod
  328. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  329. self refresh
  330. !
  331. onMethodRemoved: aMethod
  332. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  333. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem ])
  334. ifTrue: [ self selectItem: nil ].
  335. self refresh
  336. !
  337. onMethodSelected: aMethod
  338. self selectedItem: aMethod.
  339. aMethod ifNil: [ ^ self ].
  340. self focus
  341. !
  342. onProtocolSelected: aString
  343. self selectedItem: nil.
  344. self items: (self model selectedClass
  345. ifNil: [ #() ]
  346. ifNotNil: [ aString
  347. ifNil: [ #() ]
  348. ifNotNil: [ self selectorsInProtocol: aString ] ]).
  349. self refresh
  350. ! !
  351. !HLMethodsListWidget methodsFor: 'rendering'!
  352. renderContentOn: html
  353. self model showInstance
  354. ifFalse: [ html div
  355. class: 'class_side';
  356. with: [ super renderContentOn: html ] ]
  357. ifTrue: [ super renderContentOn: html ]
  358. !
  359. renderItemLabel: aSelector on: html
  360. html with: aSelector
  361. ! !
  362. !HLMethodsListWidget methodsFor: 'testing'!
  363. isOverridden: aMethod
  364. ^ self selectorsCache isOverridden: aMethod
  365. !
  366. isOverride: aMethod
  367. ^ self selectorsCache isOverride: aMethod
  368. ! !
  369. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  370. !HLMethodsListWidget class methodsFor: 'accessing'!
  371. selectorsCache
  372. ^ HLSelectorsCache current
  373. ! !
  374. HLBrowserListWidget subclass: #HLPackagesListWidget
  375. instanceVariableNames: ''
  376. package: 'Helios-Browser'!
  377. !HLPackagesListWidget methodsFor: 'accessing'!
  378. initializeItems
  379. ^ items := self model packages sort:[:a :b|
  380. a name < b name]
  381. !
  382. items
  383. ^ items ifNil: [self initializeItems]
  384. ! !
  385. !HLPackagesListWidget methodsFor: 'actions'!
  386. focusClassesListWidget
  387. self model announcer announce: HLClassesListFocus new
  388. !
  389. observeModel
  390. self model announcer on: HLPackageSelected do: [ :ann |
  391. self onPackageSelected: ann item ]
  392. !
  393. selectItem: aPackage
  394. self model selectedPackage: aPackage
  395. ! !
  396. !HLPackagesListWidget methodsFor: 'reactions'!
  397. onPackageSelected: aPackage
  398. self selectedItem: aPackage.
  399. self focus
  400. ! !
  401. !HLPackagesListWidget methodsFor: 'rendering'!
  402. renderButtonsOn: html
  403. html span class: 'info'; with: 'Auto commit'.
  404. html div
  405. class: 'btn-group switch';
  406. at: 'data-toggle' put: 'buttons-radio';
  407. with: [
  408. html button
  409. class: (String streamContents: [ :str |
  410. str nextPutAll: 'btn' ]);
  411. with: 'On'.
  412. html button
  413. class: (String streamContents: [ :str |
  414. str nextPutAll: 'btn active' ]);
  415. with: 'Off' ].
  416. html a
  417. class: 'btn';
  418. with: 'Commit'.
  419. ! !
  420. HLBrowserListWidget subclass: #HLProtocolsListWidget
  421. instanceVariableNames: ''
  422. package: 'Helios-Browser'!
  423. !HLProtocolsListWidget methodsFor: 'accessing'!
  424. allProtocol
  425. ^ self model allProtocol
  426. !
  427. selectedItem
  428. ^ super selectedItem" ifNil: [ self allProtocol ]"
  429. ! !
  430. !HLProtocolsListWidget methodsFor: 'actions'!
  431. observeModel
  432. self model announcer on: HLClassSelected do: [ :ann |
  433. self onClassSelected: ann item ].
  434. self model announcer on: HLShowInstanceToggled do: [ :ann |
  435. self onClassSelected: self model selectedClass ].
  436. self model announcer on: HLProtocolSelected do: [ :ann |
  437. self onProtocolSelected: ann item ]
  438. !
  439. selectItem: aString
  440. self model selectedProtocol: aString
  441. ! !
  442. !HLProtocolsListWidget methodsFor: 'reactions'!
  443. onClassSelected: aClass
  444. self selectedItem: nil.
  445. self items: (aClass
  446. ifNil: [ Array with: self allProtocol ]
  447. ifNotNil: [
  448. (Array with: self allProtocol)
  449. addAll: aClass protocols;
  450. yourself ]).
  451. self refresh
  452. !
  453. onProtocolSelected: aString
  454. self selectedItem: aString.
  455. aString ifNil: [ ^ self ].
  456. self focus
  457. ! !
  458. !HLProtocolsListWidget methodsFor: 'rendering'!
  459. renderContentOn: html
  460. self model showInstance
  461. ifFalse: [ html div
  462. class: 'class_side';
  463. with: [ super renderContentOn: html ] ]
  464. ifTrue: [ super renderContentOn: html ]
  465. ! !
  466. Object subclass: #HLBrowserModel
  467. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  468. package: 'Helios-Browser'!
  469. !HLBrowserModel methodsFor: 'accessing'!
  470. allProtocol
  471. ^ '-- All --'
  472. !
  473. announcer
  474. ^ announcer ifNil: [ announcer := Announcer new ]
  475. !
  476. environment
  477. ^ environment ifNil: [ HLManager current environment ]
  478. !
  479. environment: anEnvironment
  480. environment := anEnvironment
  481. !
  482. packages
  483. ^ self environment packages
  484. !
  485. selectedClass
  486. ^ selectedClass
  487. !
  488. selectedClass: aClass
  489. selectedClass = aClass ifTrue: [ ^ self ].
  490. aClass
  491. ifNil: [ selectedClass := nil ]
  492. ifNotNil: [
  493. self showInstance
  494. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  495. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  496. self selectedProtocol: nil.
  497. self announcer announce: (HLClassSelected on: self selectedClass)
  498. !
  499. selectedMethod
  500. ^ self selectedClass
  501. ifNotNil: [ self selectedClass methodDictionary at: selectedSelector ]
  502. !
  503. selectedMethod: aCompiledMethod
  504. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  505. aCompiledMethod
  506. ifNil: [ selectedSelector := nil ]
  507. ifNotNil: [
  508. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  509. selectedSelector := aCompiledMethod selector ].
  510. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  511. !
  512. selectedPackage
  513. ^ selectedPackage
  514. !
  515. selectedPackage: aPackage
  516. selectedPackage = aPackage ifTrue: [ ^ self ].
  517. selectedPackage := aPackage.
  518. self selectedClass: nil.
  519. self announcer announce: (HLPackageSelected on: aPackage)
  520. !
  521. selectedProtocol
  522. ^ selectedProtocol
  523. !
  524. selectedProtocol: aString
  525. selectedProtocol = aString ifTrue: [ ^ self ].
  526. selectedProtocol := aString.
  527. self selectedMethod: nil.
  528. self announcer announce: (HLProtocolSelected on: aString)
  529. !
  530. showComment
  531. ^ showComment ifNil: [ false ]
  532. !
  533. showComment: aBoolean
  534. showComment := aBoolean.
  535. self announcer announce: HLShowCommentToggled new
  536. !
  537. showInstance
  538. ^ showInstance ifNil: [ true ]
  539. !
  540. showInstance: aBoolean
  541. showInstance := aBoolean.
  542. self selectedClass ifNotNil: [
  543. self selectedClass: (aBoolean
  544. ifTrue: [self selectedClass theNonMetaClass ]
  545. ifFalse: [ self selectedClass theMetaClass ]) ].
  546. self announcer announce: HLShowInstanceToggled new
  547. ! !
  548. !HLBrowserModel class methodsFor: 'actions'!
  549. on: anEnvironment
  550. ^ self new
  551. environment: anEnvironment;
  552. yourself
  553. ! !
  554. HLWidget subclass: #HLBrowserSourceWidget
  555. instanceVariableNames: 'model methodContents codeWidget'
  556. package: 'Helios-Browser'!
  557. !HLBrowserSourceWidget methodsFor: 'accessing'!
  558. codeWidget
  559. ^ codeWidget ifNil: [ codeWidget := HLCodeWidget new ]
  560. !
  561. contents
  562. ^ self codeWidget contents
  563. !
  564. contents: aString
  565. self methodContents: aString.
  566. self codeWidget contents: aString
  567. !
  568. methodContents
  569. ^ methodContents ifNil: [ methodContents := '' ]
  570. !
  571. methodContents: aString
  572. methodContents := aString
  573. !
  574. model
  575. ^ model
  576. !
  577. model: aBrowserModel
  578. model := aBrowserModel.
  579. self observeModel
  580. ! !
  581. !HLBrowserSourceWidget methodsFor: 'actions'!
  582. observeModel
  583. self model announcer on: HLMethodSelected do: [ :ann |
  584. self onMethodSelected: ann item ].
  585. self model announcer on: HLClassSelected do: [ :ann |
  586. self onClassSelected: ann item ].
  587. self model announcer on: HLProtocolSelected do: [ :ann |
  588. self onProtocolSelected: ann item ]
  589. !
  590. observeSystem
  591. SystemAnnouncer current
  592. on: MethodModified
  593. do: [ :ann | self onMethodModified: ann method ]
  594. ! !
  595. !HLBrowserSourceWidget methodsFor: 'initialization'!
  596. initialize
  597. super initialize.
  598. self observeSystem
  599. ! !
  600. !HLBrowserSourceWidget methodsFor: 'reactions'!
  601. onClassSelected: aClass
  602. aClass ifNil: [ ^ self contents: '' ].
  603. self contents: aClass definition
  604. !
  605. onMethodModified: aMethod
  606. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  607. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  608. self refresh
  609. !
  610. onMethodSelected: aCompiledMethod
  611. aCompiledMethod ifNil: [ ^ self contents: '' ].
  612. self contents: aCompiledMethod source
  613. !
  614. onProtocolSelected: aString
  615. self model selectedClass ifNil: [ ^ self contents: '' ].
  616. self contents: self model selectedClass definition
  617. ! !
  618. !HLBrowserSourceWidget methodsFor: 'rendering'!
  619. renderContentOn: html
  620. self codeWidget renderOn: html
  621. ! !
  622. !HLBrowserSourceWidget methodsFor: 'testing'!
  623. hasModification
  624. ^ (self methodContents = self contents) not
  625. ! !
  626. !HLBrowserSourceWidget methodsFor: 'updating'!
  627. refresh
  628. self hasModification ifTrue: [ ^ self ].
  629. self contents: self model selectedMethod source.
  630. super refresh
  631. ! !
  632. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  633. on: aBrowserModel
  634. ^ self new
  635. model: aBrowserModel;
  636. yourself
  637. ! !
  638. Object subclass: #HLClassCache
  639. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  640. package: 'Helios-Browser'!
  641. !HLClassCache methodsFor: 'accessing'!
  642. overriddenCache
  643. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  644. !
  645. overrideCache
  646. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  647. !
  648. selectorsCache
  649. ^ selectorsCache
  650. !
  651. selectorsCache: aCache
  652. selectorsCache := aCache
  653. !
  654. theClass
  655. ^ class
  656. !
  657. theClass: aClass
  658. class := aClass
  659. ! !
  660. !HLClassCache methodsFor: 'actions'!
  661. invalidateChildrenSelector: aSelector
  662. self theClass subclasses do: [ :each |
  663. (self selectorsCache cacheFor: each)
  664. removeSelector: aSelector;
  665. invalidateChildrenSelector: aSelector ]
  666. !
  667. invalidateParentSelector: aSelector
  668. self theClass superclass ifNotNil: [
  669. (self selectorsCache cacheFor: self theClass superclass)
  670. removeSelector: aSelector;
  671. invalidateParentSelector: aSelector ]
  672. !
  673. invalidateSelector: aSelector
  674. self
  675. invalidateParentSelector: aSelector;
  676. invalidateChildrenSelector: aSelector;
  677. removeSelector: aSelector
  678. ! !
  679. !HLClassCache methodsFor: 'private'!
  680. removeSelector: aSelector
  681. self overriddenCache
  682. removeKey: aSelector
  683. ifAbsent: [ ].
  684. self overrideCache
  685. removeKey: aSelector
  686. ifAbsent: [ ]
  687. ! !
  688. !HLClassCache methodsFor: 'testing'!
  689. isOverridden: aMethod
  690. ^ self overriddenCache
  691. at: aMethod selector
  692. ifAbsentPut: [ aMethod isOverridden ]
  693. !
  694. isOverride: aMethod
  695. ^ self overrideCache
  696. at: aMethod selector
  697. ifAbsentPut: [ aMethod isOverride ]
  698. ! !
  699. !HLClassCache class methodsFor: 'instance creation'!
  700. on: aClass selectorsCache: aSelectorsCache
  701. ^ self new
  702. theClass: aClass;
  703. selectorsCache: aSelectorsCache;
  704. yourself
  705. ! !
  706. Object subclass: #HLSelectorsCache
  707. instanceVariableNames: 'classesCache'
  708. package: 'Helios-Browser'!
  709. !HLSelectorsCache methodsFor: 'accessing'!
  710. cacheFor: aClass
  711. aClass ifNil: [ ^ nil ].
  712. ^ self classesCache
  713. at: aClass name
  714. ifAbsentPut: [ self newCacheFor: aClass ]
  715. !
  716. classesCache
  717. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  718. ! !
  719. !HLSelectorsCache methodsFor: 'actions'!
  720. observeSystem
  721. SystemAnnouncer current
  722. on: MethodAdded
  723. do: [ :ann | self onMethodAdded: ann method ];
  724. on: MethodRemoved
  725. do: [ :ann | self onMethodRemoved: ann method ]
  726. ! !
  727. !HLSelectorsCache methodsFor: 'factory'!
  728. newCacheFor: aClass
  729. ^ HLClassCache
  730. on: aClass
  731. selectorsCache: self
  732. ! !
  733. !HLSelectorsCache methodsFor: 'initialization'!
  734. initialize
  735. super initialize.
  736. self observeSystem
  737. ! !
  738. !HLSelectorsCache methodsFor: 'private'!
  739. invalidateCacheFor: aMethod
  740. (self cacheFor: aMethod methodClass)
  741. invalidateSelector: aMethod selector
  742. ! !
  743. !HLSelectorsCache methodsFor: 'reactions'!
  744. onMethodAdded: aMethod
  745. self invalidateCacheFor: aMethod
  746. !
  747. onMethodRemoved: aMethod
  748. self invalidateCacheFor: aMethod
  749. ! !
  750. !HLSelectorsCache methodsFor: 'testing'!
  751. isOverridden: aMethod
  752. ^ (self cacheFor: aMethod methodClass)
  753. isOverridden: aMethod
  754. !
  755. isOverride: aMethod
  756. ^ (self cacheFor: aMethod methodClass)
  757. isOverride: aMethod
  758. ! !
  759. HLSelectorsCache class instanceVariableNames: 'current'!
  760. !HLSelectorsCache class methodsFor: 'accessing'!
  761. current
  762. ^ current ifNil: [ current := super new ]
  763. !
  764. flush
  765. current := nil
  766. ! !
  767. !HLSelectorsCache class methodsFor: 'instance creation'!
  768. new
  769. self shouldNotImplement
  770. ! !
  771. !CompiledMethod methodsFor: '*Helios-Browser'!
  772. isOverridden
  773. | selector |
  774. selector := self selector.
  775. self methodClass allSubclassesDo: [ :each |
  776. (each includesSelector: selector)
  777. ifTrue: [ ^ true ] ].
  778. ^ false
  779. !
  780. isOverride
  781. | superclass |
  782. superclass := self methodClass superclass.
  783. superclass ifNil: [ ^ false ].
  784. ^ (self methodClass superclass lookupSelector: self selector) isNil
  785. ! !