33
|
1 |
"{ NameSpace: NewInspector }"
|
|
2 |
|
|
3 |
Object subclass:#InspectorList
|
|
4 |
instanceVariableNames:'inspectedObject instanceNames instanceTypes selection'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Inspector'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!InspectorList class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
for:anObject
|
|
14 |
"create a new list for an instance
|
|
15 |
"
|
38
|
16 |
^ self new inspect:anObject
|
|
17 |
|
|
18 |
|
|
19 |
!
|
|
20 |
|
|
21 |
new
|
|
22 |
"create a new instance and set the inspected object to nil
|
|
23 |
"
|
|
24 |
^ self basicNew initialize.
|
|
25 |
|
|
26 |
! !
|
|
27 |
|
|
28 |
!InspectorList class methodsFor:'helpers'!
|
|
29 |
|
|
30 |
asString:aCollection
|
|
31 |
"converts any collection to a string seperated by spaces. If
|
|
32 |
the collection is empty or nil, nil is returned otherwise a
|
|
33 |
string.
|
|
34 |
"
|
|
35 |
|string|
|
|
36 |
|
|
37 |
aCollection isCollection ifTrue:[
|
|
38 |
aCollection isString ifTrue:[
|
|
39 |
string := aCollection
|
|
40 |
] ifFalse:[
|
|
41 |
string := aCollection asStringWith:Character space
|
|
42 |
from:1 to:(aCollection size)
|
|
43 |
compressTabs:true
|
|
44 |
final:nil
|
|
45 |
].
|
|
46 |
string := string withoutSeparators.
|
|
47 |
|
|
48 |
string notEmpty ifTrue:[
|
|
49 |
^ string
|
|
50 |
]
|
|
51 |
].
|
|
52 |
^ nil
|
33
|
53 |
|
|
54 |
|
|
55 |
! !
|
|
56 |
|
|
57 |
!InspectorList class methodsFor:'testing'!
|
|
58 |
|
|
59 |
isDirectory:anInstance
|
38
|
60 |
"returns true if the instance is a directory
|
33
|
61 |
"
|
|
62 |
|cls|
|
|
63 |
|
|
64 |
anInstance notNil ifTrue:[
|
|
65 |
cls := anInstance class.
|
|
66 |
|
|
67 |
cls == Character ifTrue:[ ^ false ].
|
|
68 |
cls == Symbol ifTrue:[ ^ false ].
|
|
69 |
cls == String ifTrue:[ ^ false ].
|
|
70 |
|
|
71 |
cls allInstVarNames notEmpty ifTrue:[
|
|
72 |
^ true
|
|
73 |
].
|
|
74 |
|
|
75 |
anInstance isVariable ifTrue:[
|
|
76 |
^ true
|
|
77 |
].
|
|
78 |
].
|
|
79 |
^ false
|
|
80 |
|
|
81 |
|
38
|
82 |
!
|
|
83 |
|
|
84 |
isTraceable:anInstance
|
|
85 |
"returns true if the instance could be traced or traped
|
|
86 |
"
|
|
87 |
|cls|
|
|
88 |
|
|
89 |
anInstance notNil ifTrue:[
|
|
90 |
cls := anInstance class.
|
|
91 |
|
|
92 |
^ ( cls ~~ True
|
|
93 |
and:[cls ~~ False
|
|
94 |
and:[cls ~~ SmallInteger]]
|
|
95 |
)
|
|
96 |
].
|
|
97 |
^ false.
|
|
98 |
|
33
|
99 |
! !
|
|
100 |
|
|
101 |
!InspectorList methodsFor:'accessing'!
|
|
102 |
|
|
103 |
includesSelf:aBoolean
|
|
104 |
"includes 'self' dependant on the boolean
|
|
105 |
"
|
|
106 |
(self includesSelf) ~~ aBoolean ifTrue:[
|
|
107 |
aBoolean ifTrue:[
|
|
108 |
instanceNames addFirst:'self'.
|
|
109 |
instanceTypes addFirst:#self.
|
|
110 |
|
38
|
111 |
selection notNil ifTrue:[selection := selection + 1]
|
|
112 |
ifFalse:[selection := 1]
|
|
113 |
|
33
|
114 |
] ifFalse:[
|
|
115 |
instanceNames removeFirst.
|
|
116 |
instanceTypes removeFirst.
|
|
117 |
|
|
118 |
selection isNil ifFalse:[
|
|
119 |
(selection := selection - 1) == 0 ifTrue:[
|
|
120 |
selection := nil
|
|
121 |
]
|
|
122 |
]
|
|
123 |
]
|
|
124 |
]
|
|
125 |
|
|
126 |
|
|
127 |
!
|
|
128 |
|
38
|
129 |
list
|
|
130 |
"returns self
|
|
131 |
"
|
|
132 |
^ self
|
|
133 |
!
|
|
134 |
|
33
|
135 |
size
|
38
|
136 |
"returns size of list
|
33
|
137 |
"
|
|
138 |
^ instanceNames size
|
|
139 |
|
38
|
140 |
!
|
|
141 |
|
|
142 |
update
|
|
143 |
"update list contents
|
|
144 |
"
|
|
145 |
|start stop size|
|
|
146 |
|
|
147 |
inspectedObject isVariable ifTrue:[
|
|
148 |
start := instanceNames findFirst:[:el|(el at:1) isDigit].
|
|
149 |
stop := instanceTypes size.
|
|
150 |
|
|
151 |
start == 0 ifTrue:[
|
|
152 |
size := stop + 10. "must be > 1: force a resize the first time"
|
|
153 |
] ifFalse:[
|
|
154 |
instanceTypes last ~~ #grow ifTrue:[size := stop]
|
|
155 |
ifFalse:[size := stop-1].
|
|
156 |
|
|
157 |
instanceTypes removeFromIndex:start toIndex:stop.
|
|
158 |
instanceNames removeFromIndex:start toIndex:stop.
|
|
159 |
].
|
|
160 |
self resizeTo:size.
|
|
161 |
]
|
33
|
162 |
! !
|
|
163 |
|
|
164 |
!InspectorList methodsFor:'accessing contents'!
|
|
165 |
|
|
166 |
inspectedObject
|
|
167 |
"returns current inspected object
|
|
168 |
"
|
|
169 |
^ inspectedObject
|
|
170 |
|
|
171 |
|
|
172 |
!
|
|
173 |
|
|
174 |
instanceNames
|
|
175 |
"returns list of instance names
|
|
176 |
"
|
|
177 |
^ instanceNames
|
|
178 |
|
|
179 |
|
|
180 |
!
|
|
181 |
|
|
182 |
instanceTypeAt:anIndex
|
38
|
183 |
"returns type assigned to the list entry (#directory #normal #self #grow)
|
|
184 |
In case of an invalid index nil is returned.
|
33
|
185 |
"
|
38
|
186 |
(anIndex isNil or:[anIndex > instanceTypes size]) ifFalse:[^ instanceTypes at:anIndex]
|
|
187 |
ifTrue:[^ nil].
|
33
|
188 |
|
|
189 |
|
|
190 |
!
|
|
191 |
|
|
192 |
instanceTypes
|
38
|
193 |
"returns list of types (#directory #normal #self #grow)
|
33
|
194 |
"
|
|
195 |
^ instanceTypes
|
|
196 |
|
|
197 |
|
|
198 |
!
|
|
199 |
|
|
200 |
instanceVarAt:anIndex
|
38
|
201 |
"returns the instnace variable assigned to the index or
|
|
202 |
nil in case of an invalid index.
|
33
|
203 |
"
|
|
204 |
|idx nm|
|
|
205 |
|
38
|
206 |
(anIndex isNil or:[anIndex > instanceTypes size]) ifFalse:[
|
33
|
207 |
nm := instanceNames at:anIndex.
|
|
208 |
|
|
209 |
(nm at:1) isDigit ifFalse:[
|
|
210 |
self includesSelf ifFalse:[
|
|
211 |
^ inspectedObject instVarAt:anIndex
|
|
212 |
].
|
|
213 |
anIndex == 1 ifFalse:[^ inspectedObject instVarAt:(anIndex-1)]
|
|
214 |
ifTrue:[^ inspectedObject]
|
|
215 |
].
|
|
216 |
^ inspectedObject basicAt:(Number readFrom:nm onError:0)
|
|
217 |
].
|
|
218 |
^ nil
|
|
219 |
|
|
220 |
|
|
221 |
! !
|
|
222 |
|
|
223 |
!InspectorList methodsFor:'initialization'!
|
|
224 |
|
38
|
225 |
initialize
|
|
226 |
"initialize instance attributes
|
33
|
227 |
"
|
38
|
228 |
super initialize.
|
33
|
229 |
|
38
|
230 |
instanceNames := OrderedCollection new.
|
|
231 |
instanceTypes := OrderedCollection new.
|
|
232 |
|
33
|
233 |
! !
|
|
234 |
|
|
235 |
!InspectorList methodsFor:'private'!
|
|
236 |
|
38
|
237 |
resizeTo:aNumber
|
|
238 |
"resize list to minimum aNumber
|
33
|
239 |
"
|
38
|
240 |
|lstVarId basicSize newLastId obj instSize|
|
33
|
241 |
|
|
242 |
(inspectedObject isVariable and:[self class isDirectory:inspectedObject]) ifFalse:[
|
|
243 |
^ self
|
|
244 |
].
|
|
245 |
|
38
|
246 |
instanceTypes size == 0 ifTrue:[
|
|
247 |
lstVarId := 0
|
|
248 |
] ifFalse:[
|
|
249 |
instSize := inspectedObject class instSize.
|
33
|
250 |
|
38
|
251 |
instanceTypes first == #self ifTrue:[
|
|
252 |
instSize := instSize + 1
|
|
253 |
].
|
33
|
254 |
instanceTypes last == #grow ifTrue:[
|
|
255 |
instanceNames removeLast. " .. "
|
|
256 |
instanceTypes removeLast. " #grow "
|
38
|
257 |
].
|
|
258 |
lstVarId := instanceTypes size - instSize.
|
|
259 |
].
|
|
260 |
|
|
261 |
(basicSize := inspectedObject basicSize) == lstVarId ifTrue:[
|
|
262 |
^ self
|
|
263 |
].
|
|
264 |
newLastId := (1 bitShift:((aNumber-1) highBit)) max:128.
|
|
265 |
|
|
266 |
(newLastId + 64) > basicSize ifTrue:[
|
|
267 |
newLastId := basicSize
|
33
|
268 |
].
|
|
269 |
|
|
270 |
[lstVarId ~~ newLastId] whileTrue:[
|
|
271 |
lstVarId := lstVarId + 1.
|
|
272 |
obj := inspectedObject basicAt:lstVarId.
|
|
273 |
|
|
274 |
(self class isDirectory:obj) ifTrue:[instanceTypes add:#directory]
|
|
275 |
ifFalse:[instanceTypes add:#normal].
|
|
276 |
|
|
277 |
instanceNames add:(lstVarId printString, ' ', obj class name printString).
|
|
278 |
].
|
|
279 |
|
|
280 |
lstVarId ~~ basicSize ifTrue:[
|
|
281 |
instanceNames add:'..'.
|
|
282 |
instanceTypes add:#grow
|
|
283 |
].
|
|
284 |
! !
|
|
285 |
|
|
286 |
!InspectorList methodsFor:'selections'!
|
|
287 |
|
|
288 |
selectedInstanceType
|
38
|
289 |
"returns type assigned to the selected list entry (#directory #normal #self #grow).
|
|
290 |
In case of no selection nil is returned.
|
33
|
291 |
"
|
|
292 |
^ self instanceTypeAt:selection
|
|
293 |
|
|
294 |
|
|
295 |
!
|
|
296 |
|
|
297 |
selectedInstanceVar
|
|
298 |
"returns current inspected instance variable or nil
|
|
299 |
"
|
|
300 |
^ self instanceVarAt:selection
|
|
301 |
|
|
302 |
|
|
303 |
!
|
|
304 |
|
|
305 |
selection
|
|
306 |
"returns current selection number or nil
|
|
307 |
"
|
|
308 |
^ selection
|
|
309 |
|
|
310 |
|
|
311 |
!
|
|
312 |
|
38
|
313 |
setSelection:aNrOrNil
|
|
314 |
"change current selection to a number or nil; may resize the lists
|
|
315 |
"
|
|
316 |
selection := aNrOrNil.
|
|
317 |
|
|
318 |
(selection isNil or:[instanceTypes size > selection]) ifFalse:[
|
|
319 |
self resizeTo:selection.
|
|
320 |
|
|
321 |
selection > instanceTypes size ifTrue:[
|
|
322 |
selection := nil
|
|
323 |
]
|
|
324 |
]
|
|
325 |
! !
|
|
326 |
|
|
327 |
!InspectorList methodsFor:'testing'!
|
|
328 |
|
|
329 |
includesSelf
|
|
330 |
"returns true if 'self' is included in the list
|
|
331 |
"
|
|
332 |
^ (instanceTypes notEmpty and:[instanceTypes first == #self])
|
|
333 |
|
|
334 |
|
|
335 |
!
|
|
336 |
|
|
337 |
isEmpty
|
|
338 |
"returns true if the list is empty
|
33
|
339 |
"
|
38
|
340 |
^ instanceNames isEmpty
|
|
341 |
|
|
342 |
!
|
|
343 |
|
|
344 |
notEmpty
|
|
345 |
"returns true if the list is not empty
|
|
346 |
"
|
|
347 |
^ instanceNames notEmpty
|
|
348 |
|
|
349 |
! !
|
|
350 |
|
|
351 |
!InspectorList methodsFor:'user interaction'!
|
|
352 |
|
|
353 |
accept:aText notifying:aView
|
|
354 |
"evaluating aText on the selected instance var; if an error occurs #Error
|
|
355 |
is returned otherwise the inspected object instance. On success the list
|
|
356 |
will be updated.
|
|
357 |
"
|
|
358 |
|text slNr value|
|
|
359 |
|
|
360 |
selection notNil ifTrue:[
|
|
361 |
text := self class asString:aText.
|
|
362 |
|
|
363 |
text notNil ifTrue:[
|
|
364 |
self includesSelf ifFalse:[slNr := selection]
|
|
365 |
ifTrue:[slNr := selection-1].
|
|
366 |
|
|
367 |
value := inspectedObject class evaluatorClass
|
|
368 |
evaluate:text
|
|
369 |
receiver:inspectedObject
|
|
370 |
notifying:aView.
|
33
|
371 |
|
38
|
372 |
slNr ~~ 0 ifTrue:[
|
|
373 |
(inspectedObject class isVariable) ifFalse:[
|
|
374 |
inspectedObject instVarAt:slNr put:value
|
|
375 |
] ifTrue:[
|
|
376 |
slNr <= (inspectedObject class instSize) ifTrue:[
|
|
377 |
inspectedObject instVarAt:slNr put:value
|
|
378 |
] ifFalse:[
|
|
379 |
slNr := slNr - inspectedObject class instSize.
|
|
380 |
inspectedObject basicAt:slNr put:value
|
|
381 |
]
|
|
382 |
]
|
|
383 |
].
|
|
384 |
inspectedObject changed.
|
|
385 |
self update.
|
|
386 |
^ inspectedObject
|
|
387 |
]
|
|
388 |
].
|
|
389 |
^ #Error
|
|
390 |
!
|
|
391 |
|
|
392 |
doIt:aCode notifying:aView
|
|
393 |
"evaluating aCode on the selected instance var; if an error occurs #Error
|
|
394 |
is returned otherwise the result returned from the evaluator. On success
|
|
395 |
the list will be updated.
|
|
396 |
"
|
|
397 |
|successFg result evaluator selInstVar code|
|
|
398 |
|
|
399 |
selInstVar := self selectedInstanceVar.
|
|
400 |
|
|
401 |
selInstVar notNil ifTrue:[
|
|
402 |
code := self class asString:aCode.
|
|
403 |
|
|
404 |
code notNil ifTrue:[
|
|
405 |
evaluator := selInstVar class evaluatorClass.
|
|
406 |
successFg := true.
|
33
|
407 |
|
38
|
408 |
evaluator notNil ifTrue:[
|
|
409 |
result := evaluator evaluate:code
|
|
410 |
in:nil
|
|
411 |
receiver:selInstVar
|
|
412 |
notifying:aView
|
|
413 |
logged:true
|
|
414 |
ifFail:[successFg := false].
|
|
415 |
|
|
416 |
successFg ifTrue:[
|
|
417 |
self update.
|
|
418 |
^ result
|
|
419 |
]
|
33
|
420 |
]
|
38
|
421 |
]
|
|
422 |
].
|
|
423 |
^ #Error.
|
|
424 |
|
|
425 |
|
|
426 |
!
|
|
427 |
|
|
428 |
inspect:anObject
|
|
429 |
"inspect a new instance; update contents
|
|
430 |
"
|
|
431 |
|varNamesSize|
|
|
432 |
|
|
433 |
selection := nil.
|
|
434 |
|
|
435 |
anObject == inspectedObject ifFalse:[
|
|
436 |
inspectedObject := anObject.
|
33
|
437 |
|
38
|
438 |
(self class isDirectory:inspectedObject) ifFalse:[
|
|
439 |
instanceNames := OrderedCollection new.
|
|
440 |
instanceTypes := OrderedCollection new.
|
|
441 |
] ifTrue:[
|
|
442 |
instanceNames := inspectedObject class allInstVarNames.
|
|
443 |
varNamesSize := instanceNames size.
|
|
444 |
instanceTypes := OrderedCollection new:varNamesSize.
|
|
445 |
|
|
446 |
1 to:varNamesSize do:[:i|
|
|
447 |
(self class isDirectory:(inspectedObject instVarAt:i)) ifTrue:[
|
|
448 |
instanceTypes add:#directory
|
|
449 |
] ifFalse:[
|
|
450 |
instanceTypes add:#normal
|
|
451 |
]
|
|
452 |
].
|
|
453 |
]
|
|
454 |
].
|
|
455 |
self update
|
33
|
456 |
! !
|
|
457 |
|
|
458 |
!InspectorList class methodsFor:'documentation'!
|
|
459 |
|
|
460 |
version
|
|
461 |
^ '$Header$'
|
|
462 |
! !
|