Helios-References.st 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 := HLNavigationCodeWidget new ]
  38. ! !
  39. !HLReferences methodsFor: 'actions'!
  40. open
  41. HLManager current addTab: (HLTab on: self labelled: self class tabLabel)
  42. !
  43. search: aString
  44. self model search: aString
  45. ! !
  46. !HLReferences methodsFor: 'rendering'!
  47. renderContentOn: html
  48. html with: (HLContainer with: (HLHorizontalSplitter
  49. with: (HLVerticalSplitter
  50. with: (HLVerticalSplitter
  51. with: self sendersListWidget
  52. with: self implementorsListWidget)
  53. with: (HLVerticalSplitter
  54. with: self classReferencesListWidget
  55. with: self regexpListWidget))
  56. with: self sourceCodeWidget)).
  57. self sendersListWidget focus
  58. ! !
  59. !HLReferences class methodsFor: 'accessing'!
  60. tabLabel
  61. ^ 'References'
  62. !
  63. tabPriority
  64. ^ 100
  65. ! !
  66. !HLReferences class methodsFor: 'testing'!
  67. canBeOpenAsTab
  68. ^ false
  69. ! !
  70. HLNavigationListWidget subclass: #HLReferencesListWidget
  71. instanceVariableNames: 'model'
  72. package: 'Helios-References'!
  73. !HLReferencesListWidget methodsFor: 'accessing'!
  74. label
  75. ^ 'List'
  76. !
  77. model
  78. ^ model
  79. !
  80. model: aModel
  81. model := aModel.
  82. self observeModel
  83. ! !
  84. !HLReferencesListWidget methodsFor: 'actions'!
  85. observeModel
  86. self model announcer
  87. on: HLSearchReferences
  88. do: [ :ann | self onSearchReferences: ann searchString ]
  89. ! !
  90. !HLReferencesListWidget methodsFor: 'reactions'!
  91. onSearchReferences: aString
  92. self subclassResponsibility
  93. ! !
  94. !HLReferencesListWidget methodsFor: 'rendering'!
  95. renderContentOn: html
  96. self renderHeadOn: html.
  97. super renderContentOn: html
  98. !
  99. renderHeadOn: html
  100. html div
  101. class: 'list-label';
  102. with: [
  103. html with: self label ]
  104. !
  105. renderItemLabel: aMethod on: html
  106. html with: aMethod methodClass name, ' >> #', aMethod selector
  107. ! !
  108. !HLReferencesListWidget class methodsFor: 'instance creation'!
  109. on: aModel
  110. ^ self new
  111. model: aModel;
  112. yourself
  113. ! !
  114. HLReferencesListWidget subclass: #HLClassReferencesListWidget
  115. instanceVariableNames: ''
  116. package: 'Helios-References'!
  117. !HLClassReferencesListWidget methodsFor: 'accessing'!
  118. label
  119. ^ 'Class references'
  120. ! !
  121. !HLClassReferencesListWidget methodsFor: 'reactions'!
  122. onSearchReferences: aString
  123. self selectItem: nil.
  124. self items: (self model classReferencesOf: aString).
  125. self refresh
  126. ! !
  127. HLReferencesListWidget subclass: #HLImplementorsListWidget
  128. instanceVariableNames: ''
  129. package: 'Helios-References'!
  130. !HLImplementorsListWidget methodsFor: 'accessing'!
  131. label
  132. ^ 'Implementors'
  133. ! !
  134. !HLImplementorsListWidget methodsFor: 'reactions'!
  135. onSearchReferences: aString
  136. self selectItem: nil.
  137. self items: (self model implementorsOf: aString).
  138. self refresh
  139. ! !
  140. HLReferencesListWidget subclass: #HLRegexpListWidget
  141. instanceVariableNames: ''
  142. package: 'Helios-References'!
  143. !HLRegexpListWidget methodsFor: 'accessing'!
  144. label
  145. ^ 'Source search'
  146. ! !
  147. !HLRegexpListWidget methodsFor: 'reactions'!
  148. onSearchReferences: aString
  149. self selectItem: nil.
  150. self items: (self model regexpReferencesOf: aString).
  151. self refresh
  152. ! !
  153. HLReferencesListWidget subclass: #HLSendersListWidget
  154. instanceVariableNames: ''
  155. package: 'Helios-References'!
  156. !HLSendersListWidget methodsFor: 'accessing'!
  157. label
  158. ^ 'Senders'
  159. ! !
  160. !HLSendersListWidget methodsFor: 'reactions'!
  161. onSearchReferences: aString
  162. self selectItem: nil.
  163. self items: (self model sendersOf: aString).
  164. self refresh
  165. ! !
  166. HLModel subclass: #HLReferencesModel
  167. instanceVariableNames: 'methodsCache classesAndMetaclassesCache'
  168. package: 'Helios-References'!
  169. !HLReferencesModel methodsFor: 'accessing'!
  170. allMethods
  171. ^ self methodsCache
  172. !
  173. allSelectors
  174. ^ (self allMethods
  175. collect: [ :each | each selector ])
  176. asSet
  177. !
  178. classReferencesOf: aString
  179. "Answer all methods referencing the class named aString"
  180. | references |
  181. references := OrderedCollection new.
  182. self classesAndMetaclasses do: [ :each |
  183. each methodDictionary values do: [ :method |
  184. (method referencedClasses includes: aString) ifTrue: [
  185. references add: method ] ] ].
  186. ^ references
  187. !
  188. classesAndMetaclasses
  189. ^ self classesAndMetaclassesCache
  190. !
  191. implementorsOf: aString
  192. ^ self allMethods select: [ :each |
  193. each selector = aString ]
  194. !
  195. regexpReferencesOf: aString
  196. ^ self allMethods select: [ :each |
  197. each source match: aString ]
  198. !
  199. sendersOf: aString
  200. ^ self allMethods select: [ :each |
  201. each messageSends includes: aString ]
  202. ! !
  203. !HLReferencesModel methodsFor: 'actions'!
  204. search: aString
  205. self updateCaches.
  206. self announcer announce: (HLSearchReferences new
  207. searchString: aString;
  208. yourself)
  209. ! !
  210. !HLReferencesModel methodsFor: 'cache'!
  211. classesAndMetaclassesCache
  212. classesAndMetaclassesCache ifNil: [ self updateClassesAndMetaclassesCache ].
  213. ^ classesAndMetaclassesCache
  214. !
  215. methodsCache
  216. methodsCache ifNil: [ self updateMethodsCache ].
  217. ^ methodsCache
  218. !
  219. updateCaches
  220. self
  221. updateClassesAndMetaclassesCache;
  222. updateMethodsCache
  223. !
  224. updateClassesAndMetaclassesCache
  225. classesAndMetaclassesCache := self environment classes
  226. inject: OrderedCollection new
  227. into: [ :acc :each |
  228. acc
  229. add: each;
  230. add: each class;
  231. yourself ]
  232. !
  233. updateMethodsCache
  234. methodsCache := self classesAndMetaclasses
  235. inject: OrderedCollection new
  236. into: [ :acc :each |
  237. acc, each methods ]
  238. ! !