forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageList.class.st
319 lines (271 loc) · 8.85 KB
/
MessageList.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
"
I am a presenter listing messages.
I am used by more complexe browsers such as MessageBrowser or VersionBrowser.
Internal Representation and Key Implementation Points.
--------------------
Instance Variables
cachedHierarchy: <aDictionary> A cache keeping info about the level of a class in the list.
listModel: <aListPresenter> A list presenter to show all the messages.
model: <aTool> A model grouping generic methods for managing packages/classes/groups/methods from a browser
topologySort: <aBoolean> A boolean to know if we should use a topology sort or not.
"
Class {
#name : #MessageList,
#superclass : #SpPresenter,
#instVars : [
'listModel',
'cachedHierarchy',
'topologySort',
'model'
],
#category : #'Spec2-Tools-Senders'
}
{ #category : #specs }
MessageList class >> defaultSpec [
^ SpBoxLayout newVertical
add: #listModel;
yourself
]
{ #category : #actions }
MessageList >> browseClassRefs [
self currentMethod ifNotNil: [ :method |
model browseClassRefsOf: method methodClass ]
]
{ #category : #actions }
MessageList >> browseMessages [
self currentMethod ifNotNil: [ :method |
model browseMessagesFrom: method selector ]
]
{ #category : #actions }
MessageList >> browseMethod [
self currentMethod ifNotNil: [ :method | method browse ]
]
{ #category : #actions }
MessageList >> browseSendersOfMessage [
self currentMethod ifNotNil: [ :method |
model browseSendersOfMessagesFrom: method selector ]
]
{ #category : #actions }
MessageList >> browseVersions [
self currentMethod ifNotNil: [ :method |
model browseVersionsFrom: method compiledMethod ]
]
{ #category : #testing }
MessageList >> buildHierarchyForMessages: messages [
| result classes |
self topologicSort ifFalse: [
result := IdentityDictionary new.
messages do: [:m | result at: m put: {} ].
^ result ].
result := Dictionary new.
classes := (messages collect: [ :each | each methodClass ]) asSet.
messages do: [:message || level class |
class := message methodClass.
level := OrderedCollection new.
class allSuperclassesDo: [:superClass |
(classes includes: superClass)
ifTrue: [ level addFirst: superClass ]].
level addLast: class.
level addLast: message selector.
result at: message put: level ].
^ result
]
{ #category : #testing }
MessageList >> cacheHierarchyForClasses: aCollection [
cachedHierarchy := self buildHierarchyForMessages: aCollection.
]
{ #category : #api }
MessageList >> contextMenu: aMenuPresenter [
listModel contextMenu: aMenuPresenter
]
{ #category : #'private-focus' }
MessageList >> ensureKeyBindingsFor: aWidget [
aWidget bindKeyCombination: PharoShortcuts current browseShortcut toAction: [ self browseMethod ].
aWidget bindKeyCombination: PharoShortcuts current inspectItShortcut toAction: [ self inspectMethod ].
aWidget bindKeyCombination: PharoShortcuts current browseImplementorsShortcut toAction: [ self browseMessages ].
aWidget bindKeyCombination: PharoShortcuts current browseSendersShortcut toAction: [ self browseSendersOfMessage ].
aWidget bindKeyCombination: PharoShortcuts current browseReferencesShortcut toAction: [ self browseClassRefs ].
aWidget bindKeyCombination: PharoShortcuts current browseVersionsShortcut toAction: [ self browseVersions ].
aWidget bindKeyCombination: PharoShortcuts current removeShortcut toAction: [ self removeMethods ]
]
{ #category : #initialization }
MessageList >> initialize [
topologySort := true.
model := AbstractTool new.
super initialize
]
{ #category : #initialization }
MessageList >> initializePresenters [
listModel := self newTable.
listModel
sortingBlock: [ :a :b | self sortClassesInCachedHierarchy: a b: b ];
addColumn: (SpStringTableColumn title: 'Location' evaluated: [ :item | self locationOf: item ]);
addColumn: (SpStringTableColumn title: 'Selector' evaluated: [ :item | self selectorOf: item ]);
addColumn: (SpStringTableColumn title: 'Package' evaluated: [ :item | self packageOf: item ]);
beResizable.
self contextMenu: self messageListMenu
]
{ #category : #actions }
MessageList >> inspectMethod [
self currentMethod ifNotNil: [ :m | m inspect ]
]
{ #category : #accessing }
MessageList >> listModel [
^ listModel
]
{ #category : #accessing }
MessageList >> locationOf: anItem [
^ String
streamContents: [ :aStream |
3 to: (cachedHierarchy at: anItem) size do: [ :i | aStream << ' ' ].
aStream << (self methodClassNameForItem: anItem) << ' ('.
anItem isFromTrait
ifTrue: [ aStream
<< anItem compiledMethod origin name;
space ].
aStream << (self protocolNameForItem: anItem) << ')' ]
]
{ #category : #accessing }
MessageList >> messageListMenu [
^ self newMenu
addGroup: [ :aGroup |
aGroup
addItem: [ :anItem |
anItem
name: 'Browse full...';
shortcut: $b meta;
action: [ self selectedMethod browse ] ];
addItem: [ :anItem |
anItem
name: 'Inspect method...';
shortcut: $i meta;
action: [ self selectedMethod inspect ] ] ];
addGroup: [ :aGroup |
aGroup
addItem: [ :anItem |
anItem
name: 'Remove method...';
shortcut: $x meta;
action: [ self selectedMethod removeFromSystem ] ];
addItem: [ :anItem |
anItem
name: 'Senders of...';
shortcut: $n meta;
action: [ model browseSendersOfMessagesFrom: self selectedMethod selector ] ];
addItem: [ :anItem |
anItem
name: 'Implementors of...';
shortcut: $m meta;
action: [ model browseMessagesFrom: self selectedMethod selector ] ] ];
addItem: [ :anItem |
anItem
name: 'Users of...';
shortcut: $N meta;
action: [ model browseClassRefsOf: self selectedMethod methodClass ] ];
addItem:
[ :anItem |
anItem
name: 'Versions...';
shortcut: $v meta;
action: [ model browseVersionsFrom: self selectedMethod ] ] yourself
]
{ #category : #accessing }
MessageList >> messages [
^ listModel items
]
{ #category : #accessing }
MessageList >> messages: aCollection [
self cacheHierarchyForClasses: aCollection.
listModel items: cachedHierarchy keys asOrderedCollection.
listModel listSize > 0 ifTrue: [ listModel selectIndex: 1 ]
]
{ #category : #private }
MessageList >> methodClassNameForItem: anItem [
^ anItem methodClass ifNotNil: [ :class | class name ] ifNil: [ '' ]
]
{ #category : #accessing }
MessageList >> model [
^model
]
{ #category : #accessing }
MessageList >> numberOfElements [
^ listModel listSize
]
{ #category : #private }
MessageList >> packageNameForItem: anItem [
^ anItem package ifNil: [ '' ] ifNotNil: [ :package | package name ]
]
{ #category : #private }
MessageList >> packageOf: anItem [
^ '[' , (self packageNameForItem: anItem) , ']'
]
{ #category : #private }
MessageList >> protocolNameForItem: anItem [
^ anItem category ifNil: [ '' ]
]
{ #category : #actions }
MessageList >> removeMethods [
self currentMethod ifNotNil: [ :method |
model removeMethod: method inClass: method methodClass ]
]
{ #category : #selecting }
MessageList >> selectIndex: anInteger [
listModel selectIndex: anInteger
]
{ #category : #accessing }
MessageList >> selectMessage: aMessage [
listModel selectItem: aMessage
]
{ #category : #selecting }
MessageList >> selectedIndex [
^ listModel selection selectedIndex
]
{ #category : #accessing }
MessageList >> selectedMessage [
^ listModel selection selectedItem
]
{ #category : #accessing }
MessageList >> selectedMethod [
self selectedMessage ifNil: [ ^ nil ].
^ self selectedMessage compiledMethod
]
{ #category : #accessing }
MessageList >> selectorOf: anItem [
^ anItem selector
]
{ #category : #sorting }
MessageList >> sortClassesInCachedHierarchy: aMethodDefinition b: otherMethodDefinition [
"This method checks wether the cached inheritance hierarchy of a method should be before than the one of another method.
It compares alphabetically the hierarchy using #compare:
If both are alphabetically equals, it uses the size the hierarchy.
We do not know why this is done like this."
| aMethodHierarchy otherMethodHierarchy minSize|
aMethodHierarchy := cachedHierarchy at: aMethodDefinition.
otherMethodHierarchy := cachedHierarchy at: otherMethodDefinition.
minSize := aMethodHierarchy size min: otherMethodHierarchy size.
1 to: minSize do: [ :i | |compare|
compare := (aMethodHierarchy at: i) printString compare: (otherMethodHierarchy at: i) printString.
compare ~~ 2
ifTrue: [ ^ compare == 1 ]].
^ aMethodHierarchy size < otherMethodHierarchy size
]
{ #category : #api }
MessageList >> sortingBlock: aBlock [
listModel sortingBlock: aBlock
]
{ #category : #accessing }
MessageList >> topologicSort [
^ topologySort
]
{ #category : #accessing }
MessageList >> topologicSort: anObject [
topologySort := anObject
]
{ #category : #enumerating }
MessageList >> whenModelChangedDo: aBlock [
listModel whenModelChangedDo: aBlock
]
{ #category : #enumerating }
MessageList >> whenSelectionChangedDo: aBlock [
listModel whenSelectionChangedDo: aBlock
]