class: NameSpace
added: #fullName:createIfAbsent:
changed: #fullName:
allow checking for the presence of a namespace without creating
(for synaxhighlighter)
--- a/NameSpace.st Wed Feb 18 21:30:21 2015 +0100
+++ b/NameSpace.st Thu Feb 19 10:44:38 2015 +0100
@@ -68,11 +68,24 @@
intermediate spaces (if not already existing) and return the
bottom-level space."
+ ^ self fullName:aFullNameSpacePathName createIfAbsent:true
+
+ "Created: 8.11.1996 / 13:41:59 / cg"
+ "Modified: 4.1.1997 / 16:50:59 / cg"
+!
+
+fullName:aFullNameSpacePathName createIfAbsent:createIfAbsent
+ "given a possibly nested name of a namespace, lookup and return
+ a namespace instance for it.
+ If createIfAbsent is true, create all required intermediate spaces (if not already existing)
+ and return the bottom-level space.
+ If false, and if any namespace along the path does not exist, reutrn nil."
+
+ |list thisNamespace|
+
"/ break it up, check for all intermediate spaces to exist
"/ create them as required.
- |list thisNamespace|
-
(aFullNameSpacePathName includes:$:) ifTrue:[
"/ old style
list := aFullNameSpacePathName asCollectionOfSubstringsSeparatedByAll:'::'.
@@ -94,10 +107,12 @@
thisNamespace := Smalltalk at:key.
(thisNamespace notNil
and:[thisNamespace isBehavior not]) ifTrue:[
+ createIfAbsent ifFalse:[ ^ nil ].
self error:'name conflict: namespace ' , aName , ' vs. global'.
]
].
thisNamespace isNil ifTrue:[
+ createIfAbsent ifFalse:[ ^ nil ].
thisNamespace := self name:key
].
] ifFalse:[
@@ -110,12 +125,13 @@
].
x isNil ifTrue:[
+ createIfAbsent ifFalse:[ ^ nil ].
thisNamespace isNameSpace ifTrue:[
- thisNamespace == Smalltalk ifTrue:[
- x := self name:key
- ] ifFalse:[
+ thisNamespace == Smalltalk ifTrue:[
+ x := self name:key
+ ] ifFalse:[
x := thisNamespace name:key.
- ]
+ ]
] ifFalse:[
x :=
self subclass:key
@@ -740,7 +756,7 @@
!NameSpace class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.78 2015-02-07 15:39:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.79 2015-02-19 09:44:38 cg Exp $'
!
version_SVN