author | Claus Gittinger <cg@exept.de> |
Thu, 22 Jun 2017 06:59:44 +0200 | |
changeset 21897 | a91007fb361f |
parent 21780 | eb9a737f9e09 |
child 23285 | feb74d5ff0d5 |
permissions | -rw-r--r-- |
17052 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
||
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
16 |
[1] Code written at SWING Research Group contains a signature |
|
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libbasic' }" |
|
22 |
||
20802 | 23 |
"{ NameSpace: Smalltalk }" |
24 |
||
17052 | 25 |
NameSpace subclass:#JavaPackage |
26 |
instanceVariableNames:'' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'Languages-Java-Support' |
|
30 |
! |
|
31 |
||
32 |
!JavaPackage class methodsFor:'documentation'! |
|
33 |
||
34 |
copyright |
|
35 |
" |
|
36 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
37 |
||
38 |
New code and modifications done at SWING Research Group [1]: |
|
39 |
||
40 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
41 |
SWING Research Group, Czech Technical University in Prague |
|
42 |
||
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
||
50 |
[1] Code written at SWING Research Group contains a signature |
|
51 |
of one of the above copright owners. For exact set of such code, |
|
52 |
see the differences between this version and version stx:libjava |
|
53 |
as of 1.9.2010 |
|
54 |
||
55 |
" |
|
56 |
! ! |
|
57 |
||
58 |
!JavaPackage class methodsFor:'initialization'! |
|
59 |
||
60 |
initialize |
|
61 |
||
62 |
"Create JAVA namespace (for easy class access)" |
|
63 |
Class withoutUpdatingChangesDo:[ |
|
64 |
self name: #JAVA |
|
65 |
] |
|
66 |
||
67 |
"Created: / 28-02-2012 / 19:33:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
68 |
! ! |
|
69 |
||
70 |
!JavaPackage class methodsFor:'instance creation'! |
|
71 |
||
72 |
fullName:fullNameSpaceName |
|
73 |
"given a possibly nested name of a namespace, create all required |
|
74 |
intermediate spaces (if not already existing) and return the |
|
75 |
bottom-level space." |
|
76 |
||
77 |
"/ break it up, check for all intermediate spaces to exist |
|
78 |
"/ create them as required. |
|
79 |
||
80 |
|list thisNamespace| |
|
81 |
||
82 |
(fullNameSpaceName includes:$:) ifTrue:[ |
|
83 |
"/ old style |
|
84 |
list := fullNameSpaceName asCollectionOfSubstringsSeparatedByAll:'::'. |
|
85 |
] ifFalse:[ |
|
86 |
"/ new style |
|
87 |
list := fullNameSpaceName asCollectionOfSubstringsSeparatedBy:$.. |
|
88 |
]. |
|
89 |
||
90 |
"/ now, look and create 'em |
|
91 |
||
92 |
thisNamespace := nil. |
|
93 |
list do:[:aName | |
|
94 |
|key x| |
|
95 |
||
96 |
key := aName asSymbol. |
|
97 |
||
98 |
thisNamespace isNil ifTrue:[ |
|
99 |
(Smalltalk includesKey:key) ifTrue:[ |
|
100 |
thisNamespace := Smalltalk at:key. |
|
101 |
thisNamespace notNil ifTrue:[ |
|
102 |
thisNamespace isBehavior ifFalse:[ |
|
103 |
self error:'name conflict: java package ' , aName , ' vs. global with the same name'. |
|
104 |
]. |
|
17055
9c4f269a8383
Fixes after moving to stx:libbasic
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17052
diff
changeset
|
105 |
(thisNamespace ~~ JAVA and:[thisNamespace isJavaPackage not]) ifTrue:[ |
17052 | 106 |
self error:'name conflict: non-java package ' , aName , 'aleady exists'. |
107 |
]. |
|
108 |
] |
|
109 |
]. |
|
110 |
thisNamespace isNil ifTrue:[ |
|
111 |
key == #JAVA ifTrue:[ |
|
112 |
thisNamespace := self name: #JAVA. |
|
113 |
] ifFalse:[ |
|
114 |
self breakPoint: #jv. |
|
115 |
thisNamespace := self name:key |
|
116 |
]. |
|
117 |
]. |
|
118 |
] ifFalse:[ |
|
119 |
thisNamespace isNameSpace ifTrue:[ |
|
120 |
x := thisNamespace at:key. |
|
121 |
] ifFalse:[ |
|
122 |
thisNamespace isBehavior ifTrue:[ |
|
123 |
x := thisNamespace privateClassesAt:key. |
|
124 |
]. |
|
125 |
]. |
|
126 |
x isNil ifTrue:[ |
|
127 |
x := |
|
128 |
self subclass:key |
|
129 |
instanceVariableNames:'' |
|
130 |
classVariableNames:'' |
|
131 |
poolDictionaries:'' |
|
132 |
privateIn:thisNamespace. |
|
133 |
"/ nameSpaces are not in any package (yet) |
|
134 |
x setPackage:nil. |
|
135 |
]. |
|
136 |
thisNamespace := x. |
|
137 |
]. |
|
138 |
]. |
|
139 |
||
140 |
^ thisNamespace |
|
141 |
||
142 |
"Created: / 08-11-1996 / 13:41:59 / cg" |
|
143 |
"Modified: / 04-01-1997 / 16:50:59 / cg" |
|
144 |
"Modified: / 13-11-2014 / 16:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
145 |
! |
|
146 |
||
147 |
name:aStringOrSymbol |
|
148 |
"create a new nameSpace, named aStringOrSymbol. |
|
149 |
Notice, that the nameSpace is created in the current one - |
|
20802 | 150 |
don't get confused; we recommend, not to nest them too much." |
17052 | 151 |
|
152 |
|currentNameSpace newNameSpace existing ok nameSym fullName| |
|
153 |
||
154 |
ok := aStringOrSymbol first isLetter. |
|
155 |
ok ifTrue:[ |
|
156 |
(aStringOrSymbol |
|
157 |
findFirst:[:ch | (ch isLetterOrDigit or:[ch == $_]) not] |
|
158 |
startingAt:2) ~~ 0 |
|
159 |
ifTrue:[ |
|
160 |
ok := false. |
|
161 |
] |
|
162 |
]. |
|
163 |
ok ifFalse:[ |
|
164 |
self error:'invalid namespace name:''' , aStringOrSymbol printString , ''' (must be a valid identifier)'. |
|
165 |
]. |
|
166 |
||
167 |
nameSym := aStringOrSymbol asSymbol. |
|
168 |
||
169 |
self == JavaPackage ifTrue:[ |
|
170 |
"/ currentNameSpace := Class nameSpaceQuerySignal query. |
|
171 |
currentNameSpace isNil ifTrue:[ |
|
172 |
currentNameSpace := Smalltalk |
|
173 |
]. |
|
174 |
fullName := nameSym |
|
175 |
] ifFalse:[ |
|
176 |
currentNameSpace := self. |
|
177 |
fullName := (self name , '::' , nameSym) asSymbol |
|
178 |
]. |
|
179 |
||
180 |
(existing := currentNameSpace at:nameSym) notNil ifTrue:[ |
|
181 |
^ existing |
|
182 |
]. |
|
183 |
newNameSpace := self |
|
184 |
subclass:fullName |
|
185 |
instanceVariableNames:'' |
|
186 |
classVariableNames:'' |
|
187 |
poolDictionaries:'' |
|
188 |
category:'uncategorized namespace' |
|
189 |
inEnvironment:Smalltalk. |
|
190 |
||
191 |
"/ nameSpaces are not in any package |
|
192 |
newNameSpace notNil ifTrue:[newNameSpace setPackage:nil]. |
|
193 |
^ newNameSpace |
|
194 |
||
195 |
" |
|
196 |
NameSpace name:'foo' |
|
197 |
(NameSpace name:'foo') category:'my name space' |
|
198 |
foo at:#bar put:(Metaclass new new) |
|
199 |
(NameSpace name:'foo') name:'bar' |
|
200 |
" |
|
201 |
" |
|
202 |
NameSpace name:'an-invalid++name' |
|
203 |
NameSpace name:'another:invalidName' |
|
204 |
NameSpace name:'another::invalidName' |
|
205 |
" |
|
206 |
||
207 |
"Modified: / 14-09-1997 / 09:46:59 / cg" |
|
208 |
"Modified: / 18-03-1999 / 18:24:13 / stefan" |
|
209 |
"Created: / 28-02-2012 / 19:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
210 |
! ! |
|
211 |
||
212 |
!JavaPackage class methodsFor:'accessing'! |
|
213 |
||
21679 | 214 |
compilerClass |
17052 | 215 |
^ self == JavaPackage ifTrue:[ |
21679 | 216 |
super compilerClass |
17052 | 217 |
] ifFalse:[ |
218 |
JavaPackage class basicNew setName: (self name , '::compiler') asSymbol |
|
219 |
]. |
|
220 |
||
21679 | 221 |
"Created: / 31-03-2017 / 17:29:53 / stefan" |
17052 | 222 |
! |
223 |
||
224 |
source |
|
225 |
^ self == JavaPackage ifTrue:[ |
|
226 |
super source |
|
227 |
] ifFalse:[ |
|
228 |
JavaPackage class basicNew setName: (self name , '::source') asSymbol |
|
229 |
]. |
|
230 |
||
231 |
"Created: / 24-09-2013 / 02:34:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
232 |
! ! |
|
233 |
||
234 |
!JavaPackage class methodsFor:'error handling'! |
|
235 |
||
236 |
doesNotUnderstand: aMessage |
|
237 |
| sel classOrPackage | |
|
238 |
||
17055
9c4f269a8383
Fixes after moving to stx:libbasic
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17052
diff
changeset
|
239 |
Java isNil ifTrue:[ |
17052 | 240 |
"/ STX:LIBJAVA not loaded |
241 |
^ super doesNotUnderstand: aMessage |
|
242 |
]. |
|
243 |
||
244 |
sel := aMessage selector. |
|
245 |
classOrPackage := self at: sel ifAbsent:[ nil ]. |
|
246 |
classOrPackage isNil ifTrue:[ |
|
247 |
sel numArgs ~~ 0 ifTrue:[ |
|
248 |
super doesNotUnderstand: aMessage |
|
249 |
] ifFalse:[ |
|
21897 | 250 |
sel isLowercaseFirst ifTrue:[ |
17052 | 251 |
classOrPackage := JavaPackage class basicNew setName: (self name , '::' , sel) asSymbol |
252 |
] ifFalse:[ |
|
253 |
| fullName | |
|
254 |
||
255 |
self == JAVA |
|
256 |
ifTrue:[ fullName := sel ] |
|
257 |
ifFalse:[ fullName := (((self name asCollectionOfSubstringsSeparatedByAll:'::') allButFirst asStringWith:$/) , '/' , sel). ]. |
|
258 |
"/ classOrPackage := JavaClassAccessor fullName: fullName |
|
259 |
classOrPackage := Java classForName: fullName. |
|
260 |
] |
|
261 |
] |
|
262 |
]. |
|
263 |
^ classOrPackage |
|
264 |
||
265 |
"Created: / 28-02-2012 / 20:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
266 |
"Modified (format): / 13-11-2014 / 16:53:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
21897 | 267 |
"Modified: / 22-06-2017 / 06:57:02 / cg" |
17052 | 268 |
! ! |
269 |
||
270 |
!JavaPackage class methodsFor:'fileOut'! |
|
271 |
||
272 |
fileOutDefinitionOn:aStream |
|
273 |
"redefined to generate another definition message" |
|
274 |
||
275 |
self == JavaPackage ifTrue:[ |
|
276 |
self basicFileOutDefinitionOn: aStream withNameSpace: false. |
|
277 |
] ifFalse:[ |
|
278 |
aStream nextPutAll:('JavaPackage name:' , self name storeString) |
|
279 |
]. |
|
280 |
||
281 |
"Created: / 24-03-2009 / 15:56:17 / karpij1 <karpij1@fel.cvut.cz>" |
|
282 |
"Modified: / 04-12-2011 / 12:19:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
283 |
! ! |
|
284 |
||
285 |
!JavaPackage class methodsFor:'printing & storing'! |
|
286 |
||
287 |
displayString |
|
21761 | 288 |
"return a printed representation - here, a reminder is appended, |
17052 | 289 |
that this is not a regular class" |
290 |
||
291 |
self == JavaPackage ifTrue:[ |
|
292 |
^ self name |
|
293 |
]. |
|
294 |
self == JAVA ifTrue:[ |
|
295 |
^ 'JAVA /* Java package root */' |
|
296 |
]. |
|
297 |
^ self name , ' /* Java package */' |
|
298 |
||
299 |
"Created: / 08-11-1996 / 21:37:24 / cg" |
|
300 |
"Modified: / 20-12-1996 / 15:11:31 / cg" |
|
301 |
"Created: / 28-02-2012 / 19:07:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
21761 | 302 |
"Modified (comment): / 17-05-2017 / 16:49:25 / mawalch" |
17052 | 303 |
! ! |
304 |
||
305 |
!JavaPackage class methodsFor:'queries'! |
|
306 |
||
307 |
isJavaPackage |
|
21780 | 308 |
"Answer true if the receiver is a Java package. My subclasses are Java packages" |
17052 | 309 |
|
21780 | 310 |
^ self ~~ JavaPackage |
17052 | 311 |
and:[self name ~~ #JAVA |
312 |
and:[(self name includes: $:)]] |
|
313 |
||
314 |
"Created: / 04-12-2011 / 12:22:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
315 |
"Modified: / 02-09-2013 / 17:52:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
21780 | 316 |
"Modified (comment): / 30-05-2017 / 19:19:56 / mawalch" |
17052 | 317 |
! |
318 |
||
319 |
isNameSpace |
|
320 |
"return true, if the receiver is a nameSpace. |
|
321 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
|
322 |
||
323 |
^ self ~~ JavaPackage . |
|
324 |
! |
|
325 |
||
326 |
isRealNameSpace |
|
327 |
"return true, if the receiver is a nameSpace, but not Smalltalk (which is also a class). |
|
328 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
|
329 |
||
330 |
^ self ~~ JavaPackage . |
|
331 |
! ! |
|
332 |
||
333 |
!JavaPackage class methodsFor:'documentation'! |
|
334 |
||
20802 | 335 |
version |
336 |
^ '$Header$' |
|
337 |
! |
|
338 |
||
339 |
version_CVS |
|
340 |
^ '$Header$' |
|
341 |
! |
|
342 |
||
17052 | 343 |
version_HG |
344 |
||
345 |
^ '$Changeset: <not expanded> $' |
|
346 |
! |
|
347 |
||
348 |
version_SVN |
|
20802 | 349 |
^ '$Id$' |
17052 | 350 |
! ! |
351 |
||
352 |
||
353 |
JavaPackage initialize! |