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