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