author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 11 Jan 2016 22:45:14 +0000 | |
branch | jv |
changeset 19017 | 2bc24e4f3e8a |
parent 18201 | 667dba93cccc |
child 21024 | 8734987eb5c7 |
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 |
||
19017
2bc24e4f3e8a
Remove (obsolete) breakpoint from JavaPackage class>>fullName:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18201
diff
changeset
|
23 |
"{ NameSpace: Smalltalk }" |
2bc24e4f3e8a
Remove (obsolete) breakpoint from JavaPackage class>>fullName:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18201
diff
changeset
|
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 |
]. |
|
18201
667dba93cccc
Fix in JavaPackage: relax sanity check in JavaPackage>>fullName:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17055
diff
changeset
|
105 |
(thisNamespace ~~ JAVA and:[thisNamespace isJavaPackage not and:[(thisNamespace name startsWith: #'JAVA_') not]]) ifTrue:[ |
17052 | 106 |
self error:'name conflict: non-java package ' , aName , 'aleady exists'. |
107 |
]. |
|
108 |
] |
|
109 |
]. |
|
110 |
thisNamespace isNil ifTrue:[ |
|
19017
2bc24e4f3e8a
Remove (obsolete) breakpoint from JavaPackage class>>fullName:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18201
diff
changeset
|
111 |
thisNamespace := self name:key |
17052 | 112 |
]. |
113 |
] ifFalse:[ |
|
114 |
thisNamespace isNameSpace ifTrue:[ |
|
115 |
x := thisNamespace at:key. |
|
116 |
] ifFalse:[ |
|
117 |
thisNamespace isBehavior ifTrue:[ |
|
118 |
x := thisNamespace privateClassesAt:key. |
|
119 |
]. |
|
120 |
]. |
|
121 |
x isNil ifTrue:[ |
|
122 |
x := |
|
123 |
self subclass:key |
|
124 |
instanceVariableNames:'' |
|
125 |
classVariableNames:'' |
|
126 |
poolDictionaries:'' |
|
127 |
privateIn:thisNamespace. |
|
128 |
"/ nameSpaces are not in any package (yet) |
|
129 |
x setPackage:nil. |
|
130 |
]. |
|
131 |
thisNamespace := x. |
|
132 |
]. |
|
133 |
]. |
|
134 |
||
135 |
^ thisNamespace |
|
136 |
||
137 |
"Created: / 08-11-1996 / 13:41:59 / cg" |
|
138 |
"Modified: / 04-01-1997 / 16:50:59 / cg" |
|
19017
2bc24e4f3e8a
Remove (obsolete) breakpoint from JavaPackage class>>fullName:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18201
diff
changeset
|
139 |
"Modified: / 11-01-2016 / 22:43:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
17052 | 140 |
! |
141 |
||
142 |
name:aStringOrSymbol |
|
143 |
"create a new nameSpace, named aStringOrSymbol. |
|
144 |
Notice, that the nameSpace is created in the current one - |
|
145 |
dont get confused; we recommend, not to nest them too much." |
|
146 |
||
147 |
|currentNameSpace newNameSpace existing ok nameSym fullName| |
|
148 |
||
149 |
ok := aStringOrSymbol first isLetter. |
|
150 |
ok ifTrue:[ |
|
151 |
(aStringOrSymbol |
|
152 |
findFirst:[:ch | (ch isLetterOrDigit or:[ch == $_]) not] |
|
153 |
startingAt:2) ~~ 0 |
|
154 |
ifTrue:[ |
|
155 |
ok := false. |
|
156 |
] |
|
157 |
]. |
|
158 |
ok ifFalse:[ |
|
159 |
self error:'invalid namespace name:''' , aStringOrSymbol printString , ''' (must be a valid identifier)'. |
|
160 |
]. |
|
161 |
||
162 |
nameSym := aStringOrSymbol asSymbol. |
|
163 |
||
164 |
self == JavaPackage ifTrue:[ |
|
165 |
"/ currentNameSpace := Class nameSpaceQuerySignal query. |
|
166 |
currentNameSpace isNil ifTrue:[ |
|
167 |
currentNameSpace := Smalltalk |
|
168 |
]. |
|
169 |
fullName := nameSym |
|
170 |
] ifFalse:[ |
|
171 |
currentNameSpace := self. |
|
172 |
fullName := (self name , '::' , nameSym) asSymbol |
|
173 |
]. |
|
174 |
||
175 |
(existing := currentNameSpace at:nameSym) notNil ifTrue:[ |
|
176 |
^ existing |
|
177 |
]. |
|
178 |
newNameSpace := self |
|
179 |
subclass:fullName |
|
180 |
instanceVariableNames:'' |
|
181 |
classVariableNames:'' |
|
182 |
poolDictionaries:'' |
|
183 |
category:'uncategorized namespace' |
|
184 |
inEnvironment:Smalltalk. |
|
185 |
||
186 |
"/ nameSpaces are not in any package |
|
187 |
newNameSpace notNil ifTrue:[newNameSpace setPackage:nil]. |
|
188 |
^ newNameSpace |
|
189 |
||
190 |
" |
|
191 |
NameSpace name:'foo' |
|
192 |
(NameSpace name:'foo') category:'my name space' |
|
193 |
foo at:#bar put:(Metaclass new new) |
|
194 |
(NameSpace name:'foo') name:'bar' |
|
195 |
" |
|
196 |
" |
|
197 |
NameSpace name:'an-invalid++name' |
|
198 |
NameSpace name:'another:invalidName' |
|
199 |
NameSpace name:'another::invalidName' |
|
200 |
" |
|
201 |
||
202 |
"Modified: / 14-09-1997 / 09:46:59 / cg" |
|
203 |
"Modified: / 18-03-1999 / 18:24:13 / stefan" |
|
204 |
"Created: / 28-02-2012 / 19:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
205 |
! ! |
|
206 |
||
207 |
!JavaPackage class methodsFor:'accessing'! |
|
208 |
||
209 |
compiler |
|
210 |
^ self == JavaPackage ifTrue:[ |
|
211 |
super compiler |
|
212 |
] ifFalse:[ |
|
213 |
JavaPackage class basicNew setName: (self name , '::compiler') asSymbol |
|
214 |
]. |
|
215 |
||
216 |
"Created: / 24-09-2013 / 02:33:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
217 |
! |
|
218 |
||
219 |
source |
|
220 |
^ self == JavaPackage ifTrue:[ |
|
221 |
super source |
|
222 |
] ifFalse:[ |
|
223 |
JavaPackage class basicNew setName: (self name , '::source') asSymbol |
|
224 |
]. |
|
225 |
||
226 |
"Created: / 24-09-2013 / 02:34:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
227 |
! ! |
|
228 |
||
229 |
!JavaPackage class methodsFor:'error handling'! |
|
230 |
||
231 |
doesNotUnderstand: aMessage |
|
232 |
| sel classOrPackage | |
|
233 |
||
17055
9c4f269a8383
Fixes after moving to stx:libbasic
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17052
diff
changeset
|
234 |
Java isNil ifTrue:[ |
17052 | 235 |
"/ STX:LIBJAVA not loaded |
236 |
^ super doesNotUnderstand: aMessage |
|
237 |
]. |
|
238 |
||
239 |
sel := aMessage selector. |
|
240 |
classOrPackage := self at: sel ifAbsent:[ nil ]. |
|
241 |
classOrPackage isNil ifTrue:[ |
|
242 |
sel numArgs ~~ 0 ifTrue:[ |
|
243 |
super doesNotUnderstand: aMessage |
|
244 |
] ifFalse:[ |
|
245 |
sel first isLowercase ifTrue:[ |
|
246 |
classOrPackage := JavaPackage class basicNew setName: (self name , '::' , sel) asSymbol |
|
247 |
] ifFalse:[ |
|
248 |
| fullName | |
|
249 |
||
250 |
self == JAVA |
|
251 |
ifTrue:[ fullName := sel ] |
|
252 |
ifFalse:[ fullName := (((self name asCollectionOfSubstringsSeparatedByAll:'::') allButFirst asStringWith:$/) , '/' , sel). ]. |
|
253 |
"/ classOrPackage := JavaClassAccessor fullName: fullName |
|
254 |
classOrPackage := Java classForName: fullName. |
|
255 |
] |
|
256 |
] |
|
257 |
]. |
|
258 |
^ classOrPackage |
|
259 |
||
260 |
"Created: / 28-02-2012 / 20:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
261 |
"Modified (format): / 13-11-2014 / 16:53:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
262 |
! ! |
|
263 |
||
264 |
!JavaPackage class methodsFor:'fileOut'! |
|
265 |
||
266 |
fileOutDefinitionOn:aStream |
|
267 |
"redefined to generate another definition message" |
|
268 |
||
269 |
self == JavaPackage ifTrue:[ |
|
270 |
self basicFileOutDefinitionOn: aStream withNameSpace: false. |
|
271 |
] ifFalse:[ |
|
272 |
aStream nextPutAll:('JavaPackage name:' , self name storeString) |
|
273 |
]. |
|
274 |
||
275 |
"Created: / 24-03-2009 / 15:56:17 / karpij1 <karpij1@fel.cvut.cz>" |
|
276 |
"Modified: / 04-12-2011 / 12:19:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
277 |
! ! |
|
278 |
||
279 |
!JavaPackage class methodsFor:'printing & storing'! |
|
280 |
||
281 |
displayString |
|
282 |
"return a printed represenation - here, a reminder is appended, |
|
283 |
that this is not a regular class" |
|
284 |
||
285 |
self == JavaPackage ifTrue:[ |
|
286 |
^ self name |
|
287 |
]. |
|
288 |
self == JAVA ifTrue:[ |
|
289 |
^ 'JAVA /* Java package root */' |
|
290 |
]. |
|
291 |
^ self name , ' /* Java package */' |
|
292 |
||
293 |
"Created: / 08-11-1996 / 21:37:24 / cg" |
|
294 |
"Modified: / 20-12-1996 / 15:11:31 / cg" |
|
295 |
"Created: / 28-02-2012 / 19:07:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
296 |
! ! |
|
297 |
||
298 |
!JavaPackage class methodsFor:'queries'! |
|
299 |
||
300 |
isJavaPackage |
|
301 |
"Anser true, if receiver is a java package. My subclasses are java packages" |
|
302 |
||
303 |
^self ~~ JavaPackage |
|
304 |
and:[self name ~~ #JAVA |
|
305 |
and:[(self name includes: $:)]] |
|
306 |
||
307 |
"Created: / 04-12-2011 / 12:22:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
308 |
"Modified: / 02-09-2013 / 17:52:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
309 |
! |
|
310 |
||
311 |
isNameSpace |
|
312 |
"return true, if the receiver is a nameSpace. |
|
313 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
|
314 |
||
315 |
^ self ~~ JavaPackage . |
|
316 |
! |
|
317 |
||
318 |
isRealNameSpace |
|
319 |
"return true, if the receiver is a nameSpace, but not Smalltalk (which is also a class). |
|
320 |
Unconditionally true here for subclasses - my subclasses are namespaces" |
|
321 |
||
322 |
^ self ~~ JavaPackage . |
|
323 |
! ! |
|
324 |
||
325 |
!JavaPackage class methodsFor:'documentation'! |
|
326 |
||
327 |
version_HG |
|
328 |
||
329 |
^ '$Changeset: <not expanded> $' |
|
330 |
! |
|
331 |
||
332 |
version_SVN |
|
17055
9c4f269a8383
Fixes after moving to stx:libbasic
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17052
diff
changeset
|
333 |
^ '$Id: JavaPackage.st,v 1.2 2014-11-14 09:52:45 vrany Exp $' |
17052 | 334 |
! ! |
335 |
||
336 |
||
337 |
JavaPackage initialize! |