author | Claus Gittinger <cg@exept.de> |
Mon, 15 Sep 1997 22:41:53 +0200 | |
changeset 2924 | 398bec06170f |
parent 2908 | b3be3629fcb1 |
child 3383 | 7837c591ecdb |
permissions | -rw-r--r-- |
1827 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
13 |
|
2924 | 14 |
'From Smalltalk/X, Version:3.1.10 on 14-sep-1997 at 10:03:22 pm' ! |
2908 | 15 |
|
1933 | 16 |
Object subclass:#Namespace |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
17 |
instanceVariableNames:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
18 |
classVariableNames:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
19 |
poolDictionaries:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
20 |
category:'Kernel-Classes' |
1933 | 21 |
! |
1827 | 22 |
|
23 |
!Namespace class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
1816 | 38 |
! |
39 |
||
1827 | 40 |
documentation |
41 |
" |
|
42 |
A Namespace is actually a dummy class, providing a home |
|
2010 | 43 |
for its private classes. |
44 |
Thus, internally, the same mechanism is used for classes in |
|
45 |
a namespace and private classes. |
|
46 |
This has two advantages: |
|
1828 | 47 |
- we only need one mechanism for both namespaces |
48 |
and private classes |
|
49 |
||
50 |
- there are no possible conflicts between a class |
|
51 |
and a namespace named alike. |
|
52 |
||
1816 | 53 |
|
1827 | 54 |
[author:] |
55 |
Claus Gittinger |
|
56 |
||
57 |
[see also:] |
|
58 |
Behavior ClassDescription Class Metaclass |
|
59 |
PrivateMetaclass |
|
60 |
" |
|
61 |
||
62 |
! ! |
|
63 |
||
1828 | 64 |
!Namespace class methodsFor:'instance creation'! |
65 |
||
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
66 |
fullName:aFullNameSpacePathName |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
67 |
"given a possibly nested name of a namespace, create all required |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
68 |
intermediate spaces (if not already existing) and return the |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
69 |
bottom-level space." |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
70 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
71 |
"/ break it up, check for all intermediate spaces to exist |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
72 |
"/ create them as required. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
73 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
74 |
|list idx0 idx superSpace done thisNamespace| |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
75 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
76 |
list := OrderedCollection new. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
77 |
idx0 := 1. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
78 |
done := false. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
79 |
[done] whileFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
80 |
idx := aFullNameSpacePathName indexOf:$: startingAt:idx0. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
81 |
(idx ~~ 0) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
82 |
(idx < aFullNameSpacePathName size and:[(aFullNameSpacePathName at:(idx+1)) == $:]) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
83 |
superSpace := aFullNameSpacePathName copyFrom:idx0 to:(idx-1). |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
84 |
list add:superSpace. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
85 |
idx0 := idx +2. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
86 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
87 |
done := true |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
88 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
89 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
90 |
done := true. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
91 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
92 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
93 |
list add:(aFullNameSpacePathName copyFrom:idx0). |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
94 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
95 |
"/ now, look and create 'em |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
96 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
97 |
thisNamespace := nil. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
98 |
list do:[:aName | |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
99 |
|key x| |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
100 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
101 |
key := aName asSymbol. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
102 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
103 |
thisNamespace isNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
104 |
(Smalltalk includesKey:key) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
105 |
thisNamespace := Smalltalk at:key. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
106 |
(thisNamespace notNil |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
107 |
and:[thisNamespace isBehavior not]) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
108 |
^ self error:'name conflict: namespace ' , aName , ' vs. global'. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
109 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
110 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
111 |
thisNamespace isNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
112 |
thisNamespace := self name:key |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
113 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
114 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
115 |
x := thisNamespace privateClassesAt:key. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
116 |
x notNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
117 |
thisNamespace := x |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
118 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
119 |
thisNamespace := |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
120 |
self subclass:key |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
121 |
instanceVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
122 |
classVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
123 |
poolDictionaries:'' |
2055 | 124 |
privateIn:thisNamespace. |
125 |
||
126 |
"/ nameSpaces are not in any package |
|
127 |
thisNamespace setPackage:nil. |
|
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
128 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
129 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
130 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
131 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
132 |
^ thisNamespace |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
133 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
134 |
"Created: 8.11.1996 / 13:41:59 / cg" |
2055 | 135 |
"Modified: 4.1.1997 / 16:50:59 / cg" |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
136 |
! |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
137 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
138 |
name:aStringOrSymbol |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
139 |
"create a new nameSpace, named aStringOrSymbol. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
140 |
Notice, that the nameSpace is created in the current one - |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
141 |
dont get confused; we recommend, not to nest them too much." |
1908 | 142 |
|
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
143 |
|currentNameSpace newNamespace existing ok| |
1828 | 144 |
|
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
145 |
ok := aStringOrSymbol first isLetter. |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
146 |
ok ifTrue:[ |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
147 |
(aStringOrSymbol |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
148 |
findFirst:[:ch | (ch isLetterOrDigit or:[ch == $_]) not] |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
149 |
startingAt:2) ~~ 0 |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
150 |
ifTrue:[ |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
151 |
ok := false. |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
152 |
] |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
153 |
|
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
154 |
"/ 2 to:aStringOrSymbol size do:[:idx | |ch| |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
155 |
"/ ch := aStringOrSymbol at:idx. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
156 |
"/ ok ifTrue:[ |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
157 |
"/ ok := ch isLetterOrDigit or:[ch == $_]. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
158 |
"/ ] |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
159 |
"/ ] |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
160 |
]. |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
161 |
ok ifFalse:[ |
2025 | 162 |
self error:'invalid namespace name:''' , aStringOrSymbol printString , ''' (must be a valid identifier)'. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
163 |
^ nil. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
164 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
165 |
|
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
166 |
currentNameSpace := Class nameSpaceQuerySignal raise. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
167 |
(existing := currentNameSpace at:aStringOrSymbol asSymbol) notNil ifTrue:[ |
2015 | 168 |
^ existing |
169 |
]. |
|
170 |
||
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
171 |
newNamespace := self subclass:aStringOrSymbol asSymbol |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
172 |
instanceVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
173 |
classVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
174 |
poolDictionaries:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
175 |
category:'uncategorized namespace'. |
2144 | 176 |
|
2055 | 177 |
"/ nameSpaces are not in any package |
2924 | 178 |
newNamespace notNil ifTrue:[newNamespace setPackage:nil]. |
1828 | 179 |
^ newNamespace |
1901 | 180 |
|
181 |
" |
|
182 |
Namespace name:'foo' |
|
183 |
(Namespace name:'foo') category:'my name space' |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
184 |
foo at:#bar put:(Metaclass new new) |
1901 | 185 |
" |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
186 |
" |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
187 |
Namespace name:'an-invalid++name' |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
188 |
Namespace name:'another:invalidName' |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
189 |
Namespace name:'another::invalidName' |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
190 |
" |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
191 |
|
2924 | 192 |
"Modified: 14.9.1997 / 09:46:59 / cg" |
1828 | 193 |
! |
194 |
||
195 |
new |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
196 |
"catch new - namespaces are not to be created by the user" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
197 |
|
1828 | 198 |
self error:'namespaces are not to be created with new' |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
199 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
200 |
"Modified: 8.11.1996 / 21:38:00 / cg" |
1828 | 201 |
! ! |
202 |
||
1908 | 203 |
!Namespace class methodsFor:'accessing'! |
1827 | 204 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
205 |
allClasses |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
206 |
|classes| |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
207 |
|
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
208 |
classes := IdentitySet new. |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
209 |
self allBehaviorsDo:[:aClass | classes add:aClass]. |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
210 |
^ classes |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
211 |
|
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
212 |
"Modified: 20.12.1996 / 15:34:50 / cg" |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
213 |
! |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
214 |
|
1827 | 215 |
at:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
216 |
"return a class from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
217 |
|
1828 | 218 |
^ self privateClassesAt:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
219 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
220 |
"Modified: 8.11.1996 / 21:39:41 / cg" |
1827 | 221 |
! |
222 |
||
223 |
at:classNameSymbol ifAbsent:exceptionBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
224 |
"return a class or an alternative |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
225 |
from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
226 |
|
1827 | 227 |
|cls| |
228 |
||
1828 | 229 |
cls := self privateClassesAt:classNameSymbol. |
1827 | 230 |
cls isNil ifTrue:[ |
231 |
^ exceptionBlock value |
|
232 |
]. |
|
233 |
^ cls |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
234 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
235 |
"Modified: 8.11.1996 / 21:40:01 / cg" |
1827 | 236 |
! |
237 |
||
238 |
at:classNameSymbol put:aClass |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
239 |
"add a class to the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
240 |
|
1828 | 241 |
^ self privateClassesAt:classNameSymbol put:aClass |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
242 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
243 |
"Modified: 8.11.1996 / 21:40:12 / cg" |
2908 | 244 |
! |
245 |
||
246 |
classNamed:aString |
|
247 |
"return the class with name aString, or nil if absent. |
|
248 |
To get to the metaClass, append ' class' to the string." |
|
249 |
||
250 |
^ Smalltalk classNamed:(self name , '::' , aString) |
|
251 |
||
252 |
"Created: 9.9.1997 / 03:33:56 / cg" |
|
1827 | 253 |
! ! |
254 |
||
1908 | 255 |
!Namespace class methodsFor:'enumerating'! |
1816 | 256 |
|
257 |
allBehaviorsDo:aBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
258 |
"enumerate all classes in this namespace" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
259 |
|
2492 | 260 |
Smalltalk allBehaviorsDo:[:aClass | |
261 |
aClass isBehavior ifTrue:[ |
|
2583 | 262 |
aClass nameSpace == self ifTrue:[ |
263 |
aBlock value:aClass |
|
264 |
]. |
|
2492 | 265 |
] |
266 |
]. |
|
2583 | 267 |
|
268 |
"Modified: 23.4.1997 / 17:00:48 / cg" |
|
1816 | 269 |
! ! |
270 |
||
1908 | 271 |
!Namespace class methodsFor:'fileOut'! |
1828 | 272 |
|
2058 | 273 |
fileOutDefinitionOn:aStream |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
274 |
"redefined to generate another definition message" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
275 |
|
1934 | 276 |
self == Namespace ifTrue:[ |
2058 | 277 |
super fileOutDefinitionOn:aStream |
1934 | 278 |
] ifFalse:[ |
279 |
aStream nextPutAll:('Namespace name:' , self name storeString) |
|
280 |
] |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
281 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
282 |
"Modified: 8.11.1996 / 21:39:03 / cg" |
2058 | 283 |
"Created: 4.1.1997 / 20:36:32 / cg" |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
284 |
! ! |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
285 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
286 |
!Namespace class methodsFor:'printing & storing'! |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
287 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
288 |
displayString |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
289 |
"return a printed represenation - here, a reminder is appended, |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
290 |
that this is not a regular class" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
291 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
292 |
self == Namespace ifTrue:[ |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
293 |
^ super displayString |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
294 |
]. |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
295 |
^ self name , ' (* namespace *)' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
296 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
297 |
"Created: 8.11.1996 / 21:37:24 / cg" |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
298 |
"Modified: 20.12.1996 / 15:11:31 / cg" |
1828 | 299 |
! ! |
300 |
||
1908 | 301 |
!Namespace class methodsFor:'queries'! |
1816 | 302 |
|
2031 | 303 |
allNamespaces |
2030 | 304 |
"return a list of all namespaces" |
305 |
||
306 |
|set| |
|
307 |
||
308 |
set := IdentitySet with:Smalltalk. |
|
309 |
Smalltalk allBehaviorsDo:[:aClass | |
|
310 |
(aClass isNamespace |
|
311 |
and:[aClass ~~ Namespace |
|
312 |
and:[aClass ~~ Smalltalk]]) ifTrue:[ |
|
313 |
set add:aClass |
|
314 |
] |
|
315 |
]. |
|
316 |
^ set |
|
317 |
||
318 |
"Created: 2.1.1997 / 20:17:40 / cg" |
|
2055 | 319 |
! |
320 |
||
321 |
isNamespace |
|
322 |
"return true - I am a namespace" |
|
323 |
||
324 |
self == Namespace ifTrue:[^ false]. |
|
325 |
^ true |
|
326 |
||
327 |
"Created: 26.10.1996 / 11:13:36 / cg" |
|
328 |
"Modified: 20.12.1996 / 15:11:45 / cg" |
|
1816 | 329 |
! ! |
330 |
||
331 |
!Namespace class methodsFor:'documentation'! |
|
332 |
||
333 |
version |
|
2924 | 334 |
^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.25 1997-09-15 20:41:51 cg Exp $' |
1816 | 335 |
! ! |