#classNamed: now loads autoloaded classes if a (possibly) private class of an
autoloaded class is referenced.
--- a/Smalltalk.st Thu Jun 15 11:52:45 2006 +0200
+++ b/Smalltalk.st Thu Jun 15 11:53:03 2006 +0200
@@ -2147,50 +2147,65 @@
classNamed:aString
"return the class with name aString, or nil if absent.
To get to the metaClass, append ' class' to the string.
- To get a nameSpace or private class, prefix the name as required."
-
- |cls sym nonMeta idx ns nm|
-
- "be careful, to not invent new symbols ..."
+ To get a nameSpace or private class, prefix the name as required.
+ If a private class of an autoloaded class is referenced, the owning class
+ will be loaded."
+
+ |cls sym nonMeta idx prefix rest namespace|
+
+ "Quick try - if everything is loaded, this will succeed.
+ But be careful, to not invent new symbols ..."
sym := aString asSymbolIfInterned.
sym notNil ifTrue:[
- cls := self at:sym ifAbsent:nil.
- cls isBehavior ifTrue:[^ cls].
- cls isNil ifTrue:[
- idx := sym indexOfSubCollection:'::'.
- idx ~~ 0 ifTrue:[
- ns := sym copyTo:idx-1.
- nm := sym copyFrom:idx+2.
- ns := Smalltalk at:ns asSymbol.
- ns notNil ifTrue:[
- ns isNameSpace ifTrue:[
- cls := ns at:(nm asSymbol).
- ] ifFalse:[
- ns isBehavior ifTrue:[
- cls := ns privateClassesAt:(nm asSymbol).
- ]
- ]
- ].
- cls isBehavior ifTrue:[^ cls].
- ].
- ].
- ].
+ cls := self at:sym ifAbsent:nil.
+ cls isBehavior ifTrue:[^ cls].
+ ].
+
(aString endsWith:' class') ifTrue:[
- nonMeta := self classNamed:(aString copyWithoutLast:6).
- nonMeta notNil ifTrue:[
- ^ nonMeta theMetaclass
- ].
- ].
+ nonMeta := self classNamed:(aString copyWithoutLast:6).
+ nonMeta notNil ifTrue:[
+ ^ nonMeta theMetaclass
+ ].
+ ].
+
+ "no success yet. Try if this is a private classes of an autoloaded class"
+ cls isNil ifTrue:[
+ idx := aString indexOfSubCollection:'::'.
+ idx ~~ 0 ifTrue:[
+ prefix := aString copyTo:idx-1.
+ rest := aString copyFrom:idx+2.
+ namespace := self at:prefix asSymbolIfInterned ifAbsent:nil.
+ "namespace may be the owner of a private class.
+ NameSpaces and Behaviors have the same protocol"
+ [namespace isBehavior] whileTrue:[
+ idx := rest indexOfSubCollection:'::'.
+ idx ~~ 0 ifTrue:[
+ prefix := rest copyTo:idx-1.
+ rest := rest copyFrom:idx+2.
+ "this does an implicit autoload if required"
+ namespace := namespace privateClassesAt:prefix.
+ ] ifFalse:[
+ cls := namespace privateClassesAt:rest.
+ cls isBehavior ifTrue:[^ cls].
+ namespace := nil. "force exit of loop"
+ ].
+ ].
+ ].
+ ].
+
^ nil
"
Smalltalk classNamed:'Object'
+ Smalltalk classNamed:'Authentication::BasicAuthenticator::BasicAuthenticationData'
+ Smalltalk classNamed:'Authentication::BasicAuthenticator::BasicAuthenticationData class'
+ Smalltalk classNamed:'Authentication::BasicAuthenticator'
Smalltalk classNamed:'fooBar'
Smalltalk classNamed:'true'
Smalltalk classNamed:'Object class'
Smalltalk classNamed:'Metaclass'
Smalltalk classNamed:'Array'
- Smalltalk classNamed:'Array class'
+ Smalltalk classNamed:'Array class'
"
"Created: 24.11.1995 / 17:30:22 / cg"
@@ -2358,6 +2373,42 @@
"
!
+loadedClassNamed:aString
+ "Same as #classNamed,
+ but a private class of an autoloaded class will not be found."
+
+ |cls sym nonMeta|
+
+ "Quick try - if everything is loaded, this will succeed.
+ But be careful, to not invent new symbols ..."
+ sym := aString asSymbolIfInterned.
+ sym notNil ifTrue:[
+ cls := self at:sym ifAbsent:nil.
+ cls isBehavior ifTrue:[^ cls].
+ ].
+
+ (aString endsWith:' class') ifTrue:[
+ nonMeta := self loadedClassNamed:(aString copyWithoutLast:6).
+ nonMeta notNil ifTrue:[
+ ^ nonMeta theMetaclass
+ ].
+ ].
+ ^ nil
+
+ "
+ Smalltalk loadedClassNamed:'Object'
+ Smalltalk loadedClassNamed:'Authentication::BasicAuthenticator::BasicAuthenticationData'
+ Smalltalk loadedClassNamed:'Authentication::BasicAuthenticator::BasicAuthenticationData class'
+ Smalltalk loadedClassNamed:'Authentication::BasicAuthenticator'
+ Smalltalk loadedClassNamed:'fooBar'
+ Smalltalk loadedClassNamed:'true'
+ Smalltalk loadedClassNamed:'Object class'
+ Smalltalk loadedClassNamed:'Metaclass'
+ Smalltalk loadedClassNamed:'Array'
+ Smalltalk loadedClassNamed:'Array class'
+ "
+!
+
methodProtocolCompletion:aPartialProtocolName
"given a partial method protocol name, return an array consisting of
2 entries: 1st: the best (longest) match
@@ -6766,5 +6817,5 @@
!Smalltalk class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.725 2006-03-20 08:55:17 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.726 2006-06-15 09:53:03 stefan Exp $'
! !