Helios-Browser.st 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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. sort: [:a :b | a name < b name ] ]).
  160. !
  161. setItemsForSelectedPackage
  162. self setItemsForPackage: self model selectedPackage
  163. ! !
  164. !HLClassesListWidget methodsFor: 'reactions'!
  165. onClassAdded: aClass
  166. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  167. self setItemsForSelectedPackage.
  168. self refresh
  169. !
  170. onClassRemoved: aClass
  171. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  172. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  173. self setItemsForSelectedPackage.
  174. self refresh
  175. !
  176. onClassSelected: aClass
  177. self selectedItem: aClass.
  178. aClass ifNil: [ ^ self ].
  179. self focus
  180. !
  181. onPackageSelected: aPackage
  182. self selectedItem: nil.
  183. self setItemsForSelectedPackage.
  184. self refresh
  185. !
  186. onShowInstanceToggled
  187. self refresh
  188. ! !
  189. !HLClassesListWidget methodsFor: 'rendering'!
  190. renderButtonsOn: html
  191. html div
  192. class: 'btn-group';
  193. at: 'data-toggle' put: 'buttons-radio';
  194. with: [
  195. html button
  196. class: (String streamContents: [ :str |
  197. str nextPutAll: 'btn'.
  198. self showInstance ifTrue: [
  199. str nextPutAll: ' active'] ]);
  200. with: 'Instance';
  201. onClick: [ self showInstance: true ].
  202. html button
  203. class: (String streamContents: [ :str |
  204. str nextPutAll: 'btn'.
  205. self model showInstance ifFalse: [
  206. str nextPutAll: ' active'] ]);
  207. with: 'Class';
  208. onClick: [ self model showInstance: false ] ].
  209. html button
  210. class: 'btn';
  211. at: 'data-toggle' put: 'button';
  212. with: 'Comment'
  213. !
  214. renderItem: aClass level: anInteger on: html
  215. | li |
  216. li := html li.
  217. li
  218. at: 'list-data' put: (self items indexOf: aClass);
  219. class: (self cssClassForItem: aClass);
  220. with: [
  221. html a
  222. with: [
  223. (html tag: 'i') class: (self iconForItem: aClass).
  224. self renderItemLabel: aClass level: anInteger on: html ];
  225. onClick: [
  226. self activateListItem: li asJQuery ] ].
  227. (self getChildrenOf: aClass) do: [ :each |
  228. self renderItem: each level: anInteger + 1 on: html ]
  229. !
  230. renderItem: aClass on: html
  231. super renderItem: aClass on: html.
  232. (self getChildrenOf: aClass) do: [ :each |
  233. self renderItem: each level: 1 on: html ]
  234. !
  235. renderItemLabel: aClass level: anInteger on: html
  236. html span asJQuery html: (String streamContents: [ :str |
  237. anInteger timesRepeat: [
  238. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  239. str nextPutAll: aClass name ])
  240. !
  241. renderItemLabel: aClass on: html
  242. self renderItemLabel: aClass level: 0 on: html
  243. !
  244. renderListOn: html
  245. (self getRootClassesOf: self items)
  246. do: [ :each | self renderItem: each on: html ]
  247. ! !
  248. HLBrowserListWidget subclass: #HLMethodsListWidget
  249. instanceVariableNames: ''
  250. package: 'Helios-Browser'!
  251. !HLMethodsListWidget methodsFor: 'accessing'!
  252. allProtocol
  253. ^ self model allProtocol
  254. !
  255. iconForItem: aSelector
  256. | override overriden method |
  257. method := self methodForSelector: aSelector.
  258. override := self isOverride: method.
  259. overriden := self isOverridden: method.
  260. ^ override
  261. ifTrue: [ overriden
  262. ifTrue: [ 'icon-resize-vertical' ]
  263. ifFalse: [ 'icon-arrow-up' ] ]
  264. ifFalse: [
  265. overriden
  266. ifTrue: [ 'icon-arrow-down' ]
  267. ifFalse: [ 'icon-none' ] ]
  268. !
  269. methodForSelector: aSelector
  270. ^ self model selectedClass
  271. methodDictionary at: aSelector
  272. !
  273. methodsInProtocol: aString
  274. self model selectedClass ifNil: [ ^ #() ].
  275. ^ aString = self allProtocol
  276. ifTrue: [ self model selectedClass methods ]
  277. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  278. !
  279. overrideSelectors
  280. ^ self selectorsCache
  281. at: 'override'
  282. ifAbsentPut: [
  283. self model selectedClass allSuperclasses
  284. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  285. !
  286. overridenSelectors
  287. ^ self selectorsCache
  288. at: 'overriden'
  289. ifAbsentPut: [
  290. self model selectedClass allSubclasses
  291. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  292. !
  293. selectorsCache
  294. ^ self class selectorsCache
  295. !
  296. selectorsInProtocol: aString
  297. ^ (self methodsInProtocol: aString)
  298. collect: [ :each | each selector ]
  299. ! !
  300. !HLMethodsListWidget methodsFor: 'actions'!
  301. observeModel
  302. self model announcer on: HLProtocolSelected do: [ :ann |
  303. self onProtocolSelected: ann item ].
  304. self model announcer on: HLShowInstanceToggled do: [ :ann |
  305. self onProtocolSelected: nil ].
  306. self model announcer on: HLMethodSelected do: [ :ann |
  307. self onMethodSelected: ann item ]
  308. !
  309. observeSystem
  310. SystemAnnouncer current
  311. on: MethodAdded
  312. do: [ :ann | self onMethodAdded: ann method ];
  313. on: MethodRemoved
  314. do: [ :ann | self onMethodRemoved: ann method ]
  315. !
  316. selectItem: aSelector
  317. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  318. self model selectedMethod: (self methodForSelector: aSelector)
  319. ! !
  320. !HLMethodsListWidget methodsFor: 'cache'!
  321. flushSelectorsCache
  322. selectorsCache := Dictionary new
  323. ! !
  324. !HLMethodsListWidget methodsFor: 'initialization'!
  325. initialize
  326. super initialize.
  327. self flushSelectorsCache
  328. ! !
  329. !HLMethodsListWidget methodsFor: 'private'!
  330. setItemsForProtocol: aString
  331. ^ self items: (aString
  332. ifNil: [ #() ]
  333. ifNotNil: [ self selectorsInProtocol: aString ])
  334. !
  335. setItemsForSelectedProtocol
  336. self setItemsForProtocol: self model selectedProtocol
  337. ! !
  338. !HLMethodsListWidget methodsFor: 'reactions'!
  339. onMethodAdded: aMethod
  340. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  341. self setItemsForSelectedProtocol.
  342. self refresh
  343. !
  344. onMethodRemoved: aMethod
  345. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  346. self selectedItem ifNotNil: [
  347. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  348. ifTrue: [ self selectItem: nil ] ].
  349. self setItemsForSelectedProtocol.
  350. self refresh
  351. !
  352. onMethodSelected: aMethod
  353. self selectedItem: aMethod.
  354. aMethod ifNil: [ ^ self ].
  355. self focus
  356. !
  357. onProtocolSelected: aString
  358. self selectedItem: nil.
  359. self setItemsForSelectedProtocol.
  360. self refresh
  361. ! !
  362. !HLMethodsListWidget methodsFor: 'rendering'!
  363. renderContentOn: html
  364. self model showInstance
  365. ifFalse: [ html div
  366. class: 'class_side';
  367. with: [ super renderContentOn: html ] ]
  368. ifTrue: [ super renderContentOn: html ]
  369. !
  370. renderItemLabel: aSelector on: html
  371. html with: aSelector
  372. ! !
  373. !HLMethodsListWidget methodsFor: 'testing'!
  374. isOverridden: aMethod
  375. ^ self selectorsCache isOverridden: aMethod
  376. !
  377. isOverride: aMethod
  378. ^ self selectorsCache isOverride: aMethod
  379. ! !
  380. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  381. !HLMethodsListWidget class methodsFor: 'accessing'!
  382. selectorsCache
  383. ^ HLSelectorsCache current
  384. ! !
  385. HLBrowserListWidget subclass: #HLPackagesListWidget
  386. instanceVariableNames: ''
  387. package: 'Helios-Browser'!
  388. !HLPackagesListWidget methodsFor: 'accessing'!
  389. initializeItems
  390. ^ items := self model packages sort:[:a :b|
  391. a name < b name]
  392. !
  393. items
  394. ^ items ifNil: [self initializeItems]
  395. ! !
  396. !HLPackagesListWidget methodsFor: 'actions'!
  397. focusClassesListWidget
  398. self model announcer announce: HLClassesListFocus new
  399. !
  400. observeModel
  401. self model announcer on: HLPackageSelected do: [ :ann |
  402. self onPackageSelected: ann item ]
  403. !
  404. selectItem: aPackage
  405. self model selectedPackage: aPackage
  406. ! !
  407. !HLPackagesListWidget methodsFor: 'reactions'!
  408. onPackageSelected: aPackage
  409. self selectedItem: aPackage.
  410. self focus
  411. ! !
  412. !HLPackagesListWidget methodsFor: 'rendering'!
  413. renderButtonsOn: html
  414. html span class: 'info'; with: 'Auto commit'.
  415. html div
  416. class: 'btn-group switch';
  417. at: 'data-toggle' put: 'buttons-radio';
  418. with: [
  419. html button
  420. class: (String streamContents: [ :str |
  421. str nextPutAll: 'btn' ]);
  422. with: 'On'.
  423. html button
  424. class: (String streamContents: [ :str |
  425. str nextPutAll: 'btn active' ]);
  426. with: 'Off' ].
  427. html a
  428. class: 'btn';
  429. with: 'Commit'.
  430. ! !
  431. HLBrowserListWidget subclass: #HLProtocolsListWidget
  432. instanceVariableNames: ''
  433. package: 'Helios-Browser'!
  434. !HLProtocolsListWidget methodsFor: 'accessing'!
  435. allProtocol
  436. ^ self model allProtocol
  437. !
  438. selectedItem
  439. ^ super selectedItem" ifNil: [ self allProtocol ]"
  440. ! !
  441. !HLProtocolsListWidget methodsFor: 'actions'!
  442. observeModel
  443. self model announcer on: HLClassSelected do: [ :ann |
  444. self onClassSelected: ann item ].
  445. self model announcer on: HLShowInstanceToggled do: [ :ann |
  446. self onClassSelected: self model selectedClass ].
  447. self model announcer on: HLProtocolSelected do: [ :ann |
  448. self onProtocolSelected: ann item ]
  449. !
  450. observeSystem
  451. SystemAnnouncer current
  452. on: ProtocolAdded
  453. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  454. on: ProtocolRemoved
  455. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  456. !
  457. selectItem: aString
  458. self model selectedProtocol: aString
  459. ! !
  460. !HLProtocolsListWidget methodsFor: 'private'!
  461. setItemsForClass: aClass
  462. self items: (aClass
  463. ifNil: [ Array with: self allProtocol ]
  464. ifNotNil: [
  465. (Array with: self allProtocol)
  466. addAll: aClass protocols;
  467. yourself ])
  468. !
  469. setItemsForSelectedClass
  470. self setItemsForClass: self model selectedClass
  471. ! !
  472. !HLProtocolsListWidget methodsFor: 'reactions'!
  473. onClassSelected: aClass
  474. self selectedItem: nil.
  475. self setItemsForSelectedClass.
  476. self refresh
  477. !
  478. onProtocolAdded: aString to: aClass
  479. aClass = self model selectedClass ifFalse: [ ^ self ].
  480. self setItemsForSelectedClass.
  481. self refresh
  482. !
  483. onProtocolRemoved: aString from: aClass
  484. aClass = self model selectedClass ifFalse: [ ^ self ].
  485. self model selectedProtocol = aString
  486. ifTrue: [ self selectItem: nil ].
  487. self setItemsForSelectedClass.
  488. self refresh
  489. !
  490. onProtocolSelected: aString
  491. self selectedItem: aString.
  492. aString ifNil: [ ^ self ].
  493. self focus
  494. ! !
  495. !HLProtocolsListWidget methodsFor: 'rendering'!
  496. renderContentOn: html
  497. self model showInstance
  498. ifFalse: [ html div
  499. class: 'class_side';
  500. with: [ super renderContentOn: html ] ]
  501. ifTrue: [ super renderContentOn: html ]
  502. ! !
  503. Object subclass: #HLBrowserModel
  504. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  505. package: 'Helios-Browser'!
  506. !HLBrowserModel methodsFor: 'accessing'!
  507. allProtocol
  508. ^ '-- All --'
  509. !
  510. announcer
  511. ^ announcer ifNil: [ announcer := Announcer new ]
  512. !
  513. environment
  514. ^ environment ifNil: [ HLManager current environment ]
  515. !
  516. environment: anEnvironment
  517. environment := anEnvironment
  518. !
  519. packages
  520. ^ self environment packages
  521. !
  522. selectedClass
  523. ^ selectedClass
  524. !
  525. selectedClass: aClass
  526. selectedClass = aClass ifTrue: [ ^ self ].
  527. aClass
  528. ifNil: [ selectedClass := nil ]
  529. ifNotNil: [
  530. self showInstance
  531. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  532. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  533. self selectedProtocol: nil.
  534. self announcer announce: (HLClassSelected on: self selectedClass)
  535. !
  536. selectedMethod
  537. ^ self selectedClass
  538. ifNotNil: [ self selectedClass methodDictionary at: selectedSelector ]
  539. !
  540. selectedMethod: aCompiledMethod
  541. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  542. aCompiledMethod
  543. ifNil: [ selectedSelector := nil ]
  544. ifNotNil: [
  545. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  546. selectedSelector := aCompiledMethod selector ].
  547. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  548. !
  549. selectedPackage
  550. ^ selectedPackage
  551. !
  552. selectedPackage: aPackage
  553. selectedPackage = aPackage ifTrue: [ ^ self ].
  554. selectedPackage := aPackage.
  555. self selectedClass: nil.
  556. self announcer announce: (HLPackageSelected on: aPackage)
  557. !
  558. selectedProtocol
  559. ^ selectedProtocol
  560. !
  561. selectedProtocol: aString
  562. selectedProtocol = aString ifTrue: [ ^ self ].
  563. selectedProtocol := aString.
  564. self selectedMethod: nil.
  565. self announcer announce: (HLProtocolSelected on: aString)
  566. !
  567. showComment
  568. ^ showComment ifNil: [ false ]
  569. !
  570. showComment: aBoolean
  571. showComment := aBoolean.
  572. self announcer announce: HLShowCommentToggled new
  573. !
  574. showInstance
  575. ^ showInstance ifNil: [ true ]
  576. !
  577. showInstance: aBoolean
  578. showInstance := aBoolean.
  579. self selectedClass ifNotNil: [
  580. self selectedClass: (aBoolean
  581. ifTrue: [self selectedClass theNonMetaClass ]
  582. ifFalse: [ self selectedClass theMetaClass ]) ].
  583. self announcer announce: HLShowInstanceToggled new
  584. ! !
  585. !HLBrowserModel class methodsFor: 'actions'!
  586. on: anEnvironment
  587. ^ self new
  588. environment: anEnvironment;
  589. yourself
  590. ! !
  591. HLWidget subclass: #HLBrowserSourceWidget
  592. instanceVariableNames: 'model methodContents codeWidget'
  593. package: 'Helios-Browser'!
  594. !HLBrowserSourceWidget methodsFor: 'accessing'!
  595. codeWidget
  596. ^ codeWidget ifNil: [ codeWidget := HLCodeWidget new ]
  597. !
  598. contents
  599. ^ self codeWidget contents
  600. !
  601. contents: aString
  602. self methodContents: aString.
  603. self codeWidget contents: aString
  604. !
  605. methodContents
  606. ^ methodContents ifNil: [ methodContents := '' ]
  607. !
  608. methodContents: aString
  609. methodContents := aString
  610. !
  611. model
  612. ^ model
  613. !
  614. model: aBrowserModel
  615. model := aBrowserModel.
  616. self observeModel
  617. ! !
  618. !HLBrowserSourceWidget methodsFor: 'actions'!
  619. observeModel
  620. self model announcer on: HLMethodSelected do: [ :ann |
  621. self onMethodSelected: ann item ].
  622. self model announcer on: HLClassSelected do: [ :ann |
  623. self onClassSelected: ann item ].
  624. self model announcer on: HLProtocolSelected do: [ :ann |
  625. self onProtocolSelected: ann item ]
  626. !
  627. observeSystem
  628. SystemAnnouncer current
  629. on: MethodModified
  630. do: [ :ann | self onMethodModified: ann method ]
  631. ! !
  632. !HLBrowserSourceWidget methodsFor: 'initialization'!
  633. initialize
  634. super initialize.
  635. self observeSystem
  636. ! !
  637. !HLBrowserSourceWidget methodsFor: 'reactions'!
  638. onClassSelected: aClass
  639. aClass ifNil: [ ^ self contents: '' ].
  640. self contents: aClass definition
  641. !
  642. onMethodModified: aMethod
  643. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  644. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  645. self refresh
  646. !
  647. onMethodSelected: aCompiledMethod
  648. aCompiledMethod ifNil: [ ^ self contents: '' ].
  649. self contents: aCompiledMethod source
  650. !
  651. onProtocolSelected: aString
  652. self model selectedClass ifNil: [ ^ self contents: '' ].
  653. self contents: self model selectedClass definition
  654. ! !
  655. !HLBrowserSourceWidget methodsFor: 'rendering'!
  656. renderContentOn: html
  657. self codeWidget renderOn: html
  658. ! !
  659. !HLBrowserSourceWidget methodsFor: 'testing'!
  660. hasModification
  661. ^ (self methodContents = self contents) not
  662. ! !
  663. !HLBrowserSourceWidget methodsFor: 'updating'!
  664. refresh
  665. self hasModification ifTrue: [ ^ self ].
  666. self contents: self model selectedMethod source.
  667. super refresh
  668. ! !
  669. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  670. on: aBrowserModel
  671. ^ self new
  672. model: aBrowserModel;
  673. yourself
  674. ! !
  675. Object subclass: #HLClassCache
  676. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  677. package: 'Helios-Browser'!
  678. !HLClassCache methodsFor: 'accessing'!
  679. overriddenCache
  680. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  681. !
  682. overrideCache
  683. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  684. !
  685. selectorsCache
  686. ^ selectorsCache
  687. !
  688. selectorsCache: aCache
  689. selectorsCache := aCache
  690. !
  691. theClass
  692. ^ class
  693. !
  694. theClass: aClass
  695. class := aClass
  696. ! !
  697. !HLClassCache methodsFor: 'actions'!
  698. invalidateChildrenSelector: aSelector
  699. self theClass subclasses do: [ :each |
  700. (self selectorsCache cacheFor: each)
  701. removeSelector: aSelector;
  702. invalidateChildrenSelector: aSelector ]
  703. !
  704. invalidateParentSelector: aSelector
  705. self theClass superclass ifNotNil: [
  706. (self selectorsCache cacheFor: self theClass superclass)
  707. removeSelector: aSelector;
  708. invalidateParentSelector: aSelector ]
  709. !
  710. invalidateSelector: aSelector
  711. self
  712. invalidateParentSelector: aSelector;
  713. invalidateChildrenSelector: aSelector;
  714. removeSelector: aSelector
  715. ! !
  716. !HLClassCache methodsFor: 'private'!
  717. removeSelector: aSelector
  718. self overriddenCache
  719. removeKey: aSelector
  720. ifAbsent: [ ].
  721. self overrideCache
  722. removeKey: aSelector
  723. ifAbsent: [ ]
  724. ! !
  725. !HLClassCache methodsFor: 'testing'!
  726. isOverridden: aMethod
  727. ^ self overriddenCache
  728. at: aMethod selector
  729. ifAbsentPut: [ aMethod isOverridden ]
  730. !
  731. isOverride: aMethod
  732. ^ self overrideCache
  733. at: aMethod selector
  734. ifAbsentPut: [ aMethod isOverride ]
  735. ! !
  736. !HLClassCache class methodsFor: 'instance creation'!
  737. on: aClass selectorsCache: aSelectorsCache
  738. ^ self new
  739. theClass: aClass;
  740. selectorsCache: aSelectorsCache;
  741. yourself
  742. ! !
  743. Object subclass: #HLSelectorsCache
  744. instanceVariableNames: 'classesCache'
  745. package: 'Helios-Browser'!
  746. !HLSelectorsCache methodsFor: 'accessing'!
  747. cacheFor: aClass
  748. aClass ifNil: [ ^ nil ].
  749. ^ self classesCache
  750. at: aClass name
  751. ifAbsentPut: [ self newCacheFor: aClass ]
  752. !
  753. classesCache
  754. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  755. ! !
  756. !HLSelectorsCache methodsFor: 'actions'!
  757. observeSystem
  758. SystemAnnouncer current
  759. on: MethodAdded
  760. do: [ :ann | self onMethodAdded: ann method ];
  761. on: MethodRemoved
  762. do: [ :ann | self onMethodRemoved: ann method ]
  763. ! !
  764. !HLSelectorsCache methodsFor: 'factory'!
  765. newCacheFor: aClass
  766. ^ HLClassCache
  767. on: aClass
  768. selectorsCache: self
  769. ! !
  770. !HLSelectorsCache methodsFor: 'initialization'!
  771. initialize
  772. super initialize.
  773. self observeSystem
  774. ! !
  775. !HLSelectorsCache methodsFor: 'private'!
  776. invalidateCacheFor: aMethod
  777. (self cacheFor: aMethod methodClass)
  778. invalidateSelector: aMethod selector
  779. ! !
  780. !HLSelectorsCache methodsFor: 'reactions'!
  781. onMethodAdded: aMethod
  782. self invalidateCacheFor: aMethod
  783. !
  784. onMethodRemoved: aMethod
  785. self invalidateCacheFor: aMethod
  786. ! !
  787. !HLSelectorsCache methodsFor: 'testing'!
  788. isOverridden: aMethod
  789. ^ (self cacheFor: aMethod methodClass)
  790. isOverridden: aMethod
  791. !
  792. isOverride: aMethod
  793. ^ (self cacheFor: aMethod methodClass)
  794. isOverride: aMethod
  795. ! !
  796. HLSelectorsCache class instanceVariableNames: 'current'!
  797. !HLSelectorsCache class methodsFor: 'accessing'!
  798. current
  799. ^ current ifNil: [ current := super new ]
  800. !
  801. flush
  802. current := nil
  803. ! !
  804. !HLSelectorsCache class methodsFor: 'instance creation'!
  805. new
  806. self shouldNotImplement
  807. ! !
  808. !CompiledMethod methodsFor: '*Helios-Browser'!
  809. isOverridden
  810. | selector |
  811. selector := self selector.
  812. self methodClass allSubclassesDo: [ :each |
  813. (each includesSelector: selector)
  814. ifTrue: [ ^ true ] ].
  815. ^ false
  816. !
  817. isOverride
  818. | superclass |
  819. superclass := self methodClass superclass.
  820. superclass ifNil: [ ^ false ].
  821. ^ (self methodClass superclass lookupSelector: self selector) notNil
  822. ! !