author | Claus Gittinger <cg@exept.de> |
Wed, 04 Aug 1999 16:10:22 +0200 | |
changeset 4522 | 29a6625dc7b1 |
parent 4457 | 001af8a9bd46 |
child 5249 | 77cad45f94f8 |
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 |
|
1933 | 14 |
Object subclass:#Namespace |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
15 |
instanceVariableNames:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
16 |
classVariableNames:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
17 |
poolDictionaries:'' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
18 |
category:'Kernel-Classes' |
1933 | 19 |
! |
1827 | 20 |
|
21 |
!Namespace class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
1816 | 36 |
! |
37 |
||
1827 | 38 |
documentation |
39 |
" |
|
40 |
A Namespace is actually a dummy class, providing a home |
|
2010 | 41 |
for its private classes. |
42 |
Thus, internally, the same mechanism is used for classes in |
|
43 |
a namespace and private classes. |
|
44 |
This has two advantages: |
|
1828 | 45 |
- we only need one mechanism for both namespaces |
46 |
and private classes |
|
47 |
||
48 |
- there are no possible conflicts between a class |
|
49 |
and a namespace named alike. |
|
50 |
||
1816 | 51 |
|
1827 | 52 |
[author:] |
53 |
Claus Gittinger |
|
54 |
||
55 |
[see also:] |
|
56 |
Behavior ClassDescription Class Metaclass |
|
57 |
PrivateMetaclass |
|
58 |
" |
|
59 |
||
60 |
! ! |
|
61 |
||
1828 | 62 |
!Namespace class methodsFor:'instance creation'! |
63 |
||
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
64 |
fullName:aFullNameSpacePathName |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
65 |
"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
|
66 |
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
|
67 |
bottom-level space." |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
68 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
69 |
"/ 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
|
70 |
"/ create them as required. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
71 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
72 |
|list idx0 idx superSpace done thisNamespace| |
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 := OrderedCollection new. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
75 |
idx0 := 1. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
76 |
done := false. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
77 |
[done] whileFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
78 |
idx := aFullNameSpacePathName indexOf:$: startingAt:idx0. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
79 |
(idx ~~ 0) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
80 |
(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
|
81 |
superSpace := aFullNameSpacePathName copyFrom:idx0 to:(idx-1). |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
82 |
list add:superSpace. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
83 |
idx0 := idx +2. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
84 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
85 |
done := true |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
86 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
87 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
88 |
done := true. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
89 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
90 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
91 |
list add:(aFullNameSpacePathName copyFrom:idx0). |
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 |
"/ now, look and create 'em |
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 |
thisNamespace := nil. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
96 |
list do:[:aName | |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
97 |
|key x| |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
98 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
99 |
key := aName asSymbol. |
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 |
thisNamespace isNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
102 |
(Smalltalk includesKey:key) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
103 |
thisNamespace := Smalltalk at:key. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
104 |
(thisNamespace notNil |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
105 |
and:[thisNamespace isBehavior not]) ifTrue:[ |
4522
29a6625dc7b1
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4457
diff
changeset
|
106 |
self error:'name conflict: namespace ' , aName , ' vs. global'. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
107 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
108 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
109 |
thisNamespace isNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
110 |
thisNamespace := self name:key |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
111 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
112 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
113 |
x := thisNamespace privateClassesAt:key. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
114 |
x notNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
115 |
thisNamespace := x |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
116 |
] ifFalse:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
117 |
thisNamespace := |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
118 |
self subclass:key |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
119 |
instanceVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
120 |
classVariableNames:'' |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
121 |
poolDictionaries:'' |
2055 | 122 |
privateIn:thisNamespace. |
123 |
||
124 |
"/ nameSpaces are not in any package |
|
125 |
thisNamespace setPackage:nil. |
|
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
126 |
] |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
127 |
] |
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 |
^ thisNamespace |
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 |
"Created: 8.11.1996 / 13:41:59 / cg" |
2055 | 133 |
"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
|
134 |
! |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
135 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
136 |
name:aStringOrSymbol |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
137 |
"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
|
138 |
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
|
139 |
dont get confused; we recommend, not to nest them too much." |
1908 | 140 |
|
3383 | 141 |
|currentNameSpace newNamespace existing ok nameSym| |
1828 | 142 |
|
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
143 |
ok := aStringOrSymbol first isLetter. |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
144 |
ok ifTrue:[ |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
145 |
(aStringOrSymbol |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
146 |
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
|
147 |
startingAt:2) ~~ 0 |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
148 |
ifTrue:[ |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
149 |
ok := false. |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
150 |
] |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
151 |
|
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
152 |
"/ 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
|
153 |
"/ ch := aStringOrSymbol at:idx. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
154 |
"/ ok ifTrue:[ |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
155 |
"/ ok := ch isLetterOrDigit or:[ch == $_]. |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
156 |
"/ ] |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
157 |
"/ ] |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
158 |
]. |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
159 |
ok ifFalse:[ |
2025 | 160 |
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
|
161 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
162 |
|
4058
58987b73c0c7
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3383
diff
changeset
|
163 |
currentNameSpace := Class nameSpaceQuerySignal query. |
3383 | 164 |
currentNameSpace isNil ifTrue:[currentNameSpace := Smalltalk]. |
165 |
||
166 |
nameSym := aStringOrSymbol asSymbol. |
|
167 |
(existing := currentNameSpace at:nameSym) notNil ifTrue:[ |
|
2015 | 168 |
^ existing |
169 |
]. |
|
170 |
||
3383 | 171 |
newNamespace := self subclass:nameSym |
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 |
|
4058
58987b73c0c7
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3383
diff
changeset
|
192 |
"Modified: / 14.9.1997 / 09:46:59 / cg" |
58987b73c0c7
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3383
diff
changeset
|
193 |
"Modified: / 18.3.1999 / 18:24:13 / stefan" |
1828 | 194 |
! |
195 |
||
196 |
new |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
197 |
"catch new - namespaces are not to be created by the user" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
198 |
|
1828 | 199 |
self error:'namespaces are not to be created with new' |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
200 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
201 |
"Modified: 8.11.1996 / 21:38:00 / cg" |
1828 | 202 |
! ! |
203 |
||
1908 | 204 |
!Namespace class methodsFor:'accessing'! |
1827 | 205 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
206 |
allClasses |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
207 |
|classes| |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
208 |
|
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
209 |
classes := IdentitySet new. |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
210 |
self allBehaviorsDo:[:aClass | classes add:aClass]. |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
211 |
^ classes |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
212 |
|
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
213 |
"Modified: 20.12.1996 / 15:34:50 / cg" |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
214 |
! |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
215 |
|
4372
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
216 |
allClassesWithAllPrivateClasses |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
217 |
|classes| |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
218 |
|
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
219 |
classes := IdentitySet new. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
220 |
self allBehaviorsDo:[:aClass | |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
221 |
classes add:aClass. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
222 |
aClass addAllPrivateClassesTo:classes. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
223 |
]. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
224 |
^ classes |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
225 |
|
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
226 |
"Modified: 20.12.1996 / 15:34:50 / cg" |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
227 |
! |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
228 |
|
1827 | 229 |
at:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
230 |
"return a class from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
231 |
|
1828 | 232 |
^ self privateClassesAt:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
233 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
234 |
"Modified: 8.11.1996 / 21:39:41 / cg" |
1827 | 235 |
! |
236 |
||
237 |
at:classNameSymbol ifAbsent:exceptionBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
238 |
"return a class or an alternative |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
239 |
from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
240 |
|
1827 | 241 |
|cls| |
242 |
||
1828 | 243 |
cls := self privateClassesAt:classNameSymbol. |
1827 | 244 |
cls isNil ifTrue:[ |
245 |
^ exceptionBlock value |
|
246 |
]. |
|
247 |
^ cls |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
248 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
249 |
"Modified: 8.11.1996 / 21:40:01 / cg" |
1827 | 250 |
! |
251 |
||
252 |
at:classNameSymbol put:aClass |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
253 |
"add a class to the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
254 |
|
1828 | 255 |
^ self privateClassesAt:classNameSymbol put:aClass |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
256 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
257 |
"Modified: 8.11.1996 / 21:40:12 / cg" |
2908 | 258 |
! |
259 |
||
260 |
classNamed:aString |
|
261 |
"return the class with name aString, or nil if absent. |
|
262 |
To get to the metaClass, append ' class' to the string." |
|
263 |
||
264 |
^ Smalltalk classNamed:(self name , '::' , aString) |
|
265 |
||
266 |
"Created: 9.9.1997 / 03:33:56 / cg" |
|
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
267 |
! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
268 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
269 |
includesKey:aClassNameStringOrSymbol |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
270 |
"{ Pragma: +optSpace }" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
271 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
272 |
"return true if such a key is present" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
273 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
274 |
|nmSym| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
275 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
276 |
nmSym := (self name , '::' , aClassNameStringOrSymbol) asSymbolIfInterned. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
277 |
nmSym isNil ifTrue:[^ false]. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
278 |
^ Smalltalk includesKey:nmSym. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
279 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
280 |
|
1827 | 281 |
! ! |
282 |
||
1908 | 283 |
!Namespace class methodsFor:'enumerating'! |
1816 | 284 |
|
285 |
allBehaviorsDo:aBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
286 |
"enumerate all classes in this namespace" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
287 |
|
2492 | 288 |
Smalltalk allBehaviorsDo:[:aClass | |
4068
ba1b46d15e70
skip metaclasses when enumerating behaviors of a namespace
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
289 |
(aClass isBehavior and:[aClass isMeta not]) ifTrue:[ |
2583 | 290 |
aClass nameSpace == self ifTrue:[ |
291 |
aBlock value:aClass |
|
292 |
]. |
|
2492 | 293 |
] |
294 |
]. |
|
2583 | 295 |
|
4068
ba1b46d15e70
skip metaclasses when enumerating behaviors of a namespace
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
296 |
"Modified: / 18.3.1999 / 17:21:06 / cg" |
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
297 |
! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
298 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
299 |
keysDo:aBlock |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
300 |
"enumerate all class names in this namespace" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
301 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
302 |
|prefix prefixLen| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
303 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
304 |
prefix := self name , '::'. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
305 |
prefixLen := prefix size. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
306 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
307 |
Smalltalk keysAndValuesDo:[:aName :aClass | |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
308 |
|key| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
309 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
310 |
(aName startsWith:prefix) ifTrue:[ |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
311 |
key := (aName copyFrom:prefixLen+1) asSymbol. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
312 |
aBlock value:key |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
313 |
] |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
314 |
]. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
315 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
316 |
" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
317 |
Benchmarks keysDo:[:k | Transcript showCR:k] |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
318 |
" |
1816 | 319 |
! ! |
320 |
||
1908 | 321 |
!Namespace class methodsFor:'fileOut'! |
1828 | 322 |
|
2058 | 323 |
fileOutDefinitionOn:aStream |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
324 |
"redefined to generate another definition message" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
325 |
|
1934 | 326 |
self == Namespace ifTrue:[ |
2058 | 327 |
super fileOutDefinitionOn:aStream |
1934 | 328 |
] ifFalse:[ |
329 |
aStream nextPutAll:('Namespace name:' , self name storeString) |
|
330 |
] |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
331 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
332 |
"Modified: 8.11.1996 / 21:39:03 / cg" |
2058 | 333 |
"Created: 4.1.1997 / 20:36:32 / cg" |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
334 |
! ! |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
335 |
|
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
336 |
!Namespace class methodsFor:'inspecting'! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
337 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
338 |
inspectorClass |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
339 |
"{ Pragma: +optSpace }" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
340 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
341 |
"redefined to launch a DictionaryInspector |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
342 |
(instead of the default Inspector)." |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
343 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
344 |
^ DictionaryInspectorView |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
345 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
346 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
347 |
! ! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
348 |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
349 |
!Namespace class methodsFor:'printing & storing'! |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
350 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
351 |
displayString |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
352 |
"return a printed represenation - here, a reminder is appended, |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
353 |
that this is not a regular class" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
354 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
355 |
self == Namespace ifTrue:[ |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
356 |
^ super displayString |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
357 |
]. |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
358 |
^ self name , ' (* namespace *)' |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
359 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
360 |
"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
|
361 |
"Modified: 20.12.1996 / 15:11:31 / cg" |
1828 | 362 |
! ! |
363 |
||
1908 | 364 |
!Namespace class methodsFor:'queries'! |
1816 | 365 |
|
2031 | 366 |
allNamespaces |
2030 | 367 |
"return a list of all namespaces" |
368 |
||
369 |
|set| |
|
370 |
||
371 |
set := IdentitySet with:Smalltalk. |
|
372 |
Smalltalk allBehaviorsDo:[:aClass | |
|
373 |
(aClass isNamespace |
|
374 |
and:[aClass ~~ Namespace |
|
375 |
and:[aClass ~~ Smalltalk]]) ifTrue:[ |
|
376 |
set add:aClass |
|
377 |
] |
|
378 |
]. |
|
379 |
^ set |
|
380 |
||
381 |
"Created: 2.1.1997 / 20:17:40 / cg" |
|
2055 | 382 |
! |
383 |
||
384 |
isNamespace |
|
385 |
"return true - I am a namespace" |
|
386 |
||
387 |
self == Namespace ifTrue:[^ false]. |
|
388 |
^ true |
|
389 |
||
390 |
"Created: 26.10.1996 / 11:13:36 / cg" |
|
391 |
"Modified: 20.12.1996 / 15:11:45 / cg" |
|
4457 | 392 |
! |
393 |
||
394 |
isTopLevelNamespace |
|
395 |
^ (self name includes:$:) not |
|
396 |
||
397 |
||
1816 | 398 |
! ! |
399 |
||
400 |
!Namespace class methodsFor:'documentation'! |
|
401 |
||
402 |
version |
|
4522
29a6625dc7b1
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4457
diff
changeset
|
403 |
^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.32 1999-08-04 14:08:36 cg Exp $' |
1816 | 404 |
! ! |