Helios-References.st 7.7 KB

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