added #methodProtocolCompletion:
authorClaus Gittinger <cg@exept.de>
Tue, 08 Aug 2000 14:48:31 +0200
changeset 5505 e99e8e9cbfef
parent 5504 246339246452
child 5506 ffa0d32f4a51
added #methodProtocolCompletion:
Smalltalk.st
--- a/Smalltalk.st	Tue Aug 08 11:43:19 2000 +0200
+++ b/Smalltalk.st	Tue Aug 08 14:48:31 2000 +0200
@@ -1865,6 +1865,59 @@
     "Created: 11.10.1996 / 18:10:43 / cg"
 !
 
+methodProtocolCompletion:aPartialProtocolName
+    "given a partial method protocol name, return an array consisting of
+     2 entries: 1st: collection consisting of matching protocols
+                2nd: the longest match"
+
+    |matches best lcName|
+
+    matches := IdentitySet new.
+
+    "/ search for exact match
+    self allClassesDo:[:aClass |
+        aClass allSelectorsAndMethodsDo:[:aSelector :aMethod |
+            |protocol|
+
+            protocol := aMethod category.
+            (protocol startsWith:aPartialProtocolName) ifTrue:[
+                matches add:protocol
+            ]
+        ].
+    ].
+    matches isEmpty ifTrue:[
+        "/ search for case-ignoring match
+        lcName := aPartialProtocolName asLowercase.
+        self allClassesDo:[:aClass |
+            aClass allSelectorsAndMethodsDo:[:aSelector :aMethod |
+                |protocol|
+
+                protocol := aMethod category.
+                (protocol asLowercase startsWith:lcName) ifTrue:[
+                    matches add:protocol
+                ]
+            ].
+        ].
+    ].
+
+    matches isEmpty ifTrue:[
+        ^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
+    ].
+    matches size == 1 ifTrue:[
+        ^ Array with:matches first with:(matches asArray)
+    ].
+    matches := matches asSortedCollection.
+    best := matches longestCommonPrefix.
+    ^ Array with:best with:matches asArray
+
+    "
+     Smalltalk methodProtocolCompletion:'doc'
+     Smalltalk methodProtocolCompletion:'docu' 
+     Smalltalk methodProtocolCompletion:'documenta' 
+    "
+
+!
+
 numberOfGlobals
     "return the number of global variables in the system"
 
@@ -5664,5 +5717,5 @@
 !Smalltalk class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.459 2000-08-08 09:43:19 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.460 2000-08-08 12:48:31 cg Exp $'
 ! !