Helios-References.st 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. Smalltalk current createPackage: 'Helios-References'!
  2. HLWidget subclass: #HLReferences
  3. instanceVariableNames: 'model sendersListWidget implementorsListWidget classReferencesListWidget regexpListWidget sourceCodeWidget'
  4. package: 'Helios-References'!
  5. !HLReferences methodsFor: 'accessing'!
  6. classReferencesListWidget
  7. ^ classReferencesListWidget ifNil: [
  8. classReferencesListWidget := HLClassReferencesListWidget on: self model.
  9. classReferencesListWidget next: self regexpListWidget ]
  10. !
  11. implementorsListWidget
  12. ^ implementorsListWidget ifNil: [
  13. implementorsListWidget := HLImplementorsListWidget on: self model.
  14. implementorsListWidget next: self classReferencesListWidget ]
  15. !
  16. model
  17. ^ model ifNil: [
  18. model := (HLReferencesModel new
  19. environment: self manager environment;
  20. yourself) ]
  21. !
  22. model: aModel
  23. model := aModel
  24. !
  25. regexpListWidget
  26. ^ regexpListWidget ifNil: [
  27. regexpListWidget := HLRegexpListWidget on: self model.
  28. regexpListWidget next: self sourceCodeWidget ]
  29. !
  30. sendersListWidget
  31. ^ sendersListWidget ifNil: [
  32. sendersListWidget := HLSendersListWidget on: self model.
  33. sendersListWidget next: self implementorsListWidget ]
  34. !
  35. sourceCodeWidget
  36. ^ sourceCodeWidget ifNil: [
  37. sourceCodeWidget := HLBrowserCodeWidget new
  38. browserModel: self model;
  39. yourself ]
  40. ! !
  41. !HLReferences methodsFor: 'actions'!
  42. open
  43. HLManager current addTab: (HLTab on: self labelled: self class tabLabel)
  44. !
  45. search: aString
  46. self model search: aString
  47. ! !
  48. !HLReferences methodsFor: 'rendering'!
  49. renderContentOn: html
  50. html with: (HLContainer with: (HLHorizontalSplitter
  51. with: (HLVerticalSplitter
  52. with: (HLVerticalSplitter
  53. with: self sendersListWidget
  54. with: self implementorsListWidget)
  55. with: (HLVerticalSplitter
  56. with: self classReferencesListWidget
  57. with: self regexpListWidget))
  58. with: self sourceCodeWidget)).
  59. self sendersListWidget focus
  60. ! !
  61. !HLReferences class methodsFor: 'accessing'!
  62. tabLabel
  63. ^ 'References'
  64. !
  65. tabPriority
  66. ^ 100
  67. ! !
  68. !HLReferences class methodsFor: 'testing'!
  69. canBeOpenAsTab
  70. ^ false
  71. ! !
  72. HLBrowserListWidget subclass: #HLReferencesListWidget
  73. instanceVariableNames: 'model'
  74. package: 'Helios-References'!
  75. !HLReferencesListWidget methodsFor: 'accessing'!
  76. commandCategory
  77. ^ 'Methods'
  78. !
  79. label
  80. ^ 'List'
  81. ! !
  82. !HLReferencesListWidget methodsFor: 'actions'!
  83. activateListItem: anItem
  84. self model withChangesDo: [ super activateListItem: anItem ]
  85. !
  86. observeModel
  87. self model announcer
  88. on: HLSearchReferences
  89. do: [ :ann | self onSearchReferences: ann searchString ];
  90. on: HLMethodSelected
  91. do: [ :ann | self onMethodSelected: ann item ]
  92. !
  93. selectItem: aMethod
  94. self model selectedMethod: aMethod
  95. ! !
  96. !HLReferencesListWidget methodsFor: 'reactions'!
  97. onMethodSelected: aMethod
  98. aMethod ifNil: [ ^ self ].
  99. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  100. self
  101. selectedItem: aMethod selector;
  102. activateItem: aMethod selector
  103. !
  104. onSearchReferences: aString
  105. self subclassResponsibility
  106. ! !
  107. !HLReferencesListWidget methodsFor: 'rendering'!
  108. renderItemLabel: aMethod on: html
  109. html with: aMethod methodClass name, ' >> #', aMethod selector
  110. ! !
  111. !HLReferencesListWidget class methodsFor: 'instance creation'!
  112. on: aModel
  113. ^ self new
  114. model: aModel;
  115. yourself
  116. ! !
  117. HLReferencesListWidget subclass: #HLClassReferencesListWidget
  118. instanceVariableNames: ''
  119. package: 'Helios-References'!
  120. !HLClassReferencesListWidget methodsFor: 'accessing'!
  121. label
  122. ^ 'Class references'
  123. ! !
  124. !HLClassReferencesListWidget methodsFor: 'reactions'!
  125. onSearchReferences: aString
  126. self selectItem: nil.
  127. self items: (self model classReferencesOf: aString).
  128. self refresh
  129. ! !
  130. HLReferencesListWidget subclass: #HLImplementorsListWidget
  131. instanceVariableNames: ''
  132. package: 'Helios-References'!
  133. !HLImplementorsListWidget methodsFor: 'accessing'!
  134. label
  135. ^ 'Implementors'
  136. ! !
  137. !HLImplementorsListWidget methodsFor: 'reactions'!
  138. onSearchReferences: aString
  139. self selectItem: nil.
  140. self items: (self model implementorsOf: aString).
  141. self refresh
  142. ! !
  143. HLReferencesListWidget subclass: #HLRegexpListWidget
  144. instanceVariableNames: ''
  145. package: 'Helios-References'!
  146. !HLRegexpListWidget methodsFor: 'accessing'!
  147. label
  148. ^ 'Source search'
  149. ! !
  150. !HLRegexpListWidget methodsFor: 'reactions'!
  151. onSearchReferences: aString
  152. self selectItem: nil.
  153. self items: (self model regexpReferencesOf: aString).
  154. self refresh
  155. ! !
  156. HLReferencesListWidget subclass: #HLSendersListWidget
  157. instanceVariableNames: ''
  158. package: 'Helios-References'!
  159. !HLSendersListWidget methodsFor: 'accessing'!
  160. label
  161. ^ 'Senders'
  162. ! !
  163. !HLSendersListWidget methodsFor: 'reactions'!
  164. onSearchReferences: aString
  165. self selectItem: nil.
  166. self items: (self model sendersOf: aString).
  167. self refresh
  168. ! !
  169. HLModel subclass: #HLReferencesModel
  170. instanceVariableNames: 'methodsCache classesAndMetaclassesCache selectedMethod'
  171. package: 'Helios-References'!
  172. !HLReferencesModel methodsFor: 'accessing'!
  173. allMethods
  174. ^ self methodsCache
  175. !
  176. allSelectors
  177. ^ (self allMethods
  178. collect: [ :each | each selector ])
  179. asSet
  180. !
  181. classReferencesOf: aString
  182. "Answer all methods referencing the class named aString"
  183. | references |
  184. references := OrderedCollection new.
  185. self classesAndMetaclasses do: [ :each |
  186. each methodDictionary values do: [ :method |
  187. (method referencedClasses includes: aString) ifTrue: [
  188. references add: method ] ] ].
  189. ^ references
  190. !
  191. classesAndMetaclasses
  192. ^ self classesAndMetaclassesCache
  193. !
  194. implementorsOf: aString
  195. ^ self allMethods select: [ :each |
  196. each selector = aString ]
  197. !
  198. regexpReferencesOf: aString
  199. ^ self allMethods select: [ :each |
  200. each source match: aString ]
  201. !
  202. selectedClass
  203. ^ self selectedMethod ifNotNil: [ :method |
  204. method methodClass ]
  205. !
  206. selectedMethod
  207. ^ selectedMethod
  208. !
  209. selectedMethod: aMethod
  210. self withChangesDo: [
  211. selectedMethod := aMethod.
  212. self announcer announce: (HLMethodSelected new
  213. item: aMethod;
  214. yourself) ]
  215. !
  216. sendersOf: aString
  217. ^ self allMethods select: [ :each |
  218. each messageSends includes: aString ]
  219. ! !
  220. !HLReferencesModel methodsFor: 'actions'!
  221. search: aString
  222. self updateCaches.
  223. self announcer announce: (HLSearchReferences new
  224. searchString: aString;
  225. yourself)
  226. ! !
  227. !HLReferencesModel methodsFor: 'cache'!
  228. classesAndMetaclassesCache
  229. classesAndMetaclassesCache ifNil: [ self updateClassesAndMetaclassesCache ].
  230. ^ classesAndMetaclassesCache
  231. !
  232. methodsCache
  233. methodsCache ifNil: [ self updateMethodsCache ].
  234. ^ methodsCache
  235. !
  236. updateCaches
  237. self
  238. updateClassesAndMetaclassesCache;
  239. updateMethodsCache
  240. !
  241. updateClassesAndMetaclassesCache
  242. classesAndMetaclassesCache := self environment classes
  243. inject: OrderedCollection new
  244. into: [ :acc :each |
  245. acc
  246. add: each;
  247. add: each class;
  248. yourself ]
  249. !
  250. updateMethodsCache
  251. methodsCache := self classesAndMetaclasses
  252. inject: OrderedCollection new
  253. into: [ :acc :each |
  254. acc, each methods ]
  255. ! !