NameSpace.st
changeset 13428 dd89d3cbed4e
parent 13173 43edd53e1204
child 13818 c29590514208
--- a/NameSpace.st	Tue Jun 28 20:28:58 2011 +0200
+++ b/NameSpace.st	Tue Jun 28 20:45:33 2011 +0200
@@ -13,7 +13,7 @@
 
 Object subclass:#NameSpace
 	instanceVariableNames:'category'
-	classVariableNames:''
+	classVariableNames:'Imports'
 	poolDictionaries:''
 	category:'Kernel-Classes'
 !
@@ -369,6 +369,26 @@
     ^ self allClasses collect:[:each | each nameWithoutPrefix]
 !
 
+import: aNameSpace
+
+    (aNameSpace isNameSpace or: [aNameSpace isProgrammingLanguage])
+        ifFalse:[self error: 'Not a namespace or prog. language'].
+
+    (self imports includes: aNameSpace) ifFalse:
+        [self setImports: (self imports copyWith: aNameSpace)]
+
+    "Created: / 21-07-2010 / 15:16:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-07-2010 / 17:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+imports
+    Imports ifNil:[^#()].
+    ^Imports at: self ifAbsent:[#()].
+
+    "Created: / 19-05-2010 / 16:06:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-07-2010 / 17:17:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 includesKey:aClassNameStringOrSymbol
     "{ Pragma: +optSpace }"
 
@@ -432,6 +452,40 @@
     "Modified: / 18.3.1999 / 17:21:06 / cg"
 !
 
+allClassesForWhich:filter
+    "return a collection with all classes in the system,
+     for which filter evaluates to true."
+
+    |collectedClasses|
+
+    collectedClasses := OrderedCollection new.
+    self allClassesForWhich:filter do:[:cls |
+        collectedClasses add:cls
+    ].
+    ^ collectedClasses
+
+    "
+     Smalltalk
+        allClassesForWhich:[:cls | cls name startsWith:'Po']
+    "
+
+    "Created: / 10-08-2006 / 12:11:31 / cg"
+!
+
+allClassesForWhich:filter do:aBlock
+    "evaluate the argument, aBlock for all classes in the system, for which filter evaluates to true."
+
+    self allClassesDo:[:cls |
+        (filter value:cls) ifTrue:[ aBlock value:cls ].
+    ].
+
+    "
+     Smalltalk
+        allClassesForWhich:[:cls | cls name startsWith:'Po']
+        do:[:aClass | Transcript showCR:aClass name]
+    "
+!
+
 allMethodsDo:aBlock
     "enumerate all methods in this namespace's classes"
 
@@ -550,6 +604,19 @@
     "Modified: 20.12.1996 / 15:11:31 / cg"
 ! !
 
+!NameSpace class methodsFor:'private'!
+
+setImports: anArrayOrNil
+
+    "Sets namespace imports. Private entry, 
+     Use 'self import: theNamespace' instead"
+
+    Imports ifNil:[Imports := IdentityDictionary new].
+	Imports at: self put: (anArrayOrNil ? #()).
+
+    "Created: / 21-07-2010 / 15:29:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !NameSpace class methodsFor:'queries'!
 
 allNameSpaces
@@ -650,10 +717,10 @@
 
 !NameSpace class methodsFor:'documentation'!
 
-version
-    ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.70 2010-12-20 11:06:03 cg Exp $'
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.71 2011-06-28 18:45:33 vrany Exp $'
 !
 
-version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.70 2010-12-20 11:06:03 cg Exp $'
+version_SVN
+    ^ ' Id: NameSpace.st 10643 2011-06-08 21:53:07Z vranyj1  '
 ! !