Helios-References.st 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. Smalltalk createPackage: 'Helios-References'!
  2. HLWidget subclass: #HLReferences
  3. slots: {#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. registerBindingsOn: aBindingGroup
  43. HLToolCommand
  44. registerConcreteClassesOn: aBindingGroup
  45. for: self model
  46. !
  47. search: aString
  48. self model search: aString.
  49. self setTabLabel: aString
  50. ! !
  51. !HLReferences methodsFor: 'rendering'!
  52. renderContentOn: html
  53. html with: (HLContainer with: (HLHorizontalSplitter
  54. with: (HLVerticalSplitter
  55. with: (HLVerticalSplitter
  56. with: self sendersListWidget
  57. with: self implementorsListWidget)
  58. with: (HLVerticalSplitter
  59. with: self classReferencesListWidget
  60. with: self regexpListWidget))
  61. with: self sourceCodeWidget)).
  62. self sendersListWidget focus
  63. ! !
  64. !HLReferences class methodsFor: 'accessing'!
  65. tabClass
  66. ^ 'references'
  67. !
  68. tabLabel
  69. ^ 'References'
  70. !
  71. tabPriority
  72. ^ 100
  73. ! !
  74. !HLReferences class methodsFor: 'testing'!
  75. canBeOpenAsTab
  76. ^ false
  77. ! !
  78. HLToolListWidget subclass: #HLReferencesListWidget
  79. slots: {}
  80. package: 'Helios-References'!
  81. !HLReferencesListWidget methodsFor: 'accessing'!
  82. commandCategory
  83. ^ 'Methods'
  84. !
  85. label
  86. ^ 'List'
  87. ! !
  88. !HLReferencesListWidget methodsFor: 'actions'!
  89. activateListItem: anItem
  90. self model withChangesDo: [ super activateListItem: anItem ]
  91. !
  92. observeModel
  93. self model announcer
  94. on: HLSearchReferences
  95. do: [ :ann | self onSearchReferences: ann searchString ];
  96. on: HLMethodSelected
  97. do: [ :ann | self onMethodSelected: ann item ]
  98. !
  99. reselectItem: aMethod
  100. self selectItem: aMethod
  101. !
  102. selectItem: aMethod
  103. super selectItem: aMethod.
  104. self model selectedClass: nil; selectedMethod: aMethod
  105. ! !
  106. !HLReferencesListWidget methodsFor: 'reactions'!
  107. onMethodSelected: aMethod
  108. aMethod ifNil: [ ^ self ].
  109. (self items includes: aMethod) ifFalse: [ ^ self ].
  110. self
  111. selectedItem: aMethod;
  112. activateItem: aMethod
  113. !
  114. onSearchReferences: aString
  115. self subclassResponsibility
  116. ! !
  117. !HLReferencesListWidget methodsFor: 'rendering'!
  118. renderItemLabel: aMethod on: html
  119. html with: aMethod asString
  120. ! !
  121. !HLReferencesListWidget class methodsFor: 'instance creation'!
  122. on: aModel
  123. ^ self new
  124. model: aModel;
  125. yourself
  126. ! !
  127. HLReferencesListWidget subclass: #HLClassReferencesListWidget
  128. slots: {}
  129. package: 'Helios-References'!
  130. !HLClassReferencesListWidget methodsFor: 'accessing'!
  131. label
  132. ^ 'Class references'
  133. ! !
  134. !HLClassReferencesListWidget methodsFor: 'reactions'!
  135. onSearchReferences: aString
  136. self selectItem: nil.
  137. self items: (self model classReferencesOf: aString).
  138. self refresh
  139. ! !
  140. HLReferencesListWidget subclass: #HLImplementorsListWidget
  141. slots: {}
  142. package: 'Helios-References'!
  143. !HLImplementorsListWidget methodsFor: 'accessing'!
  144. label
  145. ^ 'Implementors'
  146. ! !
  147. !HLImplementorsListWidget methodsFor: 'reactions'!
  148. onSearchReferences: aString
  149. self selectItem: nil.
  150. self items: (self model implementorsOf: aString).
  151. self refresh
  152. ! !
  153. HLReferencesListWidget subclass: #HLRegexpListWidget
  154. slots: {}
  155. package: 'Helios-References'!
  156. !HLRegexpListWidget methodsFor: 'accessing'!
  157. label
  158. ^ 'Source search'
  159. ! !
  160. !HLRegexpListWidget methodsFor: 'reactions'!
  161. onSearchReferences: aString
  162. self selectItem: nil.
  163. self items: (self model regexpReferencesOf: aString).
  164. self refresh
  165. ! !
  166. HLReferencesListWidget subclass: #HLSendersListWidget
  167. slots: {}
  168. package: 'Helios-References'!
  169. !HLSendersListWidget methodsFor: 'accessing'!
  170. label
  171. ^ 'Senders'
  172. ! !
  173. !HLSendersListWidget methodsFor: 'reactions'!
  174. onSearchReferences: aString
  175. self selectItem: nil.
  176. self items: (self model sendersOf: aString).
  177. self refresh
  178. ! !
  179. HLToolModel subclass: #HLReferencesModel
  180. slots: {#methodsCache. #classesAndMetaclassesCache}
  181. package: 'Helios-References'!
  182. !HLReferencesModel methodsFor: 'accessing'!
  183. allMethods
  184. ^ self methodsCache
  185. !
  186. classReferencesOf: aString
  187. "Answer all methods referencing the class named aString"
  188. ^self allMethods select: [ :each |
  189. (each referencedClasses includes: aString) ]
  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. sendersOf: aString
  203. ^ self allMethods select: [ :each |
  204. each messageSends includes: aString ]
  205. ! !
  206. !HLReferencesModel methodsFor: 'actions'!
  207. openClassNamed: aString
  208. | browser |
  209. self withChangesDo: [
  210. browser := HLBrowser openAsTab.
  211. browser openClassNamed: aString ]
  212. !
  213. openMethod
  214. | browser |
  215. self selectedMethod ifNil: [ ^ self ].
  216. self withChangesDo: [
  217. browser := HLBrowser openAsTab.
  218. browser openMethod: self selectedMethod ]
  219. !
  220. search: aString
  221. self updateCaches.
  222. self announcer announce: (HLSearchReferences new
  223. searchString: aString;
  224. yourself)
  225. ! !
  226. !HLReferencesModel methodsFor: 'cache'!
  227. classesAndMetaclassesCache
  228. classesAndMetaclassesCache ifNil: [ self updateClassesAndMetaclassesCache ].
  229. ^ classesAndMetaclassesCache
  230. !
  231. methodsCache
  232. methodsCache ifNil: [ self updateMethodsCache ].
  233. ^ methodsCache
  234. !
  235. updateCaches
  236. self
  237. updateClassesAndMetaclassesCache;
  238. updateMethodsCache
  239. !
  240. updateClassesAndMetaclassesCache
  241. classesAndMetaclassesCache := OrderedCollection new.
  242. self environment classes do: [ :eachClass | eachClass includingPossibleMetaDo: [ :each |
  243. classesAndMetaclassesCache add: each ] ]
  244. !
  245. updateMethodsCache
  246. methodsCache := OrderedCollection new.
  247. self classesAndMetaclasses
  248. do: [ :each | methodsCache addAll: each methods ]
  249. ! !
  250. !HLReferencesModel methodsFor: 'testing'!
  251. isReferencesModel
  252. ^ true
  253. ! !