timm@runxtsa.runx.oz.au (Tim Menzies) (07/07/90)
Someone was recently complementing the Objective-C class broswer because it could report where in a hierarchy a method was defined. Someone then replied that Smalltalk/V did this already. My understanding was that it did not. Rather, it told you where variables where defined. The I thought, why not write such a tool in Smalltalk/V? The following code took twenty minutes to write and debug. Note that most of the code is dealing with a generic wondow dispay function. The actual work of looking up the methods in a superclass is handled in the first method. This may not be **exactly** what the poster wants, but what the hell? Five more minutes work and it can be modified to fit. I think this demonstrates one of the virtues of the Smalltalk environment. If it don't have feature X, you can easliy add it. Tim Menzies timm@runxtsa.runx.oz.au ----- cut here ------------------------------------------------------- !Behavior methods ! allVerbs "Write all the methods of a class to a window. Repeat the process for every superclass, excluding Object. Demo: String allVerbs" |offset classes| offset := ' '. TextEditor log: 'All methods of ',self name width: 3 height: 1 code: [:out| classes := self allSuperclasses. classes addFirst: self. classes remove: Object. classes do: [:c | out cr; cr; show: c name,' instance methods:'. c selectors asSortedCollection do: [:v| out cr show: offset, v printString]. out cr; cr; show: c name ,' class methods:'. self class selectors asSortedCollection do: [:v| out cr show: offset,v printString]]]! ! !TextEditor class methods ! log: aString code: code "Pop-up a window and display the output of code in that window." "TextEditor log: 'demo' code: [:stream| stream show: 'hello'; cr; show: 'world']" self log: aString width: 3 height: 2 code: code! log: aString width: x height: y code: code "Pop-up a window that is one-xth the width of the screen and one-yth the height of the screen and display the output of code in that window. If x = y = 1, then the whole screen is used." "TextEditor log: 'demo' width: 1 height: 4 code: [:stream| stream show: 'hello'; cr; show: 'world'] " | logger extent | extent := ((Display width // x max: aString size * LabelFont width + 6) min: Display width) @ (Display height // y). logger := self windowLabeled: aString frame: (Display extent - extent extent: extent). CursorManager execute change. code value: logger. CursorManager normal change. logger topDispatcher scheduleWindow! ! "SAMPLE OUTPUT: String instance methods: < <= = > >= asArrayOfSubstrings asAsciiZ asDate asInteger asLowerCase asStream asString asSymbol asUpperCase at: at:put: basicAt: basicAt:put: checkCharacter: displayAt: displayAt:font: dumpOn:for: edit equals: fileExtension fileName hash magnifyBy: outputToPrinter primitiveForPrinterOutput printOn: replaceFrom:to:with:startingAt: replaceFrom:to:withObject: size storeOn: stringHash trim: trimBlanks withCrs String class methods: FixedSizeCollection instance methods: add: collect: copyReplaceFrom:to:with: remove:ifAbsent: select: size storeOn: FixedSizeCollection class methods: IndexedCollection instance methods: , = accessEmptyCollection atAll:put: atAllPut: checkIndex: copy copyFrom:to: copyReplaceFrom:to:with: copyWith: copyWithout: do: errorInBounds: findFirst: findLast: first grow growSize hash includes: indexOf: indexOf:ifAbsent: last replaceFrom:to:with: replaceFrom:to:with:startingAt: replaceFrom:to:withObject: reversed reverseDo: size with:do: IndexedCollection class methods: Collection instance methods: add: addAll: asArray asBag asOrderedCollection asSet asSortedCollection asSortedCollection: collect: detect: detect:ifNone: do: errorAbsentObject errorNotIndexable includes: inject:into: isEmpty notEmpty occurrencesOf: printLimit printOn: reject: remove: remove:ifAbsent: removeAll: select: species storeOn: Collection class methods: "