[ENH] Method Finder with matching classes marked

Doug Way dway at mat.net
Thu Apr 27 00:18:11 UTC 2000


On Tue, 18 Apr 2000, Michael_Chean wrote:

> > Perhaps the original poster _did_ try "reverse<Cmd-Shift-W>" and was
> > confused by the fact that "FlippyArray2" does contain a 'reverse' method,
> > as do quite a number of classes, sometimes meaning "reverse order" and
> > sometimes meaning "opposite colour".
> 
> Yep, actually this is what happened.  It was more confusing in that I
> was looking for something to do with the class String - so from my
> beginners point of view the reversed in OrderedCollection wasn't an
> immediate match. Thank goodness that the OrederedCollection actually
> had an example of reversed which clued me into the similiarity.  
> Otherwise the Newbie must try to decipher from the description or code
> what is going on.

Here is an enhancement to the Method Finder which will hopefully help to
narrow down the appropriate class in these situations.  (I realize that
you were not using Method Finder here, but if you were, this might have
helped.)

This is an enhancement to the "example mode" of the Method Finder.  When
an example is given, and one of the found methods is selected from the
list, the classes in the class list which match the class (or are a
superclass) of the receiver will be specially marked with an asterisk.

For example, if the example   'abcd'. 'dcba'   is given in the top pane,
the method 'reversed' will appear in the method list.  When 'reversed' is
selected, eight classes will appear in the class list, but now
SequenceableCollection>>reversed will be asterisked, since that is the
class/method that is actually being used in this example. (because String
is a subclass of SequenceableCollection)  Generally, the asterisked class
is really the one we're looking for... the other seven classes are
basically irrelevant to the example, although it's useful to at least
leave them in the list.

The asterisk appears before the class/method name, so the asterisked
classes end up being moved to the top of the list, since they're sorted
alphabetically.  I think this is handy, anyway.  (My original plan was to
make the matching classes appear in bold instead of using an asterisk, but
that looked like it would be a lot harder to implement.)

Here are some other fun examples to try when testing this enhancement:

'abc'. 'ab'. true
'abcd'. $c. 3
1. 2. true
#(10 20 30 40). 20. 50. #(10 50 30 40)
#(1 2 3) asOrderedCollection. 4. 4
Date. Date today

Of course, no classes will be asterisked if you use the "selector
fragment" mode.  I didn't try to implement it for the "multi-example" mode
which appears in MethodFinder>>methodFor:, either.

Also, I suppose it might be best to only asterisk the "nearest" superclass
and not all superclasses, so that only one class would ever be asterisked.  
But that looked a little bit hairy to implement, so I kept it simple for
now.

The attached changeset just makes a couple of changes to
SelectorBrowser... mainly, SelectorBrowser>>markMatchingClasses was added,
plus selectedClass was tweaked to handle parsing the extra asterisk.

(I guess I just missed the last batch of updates for 2.8, if this
enhancement is deemed worthy of inclusion... keep it in mind the next time
around. :-) )

Regarding the Method Finder, it is true that not very many newbies think
to try the Method Finder... it definitely needs to appear in more Squeak
tutorials.  (Naturally, it isn't going to be in the old Smalltalk books,
since it's a new thing.)  Also, I think the explanatory text in the lower
pane could be improved... the part about the example mode should give a
couple of typical scenarios, like a mini-tutorial... I remember I missed
the point the first time I read through it.  Maybe I'll submit something.

- Doug Way
  EAI/Transom Technologies, Ann Arbor, MI
  http://www.transom.com
  dway at mat.net, @eai.com
-------------- next part --------------
'From Squeak2.8alpha of 13 January 2000 [latest update: #1974] on 25 April 2000 at 6:58:44 pm'!
"Change Set:		MarkedMethodFinder-dew
Date:			19 April 2000
Author:			Doug Way

An enhancement to the SelectorBrowser (method finder).  When entering an example (e.g. '3. 4. 7'), and then clicking on a method in the list, classes in the class list will be marked with an asterisk if they are a class/superclass of the example instance.  (These asterisked classes are really the only ones relevant to the example.)"!


!SelectorBrowser methodsFor: 'as yet unclassified' stamp: 'dew 4/25/2000 18:36'!
messageListIndex: anInteger 
	"Set the selected message selector to be the one indexed by anInteger.  Find all classes it is in."

	selectorIndex _ anInteger.
	selectorIndex = 0 ifTrue: [^ self].

	classList _ Smalltalk allImplementorsOf: self selectedMessageName.
	self markMatchingClasses.
	classListIndex _ 0.
	self changed: #messageListIndex.		"update my selection"
	self changed: #classList.! !

!SelectorBrowser methodsFor: 'as yet unclassified' stamp: 'dew 4/19/2000 18:51'!
selectedClass
	"Answer the currently selected class."

	| pairString |
	classListIndex = 0 ifTrue: [^nil].
	pairString _ classList at: classListIndex.
	(pairString includes: $*) ifTrue: [pairString _ pairString allButFirst].
	MessageSet parse: pairString
		toClassAndSelector: [:cls :sel | ^ cls].! !




More information about the Squeak-dev mailing list