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