[comp.lang.smalltalk] st80 goodie

luebben@tubsibr.uucp (Edwin Luebben) (10/03/90)

Most of you out there will know the problem to find a method in Smalltalk80
when you don't know the name of the method and/or the name of the class. So 
here is a little tool to find the method when you have an idea how the name 
could be. FileIn the following code and SystemDictionary will offer the method

			fuzzyBrowse:

So, if you execute e.g. the statement:

	Smalltalk fuzzyBrowse: #all:pull:

the System will open a MethodBrowser with all methods that are written more 
or less like all:pull:.

The algorithm is based on the spellAgainst: method used in the System for
correcting misspelled code. If you alter the threshold for spellAgains (I
took 50), you can adjust how much matching methods you will get.

I installed the fuzzyBrowse: in the system-menu but I think, it will be as 
usefull in the browser-menu or in the SystemWorkspace.

					Have much fun trying it,
						Eddie

Edwin Luebben 
Technische Universitaet Braunscheig
Institut fuer Betriebssysteme und Rechnerverbund
Germany



cut here ---------------------------------------------------------------

'From Objectworks for Smalltalk-80(tm), Version 2.5 of 29 July 1989 on 19 March 1990 at 3:24:56 pm'!



!SystemDictionary methodsFor: 'retrieving'!

fuzzyAllImplementorsOf: aSelector  
	"Answer a SortedCollection of all the methods that implement the message aSelector.
		created by Edwin Luebben Date: 19 March 1990 Time: 3:24:47 pm."

	| aCollection |
	aCollection _ SortedCollection new.
	Cursor execute showWhile:
		[self allBehaviorsDo:
			[:class |
			class selectors do: 
				[ :selector |
					(aSelector spellAgainst: selector) > 50 ifTrue: 
	"50 is the number to alter if you want a sharper or less sharp search"
						[
							aCollection add: class name, ' ', selector
						]
				]
			]
		 ].
^aCollection! 

!'From Objectworks for Smalltalk-80(tm), Version 2.5 of 29 July 1989 on 19 March 1990 at 3:11:12 pm'!



!SystemDictionary methodsFor: 'browsing'!

fuzzyBrowse: selector
	"Create and schedule a message browser on each method that implements the
	message whose selector is the argument, selector.
	For example,
		Smalltalk fuzzyBrowse: #all:pull:.	
	created by Edwin Luebben Date: 19 March 1990 Time: 3:11:00 pm."

	BrowserView
		openListBrowserOn: (self fuzzyAllImplementorsOf: selector)
		label: 'fuzzy of ' , selector!