author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 24251 | 134cdb154b0d |
child 24568 | 7b8e0a205056 |
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 |
" |
|
5464 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17443 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
5331 | 16 |
Object subclass:#NameSpace |
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
17 |
instanceVariableNames:'category' |
13428 | 18 |
classVariableNames:'Imports' |
1943
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 |
|
5331 | 23 |
!NameSpace class methodsFor:'documentation'! |
1827 | 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 |
" |
|
5331 | 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 |
|
5331 | 45 |
a NameSpace and private classes. |
2010 | 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 |
||
5331 | 64 |
!NameSpace class methodsFor:'instance creation'! |
1828 | 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 |
|
17510 | 71 |
^ self fullName:aFullNameSpacePathName createIfAbsent:true |
72 |
||
73 |
"Created: 8.11.1996 / 13:41:59 / cg" |
|
74 |
"Modified: 4.1.1997 / 16:50:59 / cg" |
|
75 |
! |
|
76 |
||
77 |
fullName:aFullNameSpacePathName createIfAbsent:createIfAbsent |
|
78 |
"given a possibly nested name of a namespace, lookup and return |
|
79 |
a namespace instance for it. |
|
80 |
If createIfAbsent is true, create all required intermediate spaces (if not already existing) |
|
81 |
and return the bottom-level space. |
|
82 |
If false, and if any namespace along the path does not exist, reutrn nil." |
|
83 |
||
84 |
|list thisNamespace| |
|
85 |
||
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
86 |
"/ 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
|
87 |
"/ create them as required. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
88 |
|
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
89 |
(aFullNameSpacePathName includes:$:) ifTrue:[ |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
90 |
"/ old style |
8744
73522a385e11
oops - fullName did not handle '::' correctly
Claus Gittinger <cg@exept.de>
parents:
7575
diff
changeset
|
91 |
list := aFullNameSpacePathName asCollectionOfSubstringsSeparatedByAll:'::'. |
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
92 |
] ifFalse:[ |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
93 |
"/ new style |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
94 |
list := aFullNameSpacePathName asCollectionOfSubstringsSeparatedBy:$.. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
95 |
]. |
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 |
"/ now, look and create 'em |
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 |
thisNamespace := nil. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
100 |
list do:[:aName | |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
101 |
|key x| |
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 |
key := aName asSymbol. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
104 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
105 |
thisNamespace isNil ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
106 |
(Smalltalk includesKey:key) ifTrue:[ |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
107 |
thisNamespace := Smalltalk at:key. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
108 |
(thisNamespace notNil |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
109 |
and:[thisNamespace isBehavior not]) ifTrue:[ |
17510 | 110 |
createIfAbsent ifFalse:[ ^ nil ]. |
4522
29a6625dc7b1
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4457
diff
changeset
|
111 |
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
|
112 |
] |
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 |
thisNamespace isNil ifTrue:[ |
17510 | 115 |
createIfAbsent ifFalse:[ ^ nil ]. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
116 |
thisNamespace := self name:key |
8747 | 117 |
]. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
118 |
] ifFalse:[ |
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
119 |
thisNamespace isNameSpace ifTrue:[ |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
120 |
x := thisNamespace at:key. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
121 |
] ifFalse:[ |
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
122 |
thisNamespace isBehavior ifTrue:[ |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
123 |
x := thisNamespace privateClassesAt:key. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
124 |
]. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
125 |
]. |
2055 | 126 |
|
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
127 |
x isNil ifTrue:[ |
17510 | 128 |
createIfAbsent ifFalse:[ ^ nil ]. |
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
129 |
thisNamespace isNameSpace ifTrue:[ |
17510 | 130 |
thisNamespace == Smalltalk ifTrue:[ |
131 |
x := self name:key |
|
132 |
] ifFalse:[ |
|
8747 | 133 |
x := thisNamespace name:key. |
17510 | 134 |
] |
7426
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
135 |
] ifFalse:[ |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
136 |
x := |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
137 |
self subclass:key |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
138 |
instanceVariableNames:'' |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
139 |
classVariableNames:'' |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
140 |
poolDictionaries:'' |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
141 |
privateIn:thisNamespace. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
142 |
]. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
143 |
|
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
144 |
"/ nameSpaces are not in any package (yet) |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
145 |
x setPackage:nil. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
146 |
]. |
4059d00c81d7
also allow '.' as ns-separator
Claus Gittinger <cg@exept.de>
parents:
7317
diff
changeset
|
147 |
thisNamespace := x. |
8747 | 148 |
]. |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
149 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
150 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
151 |
^ thisNamespace |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
152 |
|
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
153 |
"Created: 8.11.1996 / 13:41:59 / cg" |
2055 | 154 |
"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
|
155 |
! |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
156 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
157 |
name:aStringOrSymbol |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
158 |
"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
|
159 |
Notice, that the nameSpace is created in the current one - |
14067 | 160 |
don't get confused; we recommend, not to nest them too much." |
1908 | 161 |
|
23064 | 162 |
|currentNameSpace newNameSpace existing ok nameSym fullName |
163 |
idx firstPart rest ns| |
|
1828 | 164 |
|
23064 | 165 |
"/ ouch: care for more ::'s in the given sub-name |
166 |
(aStringOrSymbol includesString:'::') ifTrue:[ |
|
167 |
idx := aStringOrSymbol indexOfString:'::'. |
|
168 |
firstPart := aStringOrSymbol copyTo:(idx-1). |
|
169 |
rest := aStringOrSymbol copyFrom:(idx+2). |
|
170 |
ns := self name:firstPart. |
|
171 |
^ ns name:rest. |
|
172 |
]. |
|
173 |
||
17443 | 174 |
ok := aStringOrSymbol first isLetterOrUnderline. |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
175 |
ok ifTrue:[ |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
176 |
(aStringOrSymbol |
24251 | 177 |
findFirst:[:ch | (ch isLetterOrDigitOrUnderline) not] |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
178 |
startingAt:2) ~~ 0 |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
179 |
ifTrue:[ |
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
180 |
ok := false. |
2024
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
181 |
] |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
182 |
]. |
71a088db4583
validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents:
2015
diff
changeset
|
183 |
ok ifFalse:[ |
2025 | 184 |
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
|
185 |
]. |
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
186 |
|
5249
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
187 |
nameSym := aStringOrSymbol asSymbol. |
3383 | 188 |
|
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
189 |
self == NameSpace ifTrue:[ |
7575
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
190 |
"/ currentNameSpace := Class nameSpaceQuerySignal query. |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
191 |
currentNameSpace isNil ifTrue:[ |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
192 |
currentNameSpace := Smalltalk |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
193 |
]. |
5249
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
194 |
fullName := nameSym |
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
195 |
] ifFalse:[ |
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
196 |
currentNameSpace := self. |
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
197 |
fullName := (self name , '::' , nameSym) asSymbol |
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
198 |
]. |
77cad45f94f8
fixed sub-namespace creation
Claus Gittinger <cg@exept.de>
parents:
4522
diff
changeset
|
199 |
|
3383 | 200 |
(existing := currentNameSpace at:nameSym) notNil ifTrue:[ |
2015 | 201 |
^ existing |
202 |
]. |
|
7575
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
203 |
newNameSpace := self |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
204 |
subclass:fullName |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
205 |
instanceVariableNames:'' |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
206 |
classVariableNames:'' |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
207 |
poolDictionaries:'' |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
208 |
category:'uncategorized namespace' |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
209 |
inEnvironment:Smalltalk. |
2144 | 210 |
|
2055 | 211 |
"/ nameSpaces are not in any package |
7575
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
212 |
newNameSpace notNil ifTrue:[newNameSpace setPackage:nil]. |
80341bf0e03e
bug: created sub-nameSpace Foo::Foo,
Claus Gittinger <cg@exept.de>
parents:
7433
diff
changeset
|
213 |
^ newNameSpace |
1901 | 214 |
|
215 |
" |
|
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
216 |
NameSpace name:'foo' |
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
217 |
(NameSpace name:'foo') category:'my name space' |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
218 |
foo at:#bar put:(Metaclass new new) |
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
219 |
(NameSpace name:'foo') name:'bar' |
1901 | 220 |
" |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
221 |
" |
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
222 |
NameSpace name:'an-invalid++name' |
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
223 |
NameSpace name:'another:invalidName' |
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
224 |
NameSpace name:'another::invalidName' |
2177
80f6ec11f797
create new namespaces in the current nameSpace (by default)
Claus Gittinger <cg@exept.de>
parents:
2144
diff
changeset
|
225 |
" |
1931
5f60d3e5ba6e
moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents:
1908
diff
changeset
|
226 |
|
14067 | 227 |
"Modified: / 14-09-1997 / 09:46:59 / cg" |
228 |
"Modified: / 18-03-1999 / 18:24:13 / stefan" |
|
229 |
"Modified (comment): / 23-03-2012 / 11:49:00 / cg" |
|
24251 | 230 |
"Modified: / 05-06-2019 / 17:06:27 / Claus Gittinger" |
1828 | 231 |
! |
232 |
||
233 |
new |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
234 |
"catch new - namespaces are not to be created by the user" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
235 |
|
1828 | 236 |
self error:'namespaces are not to be created with new' |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
237 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
238 |
"Modified: 8.11.1996 / 21:38:00 / cg" |
1828 | 239 |
! ! |
240 |
||
7298 | 241 |
!NameSpace class methodsFor:'Compatibility-VW5.4'! |
6450 | 242 |
|
243 |
defineClass: name |
|
244 |
superclass: superclass |
|
245 |
indexedType: indexed |
|
246 |
private: private |
|
247 |
instanceVariableNames: instVars |
|
248 |
classInstanceVariableNames: classInstVars |
|
249 |
imports: imports |
|
250 |
category: category |
|
251 |
||
16035 | 252 |
"VW5i compatibility class/namespace creation" |
253 |
||
6450 | 254 |
^ self |
255 |
defineClass: name |
|
256 |
superclass: superclass |
|
257 |
indexedType: indexed |
|
258 |
private: private |
|
259 |
instanceVariableNames: instVars |
|
260 |
classInstanceVariableNames: classInstVars |
|
261 |
imports: imports |
|
262 |
category: category |
|
263 |
attributes: nil |
|
264 |
! |
|
265 |
||
266 |
defineClass: name |
|
7431 | 267 |
superclass: superclassOrName |
6450 | 268 |
indexedType: indexed |
269 |
private: private |
|
270 |
instanceVariableNames: instVars |
|
271 |
classInstanceVariableNames: classInstVars |
|
272 |
imports: imports |
|
273 |
category: category |
|
274 |
attributes: annotations |
|
275 |
||
276 |
"VW5i compatibility class/namespace creation" |
|
277 |
||
7431 | 278 |
|variable words pointers superclass| |
6450 | 279 |
|
280 |
variable := words := pointers := false. |
|
281 |
indexed ~~ #none ifTrue:[ |
|
12031
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
282 |
indexed == #objects ifTrue:[ |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
283 |
variable := pointers := true. |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
284 |
] ifFalse:[ |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
285 |
self shouldImplement. |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
286 |
] |
6450 | 287 |
]. |
7431 | 288 |
superclassOrName isSymbol ifTrue:[ |
289 |
superclass := Smalltalk at:superclassOrName. |
|
290 |
superclass isNil ifTrue:[ |
|
291 |
self error:'missing superclass: ' , superclassOrName. |
|
292 |
] |
|
293 |
] ifFalse:[ |
|
294 |
superclass := superclassOrName |
|
295 |
]. |
|
6450 | 296 |
^ superclass value class |
297 |
name:name |
|
6824
6fbe85d05646
...in:... -> ...inEnvironment:...
Claus Gittinger <cg@exept.de>
parents:
6450
diff
changeset
|
298 |
inEnvironment:self |
6450 | 299 |
subclassOf:superclass value |
300 |
instanceVariableNames:instVars |
|
301 |
variable:variable |
|
302 |
words:words |
|
303 |
pointers:pointers |
|
304 |
classVariableNames:'' |
|
305 |
poolDictionaries:'' |
|
306 |
category:category |
|
307 |
comment:nil |
|
308 |
changed:true |
|
309 |
classInstanceVariableNames:classInstVars |
|
12031
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
310 |
! |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
311 |
|
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
312 |
defineNameSpace:nameSymbol private:private imports:imports category:category |
16035 | 313 |
"VW5i compatibility class/namespace creation" |
314 |
||
12031
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
315 |
|newNameSpace| |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
316 |
|
12587
7084aa23890c
changed: #defineNameSpace:private:imports:category:
Stefan Vogel <sv@exept.de>
parents:
12031
diff
changeset
|
317 |
private ifTrue:[self shouldImplement]. "/ what to do ? |
7084aa23890c
changed: #defineNameSpace:private:imports:category:
Stefan Vogel <sv@exept.de>
parents:
12031
diff
changeset
|
318 |
imports withoutSeparators notEmpty ifTrue:[self shouldImplement]. "/ what to do ? |
12031
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
319 |
newNameSpace := NameSpace name:nameSymbol. |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
320 |
newNameSpace setCategory:category. |
1847af6f43c6
added: #defineNameSpace:private:imports:category:
Claus Gittinger <cg@exept.de>
parents:
11999
diff
changeset
|
321 |
^ newNameSpace |
6450 | 322 |
! ! |
323 |
||
5331 | 324 |
!NameSpace class methodsFor:'accessing'! |
1827 | 325 |
|
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
326 |
allClasses |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
327 |
|classes| |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
328 |
|
14416 | 329 |
classes := OrderedCollection new. |
5581 | 330 |
self allClassesDo:[:aClass | classes add:aClass]. |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
331 |
^ classes |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
332 |
|
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
333 |
"Modified: 20.12.1996 / 15:34:50 / cg" |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
334 |
! |
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
335 |
|
4372
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
336 |
allClassesWithAllPrivateClasses |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
337 |
|classes| |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
338 |
|
14416 | 339 |
classes := OrderedCollection new. |
5581 | 340 |
self allClassesDo:[:aClass | |
4372
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
341 |
classes add:aClass. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
342 |
aClass addAllPrivateClassesTo:classes. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
343 |
]. |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
344 |
^ classes |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
345 |
|
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
346 |
"Modified: 20.12.1996 / 15:34:50 / cg" |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
347 |
! |
eaba7e085030
added #allClassesWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
4068
diff
changeset
|
348 |
|
1827 | 349 |
at:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
350 |
"return a class from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
351 |
|
1828 | 352 |
^ self privateClassesAt:classNameSymbol |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
353 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
354 |
"Modified: 8.11.1996 / 21:39:41 / cg" |
1827 | 355 |
! |
356 |
||
357 |
at:classNameSymbol ifAbsent:exceptionBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
358 |
"return a class or an alternative |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
359 |
from the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
360 |
|
1827 | 361 |
|cls| |
362 |
||
1828 | 363 |
cls := self privateClassesAt:classNameSymbol. |
1827 | 364 |
cls isNil ifTrue:[ |
365 |
^ exceptionBlock value |
|
366 |
]. |
|
367 |
^ cls |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
368 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
369 |
"Modified: 8.11.1996 / 21:40:01 / cg" |
1827 | 370 |
! |
371 |
||
10587 | 372 |
at:aKey ifPresent:aBlock |
373 |
"try to retrieve the value stored at aKey. |
|
374 |
If there is nothing stored under this key, do nothing. |
|
375 |
Otherwise, evaluate aBlock, passing the retrieved value as argument." |
|
376 |
||
377 |
(self includesKey:aKey) ifTrue:[ |
|
378 |
^ aBlock value:(self at:aKey) |
|
379 |
]. |
|
380 |
^ nil |
|
381 |
||
382 |
"Modified: / 31-05-2007 / 17:50:46 / cg" |
|
383 |
! |
|
384 |
||
1827 | 385 |
at:classNameSymbol put:aClass |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
386 |
"add a class to the namespace defined by the receiver" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
387 |
|
1828 | 388 |
^ self privateClassesAt:classNameSymbol put:aClass |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
389 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
390 |
"Modified: 8.11.1996 / 21:40:12 / cg" |
2908 | 391 |
! |
392 |
||
393 |
classNamed:aString |
|
394 |
"return the class with name aString, or nil if absent. |
|
395 |
To get to the metaClass, append ' class' to the string." |
|
396 |
||
397 |
^ Smalltalk classNamed:(self name , '::' , aString) |
|
398 |
||
399 |
"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
|
400 |
! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
401 |
|
9267 | 402 |
classNames |
403 |
^ self allClasses collect:[:each | each nameWithoutPrefix] |
|
404 |
! |
|
405 |
||
13428 | 406 |
import: aNameSpace |
407 |
||
408 |
(aNameSpace isNameSpace or: [aNameSpace isProgrammingLanguage]) |
|
409 |
ifFalse:[self error: 'Not a namespace or prog. language']. |
|
410 |
||
411 |
(self imports includes: aNameSpace) ifFalse: |
|
412 |
[self setImports: (self imports copyWith: aNameSpace)] |
|
413 |
||
414 |
"Created: / 21-07-2010 / 15:16:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
415 |
"Modified: / 21-07-2010 / 17:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
416 |
! |
|
417 |
||
418 |
imports |
|
13818 | 419 |
Imports isNil ifTrue:[^#()]. |
13428 | 420 |
^Imports at: self ifAbsent:[#()]. |
421 |
||
422 |
"Created: / 19-05-2010 / 16:06:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
423 |
"Modified: / 21-07-2010 / 17:17:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13818 | 424 |
"Modified: / 18-11-2011 / 14:48:56 / cg" |
13428 | 425 |
! |
426 |
||
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
427 |
includesKey:aClassNameStringOrSymbol |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
428 |
"{ Pragma: +optSpace }" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
429 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
430 |
"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
|
431 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
432 |
|nmSym| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
433 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
434 |
nmSym := (self name , '::' , aClassNameStringOrSymbol) asSymbolIfInterned. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
435 |
nmSym isNil ifTrue:[^ false]. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
436 |
^ Smalltalk includesKey:nmSym. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
437 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
438 |
|
9546 | 439 |
! |
440 |
||
10372 | 441 |
loadedClassNamed:aString |
442 |
"return the class with name aString, or nil if absent. |
|
443 |
To get to the metaClass, append ' class' to the string. |
|
444 |
Do not autoload the owning class of a private class." |
|
445 |
||
446 |
^ Smalltalk loadedClassNamed:(self name , '::' , aString) |
|
447 |
||
448 |
"Created: 9.9.1997 / 03:33:56 / cg" |
|
449 |
! |
|
450 |
||
9546 | 451 |
package |
452 |
self isNameSpace ifTrue:[ |
|
453 |
^ nil "all nameSpaces are outside of any package" |
|
454 |
]. |
|
455 |
^ super package "the nameSpace class itself has a package" |
|
456 |
||
457 |
"Created: / 16-08-2006 / 18:48:29 / User" |
|
1827 | 458 |
! ! |
459 |
||
5331 | 460 |
!NameSpace class methodsFor:'enumerating'! |
1816 | 461 |
|
462 |
allBehaviorsDo:aBlock |
|
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
463 |
"enumerate all classes in this namespace" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
464 |
|
2492 | 465 |
Smalltalk allBehaviorsDo:[:aClass | |
4068
ba1b46d15e70
skip metaclasses when enumerating behaviors of a namespace
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
466 |
(aClass isBehavior and:[aClass isMeta not]) ifTrue:[ |
2583 | 467 |
aClass nameSpace == self ifTrue:[ |
468 |
aBlock value:aClass |
|
469 |
]. |
|
2492 | 470 |
] |
471 |
]. |
|
2583 | 472 |
|
4068
ba1b46d15e70
skip metaclasses when enumerating behaviors of a namespace
Claus Gittinger <cg@exept.de>
parents:
4058
diff
changeset
|
473 |
"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
|
474 |
! |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
475 |
|
5581 | 476 |
allClassesDo:aBlock |
477 |
"enumerate all classes in this namespace" |
|
478 |
||
479 |
Smalltalk allClassesDo:[:aClass | |
|
480 |
(aClass isBehavior and:[aClass isMeta not]) ifTrue:[ |
|
481 |
aClass nameSpace == self ifTrue:[ |
|
482 |
aBlock value:aClass |
|
483 |
]. |
|
484 |
] |
|
485 |
]. |
|
486 |
||
487 |
"Modified: / 18.3.1999 / 17:21:06 / cg" |
|
488 |
! |
|
489 |
||
13428 | 490 |
allClassesForWhich:filter |
491 |
"return a collection with all classes in the system, |
|
492 |
for which filter evaluates to true." |
|
493 |
||
494 |
|collectedClasses| |
|
495 |
||
496 |
collectedClasses := OrderedCollection new. |
|
497 |
self allClassesForWhich:filter do:[:cls | |
|
498 |
collectedClasses add:cls |
|
499 |
]. |
|
500 |
^ collectedClasses |
|
501 |
||
502 |
" |
|
503 |
Smalltalk |
|
504 |
allClassesForWhich:[:cls | cls name startsWith:'Po'] |
|
505 |
" |
|
506 |
||
507 |
"Created: / 10-08-2006 / 12:11:31 / cg" |
|
508 |
! |
|
509 |
||
510 |
allClassesForWhich:filter do:aBlock |
|
511 |
"evaluate the argument, aBlock for all classes in the system, for which filter evaluates to true." |
|
512 |
||
513 |
self allClassesDo:[:cls | |
|
514 |
(filter value:cls) ifTrue:[ aBlock value:cls ]. |
|
515 |
]. |
|
516 |
||
517 |
" |
|
518 |
Smalltalk |
|
519 |
allClassesForWhich:[:cls | cls name startsWith:'Po'] |
|
520 |
do:[:aClass | Transcript showCR:aClass name] |
|
521 |
" |
|
522 |
! |
|
523 |
||
11999 | 524 |
allMethodsDo:aBlock |
525 |
"enumerate all methods in this namespace's classes" |
|
526 |
||
527 |
self allClassesDo:[:eachClass | |
|
528 |
eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
529 |
aBlock value:mthd |
|
530 |
] |
|
531 |
]. |
|
532 |
! |
|
533 |
||
534 |
allMethodsWithSelectorDo:aBlock |
|
535 |
"enumerate all methods in the Smalltalk namespace's classes" |
|
536 |
||
537 |
self allClassesDo:[:eachClass | |
|
538 |
eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
539 |
aBlock value:mthd value:sel |
|
540 |
] |
|
541 |
]. |
|
542 |
! |
|
543 |
||
13173 | 544 |
keyAtValue:anObject |
545 |
"return the symbol under which anObject is stored - or nil" |
|
546 |
||
547 |
self keysDo:[:aKey | |
|
548 |
(self at:aKey) == anObject ifTrue:[^ aKey] |
|
549 |
]. |
|
550 |
^ nil |
|
551 |
||
552 |
"Smalltalk keyAtValue:Object" |
|
553 |
||
554 |
"Created: / 19-12-2010 / 14:35:49 / cg" |
|
555 |
! |
|
556 |
||
9289 | 557 |
keys |
558 |
"enumerate all class names in this namespace" |
|
559 |
||
560 |
|setOfKeys| |
|
561 |
||
562 |
setOfKeys := OrderedCollection new. |
|
563 |
self keysDo:[:eachKey |setOfKeys add:eachKey]. |
|
564 |
^ setOfKeys |
|
565 |
||
566 |
" |
|
567 |
Benchmarks keys |
|
568 |
" |
|
569 |
! |
|
570 |
||
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
571 |
keysDo:aBlock |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
572 |
"enumerate all class names in this namespace" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
573 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
574 |
|prefix prefixLen| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
575 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
576 |
prefix := self name , '::'. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
577 |
prefixLen := prefix size. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
578 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
579 |
Smalltalk keysAndValuesDo:[:aName :aClass | |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
580 |
|key| |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
581 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
582 |
(aName startsWith:prefix) ifTrue:[ |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
583 |
key := (aName copyFrom:prefixLen+1) asSymbol. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
584 |
aBlock value:key |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
585 |
] |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
586 |
]. |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
587 |
|
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
588 |
" |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
589 |
Benchmarks keysDo:[:k | Transcript showCR:k] |
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
590 |
" |
1816 | 591 |
! ! |
592 |
||
5331 | 593 |
!NameSpace class methodsFor:'fileOut'! |
1828 | 594 |
|
2058 | 595 |
fileOutDefinitionOn:aStream |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
596 |
"redefined to generate another definition message" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
597 |
|
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
598 |
self == NameSpace ifTrue:[ |
2058 | 599 |
super fileOutDefinitionOn:aStream |
1934 | 600 |
] ifFalse:[ |
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
601 |
aStream nextPutAll:('NameSpace name:' , self name storeString) |
1934 | 602 |
] |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
603 |
|
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
604 |
"Modified: 8.11.1996 / 21:39:03 / cg" |
2058 | 605 |
"Created: 4.1.1997 / 20:36:32 / cg" |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
606 |
! ! |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
607 |
|
5464 | 608 |
!NameSpace class methodsFor:'fileOut-xml'! |
609 |
||
610 |
fileOutXMLDefinitionOn:aStream |
|
611 |
"redefined to generate another definition message" |
|
612 |
||
613 |
self == NameSpace ifTrue:[ |
|
614 |
super fileOutXMLDefinitionOn:aStream |
|
615 |
] ifFalse:[ |
|
616 |
aStream nextPutLine:'<name-space>'. |
|
617 |
aStream nextPutLine:' <name>' , self name , '</name>'. |
|
618 |
aStream nextPutLine:' <environment>Smalltalk</environment>'. |
|
619 |
aStream nextPutLine:' <private>false</private>'. |
|
620 |
aStream nextPutLine:' <imports>Smalltalk.*</imports>'. |
|
621 |
aStream nextPutLine:' <category>none</category>'. |
|
622 |
aStream nextPutLine:'</name-space>'. |
|
623 |
] |
|
624 |
! ! |
|
625 |
||
4397
bfcf41484c1f
added keysDo: and includesKey: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
4372
diff
changeset
|
626 |
|
5331 | 627 |
!NameSpace class methodsFor:'printing & storing'! |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
628 |
|
14285
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
629 |
displayOn:aGCOrStream |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
630 |
"Compatibility |
21762 | 631 |
append a printed description on some stream (Dolphin, Squeak) |
14285
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
632 |
OR: |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
633 |
display the receiver in a graphicsContext at 0@0 (ST80). |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
634 |
This method allows for any object to be displayed in some view |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
635 |
(although the fallBack is to display its printString ...)" |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
636 |
|
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
637 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
638 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
639 |
aGCOrStream isStream ifFalse:[ |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
640 |
^ super displayOn:aGCOrStream. |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
641 |
]. |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
642 |
|
21762 | 643 |
"return a printed representation - here, a reminder is appended, |
1943
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
644 |
that this is not a regular class" |
0ec17e4627ae
better displayString & commentary
Claus Gittinger <cg@exept.de>
parents:
1934
diff
changeset
|
645 |
|
5328
319b8e3ee60e
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
646 |
self == NameSpace ifTrue:[ |
14285
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
647 |
super displayOn:aGCOrStream. |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
648 |
] ifFalse:[ |
21762 | 649 |
aGCOrStream |
14285
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
650 |
nextPutAll:self name; |
31f229c1f4d1
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14067
diff
changeset
|
651 |
nextPutAll:' (* NameSpace *)'. |
2007
57434c08d720
namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents:
1943
diff
changeset
|
652 |
]. |
21762 | 653 |
|
654 |
"Modified (comment): / 17-05-2017 / 16:49:12 / mawalch" |
|
1828 | 655 |
! ! |
656 |
||
13428 | 657 |
!NameSpace class methodsFor:'private'! |
658 |
||
659 |
setImports: anArrayOrNil |
|
660 |
||
661 |
"Sets namespace imports. Private entry, |
|
662 |
Use 'self import: theNamespace' instead" |
|
663 |
||
13818 | 664 |
Imports isNil ifTrue:[Imports := IdentityDictionary new]. |
665 |
Imports at: self put: (anArrayOrNil ? #()). |
|
13428 | 666 |
|
667 |
"Created: / 21-07-2010 / 15:29:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13818 | 668 |
"Modified: / 18-11-2011 / 14:49:10 / cg" |
13428 | 669 |
! ! |
670 |
||
5331 | 671 |
!NameSpace class methodsFor:'queries'! |
1816 | 672 |
|
9267 | 673 |
allNameSpaces |
2030 | 674 |
"return a list of all namespaces" |
675 |
||
9267 | 676 |
^ self allNameSpacesIn:Smalltalk |
6401 | 677 |
! |
678 |
||
9267 | 679 |
allNameSpacesIn:anEnvironment |
6401 | 680 |
"return a list of all namespaces" |
681 |
||
2030 | 682 |
|set| |
683 |
||
6401 | 684 |
set := IdentitySet with:anEnvironment. |
685 |
anEnvironment allClassesDo:[:aClass | |
|
10176 | 686 |
(aClass isRealNameSpace |
687 |
and:[aClass ~~ anEnvironment]) ifTrue:[ |
|
2030 | 688 |
set add:aClass |
689 |
] |
|
690 |
]. |
|
691 |
^ set |
|
10176 | 692 |
|
693 |
"Modified: / 10-11-2006 / 17:12:02 / cg" |
|
2055 | 694 |
! |
695 |
||
9267 | 696 |
allNamespaces |
697 |
"return a list of all namespaces" |
|
698 |
||
699 |
<resource: #obsolete> |
|
700 |
||
701 |
^ self allNameSpaces |
|
702 |
! |
|
703 |
||
704 |
allNamespacesIn:anEnvironment |
|
705 |
"return a list of all namespaces" |
|
706 |
||
707 |
<resource: #obsolete> |
|
708 |
||
709 |
^ self allNameSpacesIn:anEnvironment |
|
710 |
! |
|
711 |
||
9814 | 712 |
canHaveExtensions |
713 |
"return true, if this class allows extensions from other packages. |
|
20805 | 714 |
Private classes, namespaces and projectDefinitions don't allow this" |
9814 | 715 |
|
716 |
^ self == NameSpace |
|
717 |
||
718 |
" |
|
719 |
Smalltalk allClasses select:[:each | each canHaveExtensions not] |
|
720 |
" |
|
721 |
||
722 |
"Created: / 30-08-2006 / 15:28:39 / cg" |
|
723 |
! |
|
724 |
||
9267 | 725 |
hasNameSpaces |
726 |
"return true - if I support sub-namespaces" |
|
727 |
||
728 |
^ false |
|
729 |
! |
|
730 |
||
7317 | 731 |
hasNamespaces |
732 |
"return true - if I support sub-namespaces" |
|
733 |
||
9267 | 734 |
<resource: #obsolete> |
735 |
||
736 |
^ self hasNameSpaces |
|
7317 | 737 |
! |
738 |
||
5327
5e5602d156fa
#isNamespace renamed to #isNameSpace
Claus Gittinger <cg@exept.de>
parents:
5305
diff
changeset
|
739 |
isNameSpace |
9217 | 740 |
"return true, if the receiver is a nameSpace. |
10170 | 741 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
2055 | 742 |
|
9372 | 743 |
^ self ~~ NameSpace . |
10170 | 744 |
|
745 |
"Modified: / 10-11-2006 / 17:01:56 / cg" |
|
746 |
! |
|
747 |
||
748 |
isRealNameSpace |
|
749 |
"return true, if the receiver is a nameSpace, but not Smalltalk (which is also a class). |
|
750 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
|
751 |
||
752 |
^ self ~~ NameSpace . |
|
753 |
||
754 |
"Created: / 10-11-2006 / 17:01:52 / cg" |
|
4457 | 755 |
! |
756 |
||
5464 | 757 |
isTopLevelNameSpace |
758 |
^ (self name includes:$:) not |
|
759 |
! |
|
760 |
||
4457 | 761 |
isTopLevelNamespace |
5365 | 762 |
"obsolete - use isTopLevelNameSpace" |
4457 | 763 |
|
9267 | 764 |
<resource: #obsolete> |
7433 | 765 |
|
5365 | 766 |
^ (self name includes:$:) not |
1816 | 767 |
! ! |
768 |
||
5331 | 769 |
!NameSpace class methodsFor:'documentation'! |
1816 | 770 |
|
13428 | 771 |
version_CVS |
20805 | 772 |
^ '$Header$' |
12587
7084aa23890c
changed: #defineNameSpace:private:imports:category:
Stefan Vogel <sv@exept.de>
parents:
12031
diff
changeset
|
773 |
! |
7084aa23890c
changed: #defineNameSpace:private:imports:category:
Stefan Vogel <sv@exept.de>
parents:
12031
diff
changeset
|
774 |
|
13428 | 775 |
version_SVN |
16035 | 776 |
^ '$ Id: NameSpace.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
1816 | 777 |
! ! |
14671 | 778 |