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