author | Claus Gittinger <cg@exept.de> |
Thu, 24 Nov 2011 11:46:57 +0100 | |
changeset 2186 | f7b615cfd66c |
parent 2151 | c0b6570c6f9b |
child 2197 | 6c7576efbf16 |
permissions | -rw-r--r-- |
454 | 1 |
" |
2151 | 2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
4 |
SWING Research Group, Czech Technical University in Prague |
|
5 |
||
6 |
Parts of the code written by Claus Gittinger are under following |
|
7 |
license: |
|
454 | 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. |
|
2151 | 15 |
|
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
17 |
||
18 |
Permission is hereby granted, free of charge, to any person |
|
19 |
obtaining a copy of this software and associated documentation |
|
20 |
files (the 'Software'), to deal in the Software without |
|
21 |
restriction, including without limitation the rights to use, |
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
23 |
copies of the Software, and to permit persons to whom the |
|
24 |
Software is furnished to do so, subject to the following |
|
25 |
conditions: |
|
26 |
||
27 |
The above copyright notice and this permission notice shall be |
|
28 |
included in all copies or substantial portions of the Software. |
|
29 |
||
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
37 |
OTHER DEALINGS IN THE SOFTWARE. |
|
38 |
||
39 |
[1] Code written at SWING Research Group contain a signature |
|
40 |
of one of the above copright owners. |
|
2080 | 41 |
" |
674 | 42 |
"{ Package: 'stx:libjava' }" |
43 |
||
2118 | 44 |
JavaBehavior subclass:#JavaClass |
2143 | 45 |
instanceVariableNames:'classLoader fullName sourceFile binaryFilePath fields initValues |
2151 | 46 |
staticFields annotations protectionDomain signatureJ' |
2118 | 47 |
classVariableNames:'ArgumentConversionErrorSignal OrderOfClassInits' |
1 | 48 |
poolDictionaries:'' |
2107 | 49 |
category:'Languages-Java-Classes' |
1 | 50 |
! |
51 |
||
133 | 52 |
!JavaClass class methodsFor:'documentation'! |
53 |
||
454 | 54 |
copyright |
55 |
" |
|
2151 | 56 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
57 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
58 |
SWING Research Group, Czech Technical University in Prague |
|
59 |
||
60 |
Parts of the code written by Claus Gittinger are under following |
|
61 |
license: |
|
454 | 62 |
|
63 |
This software is furnished under a license and may be used |
|
64 |
only in accordance with the terms of that license and with the |
|
65 |
inclusion of the above copyright notice. This software may not |
|
66 |
be provided or otherwise made available to, or used by, any |
|
67 |
other person. No title to or ownership of the software is |
|
68 |
hereby transferred. |
|
2151 | 69 |
|
70 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
71 |
||
72 |
Permission is hereby granted, free of charge, to any person |
|
73 |
obtaining a copy of this software and associated documentation |
|
74 |
files (the 'Software'), to deal in the Software without |
|
75 |
restriction, including without limitation the rights to use, |
|
76 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
77 |
copies of the Software, and to permit persons to whom the |
|
78 |
Software is furnished to do so, subject to the following |
|
79 |
conditions: |
|
80 |
||
81 |
The above copyright notice and this permission notice shall be |
|
82 |
included in all copies or substantial portions of the Software. |
|
83 |
||
84 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
85 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
86 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
87 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
88 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
89 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
90 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
91 |
OTHER DEALINGS IN THE SOFTWARE. |
|
92 |
||
93 |
[1] Code written at SWING Research Group contain a signature |
|
94 |
of one of the above copright owners. |
|
95 |
||
2080 | 96 |
" |
454 | 97 |
! |
98 |
||
255 | 99 |
documentation |
100 |
" |
|
101 |
fields upTo-and-including accessFlags are known & used by the VM |
|
102 |
only add fields after those and keep their order intact. |
|
103 |
" |
|
104 |
! |
|
105 |
||
133 | 106 |
examples |
107 |
" |
|
108 |
(Java at:'java.util.Stack') new inspect |
|
109 |
(Java at:'java.util.Vector') new inspect |
|
110 |
" |
|
111 |
! ! |
|
1 | 112 |
|
130 | 113 |
!JavaClass class methodsFor:'instance creation'! |
1 | 114 |
|
7 | 115 |
fullName:aString |
90 | 116 |
self shouldNotImplement. |
117 |
^ self new flags:0; setFullName:aString |
|
7 | 118 |
|
119 |
! |
|
120 |
||
38 | 121 |
fullName:aString numStatic:nStatic |
590 | 122 |
|meta cls s ns nameComponents| |
38 | 123 |
|
130 | 124 |
"/ check for a JAVA nameSpace to exist |
125 |
JAVA isNil ifTrue:[ |
|
2143 | 126 |
NameSpace name:'JAVA' |
130 | 127 |
]. |
128 |
||
38 | 129 |
"create the metaclass first" |
130 |
||
40 | 131 |
meta := Metaclass new. |
132 |
meta setSuperclass:(self). |
|
130 | 133 |
meta instSize:(JavaClass instSize + nStatic). |
172 | 134 |
"/ meta setName:(aString , 'class') asSymbol. |
135 |
"/ meta setClassVariableString:''. |
|
252 | 136 |
meta flags:(meta flags bitOr:Behavior flagJavaClass). |
137 |
"/ meta setSuperclass:JavaObject class. |
|
38 | 138 |
|
139 |
"then let the new meta create the class" |
|
140 |
cls := meta new. |
|
141 |
cls setSuperclass:JavaObject. |
|
142 |
cls instSize:0. |
|
2151 | 143 |
cls setName:('JAVA::' , aString). |
38 | 144 |
cls flags:0. |
2151 | 145 |
|
590 | 146 |
cls setAccessFlags:0. |
40 | 147 |
"/ cls setClassVariableString:''. |
38 | 148 |
cls setInstanceVariableString:''. |
2143 | 149 |
cls setCategory:#java. |
590 | 150 |
cls setFullName:aString. |
40 | 151 |
|
590 | 152 |
"/ java classes do not really have a category; |
153 |
"/ simulate one by separating its name into individual components, |
|
154 |
"/ prepending 'java'" |
|
155 |
||
156 |
nameComponents := aString asCollectionOfSubstringsSeparatedBy:$/. |
|
157 |
nameComponents size > 1 ifTrue:[ |
|
2143 | 158 |
cls category:((nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1)) |
159 |
replaceAll:$/ with:$. ). |
|
590 | 160 |
]. |
161 |
||
162 |
nameComponents size > 1 ifTrue:[ |
|
2143 | 163 |
cls setPackage:((nameComponents copyWithoutLast:1) asStringWith:$/) asSymbol |
590 | 164 |
] ifFalse:[ |
2143 | 165 |
cls setPackage:aString asSymbol |
590 | 166 |
]. |
130 | 167 |
|
181 | 168 |
"/ break up the package and create nameSpaces |
169 |
"/ for each package component. |
|
170 |
"/ This allows java.foo.bar to be visible in ST/X |
|
171 |
"/ under the name JAVA::java::foo::bar |
|
172 |
||
173 |
ns := JAVA. |
|
174 |
||
590 | 175 |
nameComponents size > 1 ifTrue:[ |
2143 | 176 |
s := '' writeStream. |
177 |
s nextPutAll:'JAVA'. |
|
178 |
nameComponents from:1 to:(nameComponents size - 1) do:[:aPart | |
|
179 |
s nextPutAll:'::'. |
|
180 |
s nextPutAll:aPart |
|
181 |
]. |
|
182 |
Metaclass confirmationQuerySignal answer:false do:[ |
|
183 |
Class updateChangeFileQuerySignal answer:false do:[ |
|
184 |
ns := NameSpace fullName:(s contents). |
|
185 |
] |
|
186 |
] |
|
181 | 187 |
]. |
675 | 188 |
ns isNameSpace ifTrue:[ |
2143 | 189 |
ns at:nameComponents last asSymbol put:cls. |
197 | 190 |
]. |
181 | 191 |
|
192 |
"/ for ST/X browsing |
|
130 | 193 |
Smalltalk at:('JAVA::' , aString) asSymbol put:cls. |
194 |
||
38 | 195 |
^ cls |
196 |
||
2151 | 197 |
"Created: / 15-04-1996 / 15:52:55 / cg" |
198 |
"Modified: / 03-01-1998 / 22:32:25 / cg" |
|
199 |
"Modified: / 26-11-2010 / 19:00:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
38 | 200 |
! |
201 |
||
1 | 202 |
name:aString |
7 | 203 |
self shouldNotImplement |
1 | 204 |
|
205 |
"Created: 15.4.1996 / 15:52:55 / cg" |
|
206 |
! ! |
|
207 |
||
2151 | 208 |
!JavaClass class methodsFor:'class initialization'! |
209 |
||
210 |
initialize |
|
211 |
||
212 |
ArgumentConversionErrorSignal := Signal new notifierString:'argument conversion error'. |
|
213 |
||
214 |
"Created: / 20-10-2010 / 11:11:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
215 |
! ! |
|
216 |
||
229 | 217 |
!JavaClass class methodsFor:'method lookup'! |
218 |
||
423 | 219 |
canConvertArgsToJava:argArray asSpecifiedIn:argSigSpecArray |
220 |
"given a smalltalk argument array, return true, if these can be converted to java objects as appropriate." |
|
221 |
||
2118 | 222 |
argArray |
223 |
with:argSigSpecArray |
|
224 |
do:[:arg :type | |
|
225 |
self |
|
226 |
convertToJava:arg |
|
227 |
type:type |
|
228 |
ifFail:[:msg :default| ^ false]]. |
|
423 | 229 |
^ true |
230 |
||
231 |
"Created: / 5.11.1998 / 18:25:05 / cg" |
|
426 | 232 |
"Modified: / 6.11.1998 / 00:45:58 / cg" |
423 | 233 |
! |
234 |
||
426 | 235 |
convertArgsToJava:argArray asSpecifiedIn:argSigSpecArray numArgs:na |
236 |
"given a smalltalk argument array, convert to java objects as appropriate. |
|
237 |
Currently, only Strings and booleans are converted." |
|
238 |
||
239 |
|sigIndex newArgIndex newArgArray| |
|
240 |
||
241 |
sigIndex := newArgIndex := 1. |
|
242 |
||
243 |
newArgArray := Array new:na. |
|
244 |
argArray do:[:arg | |
|
2118 | 245 |
|type newArg| |
426 | 246 |
|
2118 | 247 |
type := argSigSpecArray at:sigIndex. |
248 |
sigIndex := sigIndex + 1. |
|
249 |
newArg := self convertToJava:arg type:type. |
|
250 |
newArgArray at:newArgIndex put:newArg. |
|
251 |
newArgIndex := newArgIndex + 1. |
|
252 |
(type == #long or:[type == #double]) ifTrue:[ |
|
253 |
newArgIndex > na ifTrue:[ |
|
254 |
self halt:'should not happen' |
|
255 |
]. |
|
256 |
newArgArray at:newArgIndex put:nil. |
|
257 |
newArgIndex := newArgIndex + 1. |
|
258 |
] |
|
426 | 259 |
]. |
260 |
||
261 |
^ newArgArray |
|
262 |
||
263 |
"Created: / 5.11.1998 / 18:30:57 / cg" |
|
264 |
"Modified: / 6.11.1998 / 00:45:00 / cg" |
|
265 |
! |
|
266 |
||
267 |
convertToJava:arg type:type |
|
423 | 268 |
"given a smalltalk argument, convert to a java object as appropriate." |
269 |
||
2118 | 270 |
^ self |
2151 | 271 |
convertToJava:arg |
272 |
type:type |
|
273 |
ifFail:[:msg :default | |
|
274 |
ArgumentConversionErrorSignal |
|
275 |
raiseWith:arg |
|
276 |
errorString:msg. |
|
277 |
default |
|
278 |
] |
|
279 |
||
280 |
"Created: / 06-11-1998 / 00:45:13 / cg" |
|
281 |
"Modified: / 20-10-2010 / 11:08:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
423 | 282 |
! |
283 |
||
426 | 284 |
convertToJava:arg type:type ifFail:failBlock |
423 | 285 |
"given a smalltalk argument, convert to a java object as appropriate. |
286 |
Currently, only a few types are converted." |
|
287 |
||
546 | 288 |
|expectedCls f failValue| |
426 | 289 |
|
423 | 290 |
type == #boolean ifTrue:[ |
2151 | 291 |
arg == true ifTrue:[ |
292 |
^ 1 |
|
293 |
]. |
|
294 |
arg == false ifTrue:[ |
|
295 |
^ 0 |
|
296 |
]. |
|
297 |
^ failBlock value:('cannot convert argument to ' , type) value:0 |
|
423 | 298 |
]. |
299 |
||
300 |
type == #int ifTrue:[ |
|
2151 | 301 |
arg isInteger ifTrue:[ |
302 |
(arg between: (16r8000000 * -1) and:16r7FFFFFFF) ifTrue:[ |
|
303 |
^ arg |
|
304 |
]. |
|
305 |
^ failBlock value:('integer range; cannot convert argument to ' , type) value:0. |
|
306 |
]. |
|
307 |
^ failBlock value:('cannot convert argument to ' , type) value:0 |
|
423 | 308 |
]. |
309 |
||
310 |
type == #long ifTrue:[ |
|
2151 | 311 |
arg isInteger ifTrue:[ |
312 |
(arg between:"(-1 * 16r800000000000000) -->"-576460752303423488 and:16r7FFFFFFFFFFFFFFF) ifTrue:[ |
|
313 |
^ arg |
|
314 |
]. |
|
315 |
^ failBlock value:('integer range; cannot convert argument to ' , type) value:0 |
|
316 |
]. |
|
317 |
^ failBlock value:('cannot convert argument to ' , type) value:0 |
|
423 | 318 |
]. |
319 |
||
320 |
(type == #float) ifTrue:[ |
|
2151 | 321 |
arg isLimitedPrecisionReal ifTrue:[ |
322 |
^ arg asShortFloat |
|
323 |
]. |
|
324 |
^ failBlock value:('cannot convert argument to ' , type) value:0.0. |
|
423 | 325 |
]. |
326 |
||
2104
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
327 |
(type = 'java.lang.Float') ifTrue:[ |
2151 | 328 |
arg isLimitedPrecisionReal ifTrue:[ |
329 |
f := (Java at:'java.lang.Float') new. |
|
330 |
f perform:#'<init>(F)V' with:(arg asShortFloat). |
|
433 | 331 |
self halt. |
2151 | 332 |
^ f. |
333 |
]. |
|
334 |
^ failBlock value:('cannot convert argument to ' , type) value:0.0. |
|
433 | 335 |
]. |
2104
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
336 |
(type = 'java.lang.Double') ifTrue:[ |
2151 | 337 |
arg isLimitedPrecisionReal ifTrue:[ |
338 |
f := (Java at:'java.lang.Double') new. |
|
339 |
f perform:#'<init>(D)V' with:(arg asFloat). |
|
433 | 340 |
self halt. |
2151 | 341 |
^ f. |
342 |
]. |
|
343 |
^ failBlock value:('cannot convert argument to ' , type) value:0.0. |
|
433 | 344 |
]. |
345 |
||
423 | 346 |
(type == #double) ifTrue:[ |
2151 | 347 |
arg isLimitedPrecisionReal ifTrue:[ |
348 |
^ arg asFloat |
|
349 |
]. |
|
350 |
^ failBlock value:('cannot convert argument to ' , type) value:0.0. |
|
423 | 351 |
]. |
352 |
||
353 |
(type == #char) ifTrue:[ |
|
2151 | 354 |
arg isCharacter ifTrue:[ |
355 |
^ arg asciiValue |
|
356 |
]. |
|
357 |
^ failBlock value:('cannot convert argument to ' , type) value:0 |
|
2118 | 358 |
]. |
423 | 359 |
|
360 |
(type = 'char[]') ifTrue:[ |
|
2151 | 361 |
arg isString ifTrue:[ |
362 |
^ arg |
|
363 |
]. |
|
364 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
2118 | 365 |
]. |
423 | 366 |
|
426 | 367 |
(type = 'int[]') ifTrue:[ |
2151 | 368 |
(arg isArray or:[arg isMemberOf:SignedIntegerArray]) ifTrue:[ |
369 |
^ arg |
|
370 |
]. |
|
371 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
2118 | 372 |
]. |
426 | 373 |
(type = 'long[]') ifTrue:[ |
2151 | 374 |
(arg isArray or:[arg isMemberOf:SignedIntegerArray]) ifTrue:[ |
375 |
^ arg |
|
376 |
]. |
|
377 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
2118 | 378 |
]. |
426 | 379 |
(type = 'float[]') ifTrue:[ |
2151 | 380 |
(arg isArray or:[arg isMemberOf:FloatArray]) ifTrue:[ |
381 |
^ arg |
|
382 |
]. |
|
383 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
2118 | 384 |
]. |
426 | 385 |
(type = 'double[]') ifTrue:[ |
2151 | 386 |
(arg isArray or:[arg isMemberOf:DoubleArray]) ifTrue:[ |
387 |
^ arg |
|
388 |
]. |
|
389 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
2118 | 390 |
]. |
426 | 391 |
|
392 |
(type endsWith:'[]') ifTrue:[ |
|
2151 | 393 |
(arg isArray or:[arg isNil]) ifTrue:[ |
394 |
^ arg |
|
395 |
]. |
|
396 |
^ failBlock value:('cannot convert argument to ' , type) value:'' |
|
426 | 397 |
]. |
398 |
||
2151 | 399 |
expectedCls := Java classForName:type. |
400 |
(arg isKindOf:expectedCls) ifTrue:[ |
|
401 |
"/ matches class and subclasses |
|
402 |
^ arg |
|
403 |
]. |
|
404 |
||
405 |
||
423 | 406 |
(type = 'java.lang.Object') ifTrue:[ |
2151 | 407 |
"/ matches any |
408 |
^ arg |
|
423 | 409 |
]. |
410 |
(type = 'java.lang.String') ifTrue:[ |
|
2151 | 411 |
arg isString ifTrue:[ |
412 |
^ Java as_String:arg |
|
413 |
]. |
|
414 |
failValue := '' |
|
2080 | 415 |
]. |
456 | 416 |
arg isNil ifTrue:[ |
2151 | 417 |
"/ matches any |
418 |
^ arg |
|
456 | 419 |
]. |
423 | 420 |
self halt. |
546 | 421 |
^ failBlock value:('cannot convert argument to ' , type) value:failValue |
423 | 422 |
|
2151 | 423 |
"Created: / 06-11-1998 / 00:46:19 / cg" |
424 |
"Modified: / 06-11-2001 / 13:28:29 / cg" |
|
425 |
"Modified: / 17-01-2011 / 10:08:04 / kursjan <kursjan@fit.cvut.cz>" |
|
426 |
"Modified: / 17-03-2011 / 14:09:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
423 | 427 |
! |
428 |
||
2118 | 429 |
convertToSmalltalk:jObj type:type |
426 | 430 |
"given a java return value, convert to a smalltalk object as appropriate. |
431 |
Currently, only a few types are converted." |
|
336 | 432 |
|
2151 | 433 |
"JV@2011-02-04" |
434 |
"Hack for primitive types" |
|
435 |
(JavaDescriptor baseTypesByTypeName keys includes: type) ifTrue:[^jObj]. |
|
436 |
"jObj is registered for the specified type?" |
|
437 |
||
438 |
" |
|
439 |
(JavaObjectDictionary new reflectionOf: jObj class name) = (Java classForName: type) ifTrue: [ |
|
440 |
^ jObj |
|
441 |
]. |
|
442 |
" |
|
443 |
||
426 | 444 |
type == #boolean ifTrue:[ |
2151 | 445 |
jObj == 0 ifTrue:[ |
446 |
^ false |
|
447 |
]. |
|
448 |
^ true |
|
426 | 449 |
]. |
450 |
||
451 |
type == #void ifTrue:[ |
|
2151 | 452 |
^ nil |
336 | 453 |
]. |
454 |
||
426 | 455 |
(type = 'java.lang.String') ifTrue:[ |
2151 | 456 |
^ Java as_ST_String:jObj |
426 | 457 |
]. |
336 | 458 |
|
433 | 459 |
"/ (type = 'java.lang.Float') ifTrue:[ |
460 |
"/ ^ jObj instVarNamed:'value' |
|
461 |
"/ ]. |
|
462 |
"/ (type = 'java.lang.Double') ifTrue:[ |
|
463 |
"/ ^ jObj instVarNamed:'value' |
|
464 |
"/ ]. |
|
465 |
||
426 | 466 |
(type == #char) ifTrue:[ |
2151 | 467 |
jObj isInteger ifTrue:[ |
468 |
^ Character value:jObj |
|
469 |
]. |
|
2118 | 470 |
]. |
426 | 471 |
|
472 |
^ jObj |
|
473 |
||
2151 | 474 |
"Created: / 06-11-1998 / 00:49:53 / cg" |
475 |
"Modified: / 11-11-1998 / 02:08:11 / cg" |
|
476 |
"Modified: / 17-01-2011 / 10:42:56 / kursjan <kursjan@fit.cvut.cz>" |
|
477 |
"Modified: / 08-04-2011 / 17:04:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
336 | 478 |
! |
479 |
||
236 | 480 |
lookupMethod:selector numArgs:nargs in:aClass static:staticMethod |
229 | 481 |
"lookup a method" |
482 |
||
483 |
|method cls sel| |
|
484 |
||
485 |
sel := selector. |
|
486 |
(sel includes:$:) ifTrue:[ |
|
2118 | 487 |
sel := sel copyTo:(sel indexOf:$:)-1 |
229 | 488 |
]. |
489 |
||
490 |
sel := sel asSymbolIfInterned. |
|
491 |
sel notNil ifTrue:[ |
|
2118 | 492 |
cls := aClass. |
229 | 493 |
|
2118 | 494 |
[cls notNil |
495 |
and:[cls ~~ JavaObject |
|
496 |
and:[cls ~~ JavaClass]]] whileTrue:[ |
|
497 |
cls methodDictionary keysAndValuesDo:[:jSel :m | |
|
498 |
|aMethod| |
|
499 |
||
500 |
aMethod := m. |
|
501 |
aMethod isWrapped ifTrue:[ |
|
502 |
aMethod := aMethod originalMethod |
|
503 |
]. |
|
456 | 504 |
|
2118 | 505 |
((jSel == sel) |
506 |
or:[aMethod name = sel |
|
507 |
or:[aMethod signatureNameWithoutReturnType = sel]]) |
|
508 |
ifTrue:[ |
|
509 |
aMethod numArgs == nargs ifTrue:[ |
|
510 |
staticMethod == (aMethod isStatic) ifTrue:[ |
|
511 |
^ m |
|
512 |
] |
|
513 |
] |
|
514 |
] |
|
515 |
]. |
|
229 | 516 |
|
2118 | 517 |
cls := cls superclass. |
518 |
]. |
|
229 | 519 |
]. |
375 | 520 |
"/ self halt. |
229 | 521 |
^ nil |
522 |
||
375 | 523 |
"Created: / 17.8.1997 / 18:25:47 / cg" |
456 | 524 |
"Modified: / 16.11.1998 / 16:46:48 / cg" |
415 | 525 |
! |
526 |
||
527 |
lookupMethods:selector numArgs:nargs in:aClass static:staticMethod |
|
528 |
"lookup methods matching a selector. |
|
529 |
This is a special entry for doesNotUnderstand redirection |
|
530 |
(the caller must select the one method which fits the argument(s) best." |
|
531 |
||
532 |
|methods cls sel| |
|
533 |
||
534 |
sel := selector. |
|
535 |
(sel includes:$:) ifTrue:[ |
|
2118 | 536 |
sel := sel copyTo:(sel indexOf:$:)-1 |
415 | 537 |
]. |
538 |
||
539 |
sel := sel asSymbolIfInterned. |
|
540 |
sel notNil ifTrue:[ |
|
2118 | 541 |
cls := aClass. |
415 | 542 |
|
2118 | 543 |
[cls notNil |
544 |
and:[cls ~~ JavaObject |
|
545 |
and:[cls ~~ JavaClass]]] whileTrue:[ |
|
546 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
547 |
((jSel == sel) |
|
548 |
or:[aMethod name = sel |
|
549 |
or:[aMethod signatureNameWithoutReturnType = sel]]) |
|
550 |
ifTrue:[ |
|
551 |
(nargs isNil |
|
552 |
or:[aMethod numArgs == nargs]) ifTrue:[ |
|
553 |
staticMethod == (aMethod isStatic) ifTrue:[ |
|
554 |
methods isNil ifTrue:[ |
|
555 |
methods := OrderedCollection new |
|
556 |
]. |
|
557 |
methods add:aMethod |
|
558 |
] |
|
559 |
] |
|
560 |
] |
|
561 |
]. |
|
415 | 562 |
|
2118 | 563 |
cls := cls superclass. |
564 |
]. |
|
415 | 565 |
]. |
566 |
^ methods ? #() |
|
567 |
||
568 |
"Created: / 4.11.1998 / 19:04:51 / cg" |
|
569 |
"Modified: / 4.11.1998 / 19:31:33 / cg" |
|
229 | 570 |
! ! |
571 |
||
130 | 572 |
!JavaClass class methodsFor:'signature parsing'! |
52 | 573 |
|
574 |
initialValueFromSignature:aSignature |
|
575 |
"given a signature, return an initializer value" |
|
576 |
||
577 |
|s| |
|
578 |
||
579 |
s := aSignature readStream. |
|
580 |
^ self initialValueFromStream:s. |
|
581 |
||
582 |
" |
|
2118 | 583 |
JavaClass initialValueFromSignature:'LObject;' |
584 |
JavaClass initialValueFromSignature:'B' |
|
585 |
JavaClass initialValueFromSignature:'I' |
|
52 | 586 |
" |
587 |
||
588 |
||
589 |
! ! |
|
590 |
||
130 | 591 |
!JavaClass class methodsFor:'special'! |
40 | 592 |
|
2151 | 593 |
deinitClasses |
594 |
||
595 |
Smalltalk allClassesDo: |
|
596 |
[:cls|cls isJavaClass ifTrue:[cls deinit]]. |
|
597 |
self flushClassesInitOrder. |
|
598 |
||
599 |
" |
|
600 |
JavaClass deinitClasses |
|
601 |
" |
|
602 |
||
603 |
"Created: / 25-10-2010 / 16:47:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
604 |
! |
|
605 |
||
2104
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
606 |
flushClassesInitOrder |
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
607 |
OrderOfClassInits := nil |
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
608 |
|
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
609 |
"Created: / 6.11.2001 / 09:49:49 / cg" |
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
610 |
! |
1b6366474dbf
isReal -> isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
2102
diff
changeset
|
611 |
|
435 | 612 |
orderOfClassInits |
613 |
^ OrderOfClassInits |
|
614 |
||
615 |
"Created: / 12.11.1998 / 15:35:57 / cg" |
|
616 |
! |
|
617 |
||
40 | 618 |
setInstanceVariableStringFromFields:f in:aClass |
619 |
|varNames| |
|
620 |
||
621 |
varNames := ''. |
|
622 |
f do:[:aField | |
|
172 | 623 |
varNames := varNames , aField name , ' ' |
40 | 624 |
]. |
625 |
aClass setInstanceVariableString:varNames. |
|
626 |
||
627 |
"Created: 15.4.1996 / 16:42:52 / cg" |
|
435 | 628 |
! |
629 |
||
630 |
startRememberingOrderOfClassInits |
|
631 |
OrderOfClassInits := OrderedCollection new. |
|
632 |
||
633 |
"Created: / 12.11.1998 / 15:26:32 / cg" |
|
634 |
"Modified: / 12.11.1998 / 15:29:10 / cg" |
|
40 | 635 |
! ! |
636 |
||
5 | 637 |
!JavaClass methodsFor:'accessing'! |
638 |
||
2151 | 639 |
allInterfaces |
640 |
||
641 |
| ifaces cls | |
|
642 |
||
643 |
ifaces := Set new. |
|
644 |
cls := self. |
|
645 |
[ cls isJavaClass ] whileTrue: |
|
646 |
[cls interfaces do:[:iface| ifaces add: iface; addAll: iface allInterfaces]. |
|
647 |
cls := cls superclass]. |
|
648 |
^ifaces. |
|
649 |
||
650 |
"Created: / 05-02-2011 / 23:51:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
651 |
! |
|
652 |
||
653 |
annotations |
|
654 |
^ annotations ifNil:[JavaClassAnnotationContainer empty]. |
|
655 |
||
656 |
"Modified: / 03-03-2011 / 22:52:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
657 |
! |
|
658 |
||
659 |
annotations:something |
|
660 |
annotations := something. |
|
661 |
! |
|
662 |
||
74 | 663 |
binaryFile |
664 |
^ binaryFilePath |
|
665 |
! |
|
666 |
||
7 | 667 |
category |
590 | 668 |
"java classes do not really have a category; |
7 | 669 |
simulate one by separating its name into individual components, |
670 |
prepending 'java'" |
|
671 |
||
672 |
|nameComponents| |
|
673 |
||
674 |
nameComponents := fullName asCollectionOfSubstringsSeparatedBy:$/. |
|
160 | 675 |
nameComponents size <= 1 ifTrue:[ |
2118 | 676 |
^ 'java' "/ fullName |
160 | 677 |
]. |
2118 | 678 |
^ ((nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1))) |
679 |
replaceAll:$/ with:$. |
|
160 | 680 |
|
175 | 681 |
"Modified: 30.7.1997 / 15:35:22 / cg" |
7 | 682 |
! |
683 |
||
255 | 684 |
classLoader |
685 |
^ classLoader |
|
686 |
! |
|
687 |
||
688 |
classLoader:aJavaClassLoaderOrNil |
|
689 |
classLoader := aJavaClassLoaderOrNil |
|
690 |
! |
|
691 |
||
651 | 692 |
compiledMethodAt:name |
693 |
"redefined to find the constructor" |
|
694 |
||
695 |
|m| |
|
696 |
||
697 |
m := super compiledMethodAt:name. |
|
698 |
m isNil ifTrue:[ |
|
2118 | 699 |
name = self lastName ifTrue:[ |
700 |
^ super compiledMethodAt:#'<init>()V' |
|
701 |
]. |
|
651 | 702 |
]. |
703 |
^ m |
|
704 |
||
705 |
" |
|
706 |
JAVA::java::lang::Object compiledMethodAt:#Object |
|
707 |
" |
|
708 |
||
709 |
"Created: / 24.12.1999 / 02:02:50 / cg" |
|
710 |
"Modified: / 24.12.1999 / 02:04:46 / cg" |
|
711 |
! |
|
712 |
||
185 | 713 |
compiledMethodAt:name signature:sig |
714 |
"lookup the classes methodDictionary" |
|
715 |
||
716 |
methodDictionary keysAndValuesDo:[:mFullSelector :aMethod | |
|
252 | 717 |
aMethod name == name ifTrue:[ |
718 |
aMethod signature == sig ifTrue:[ |
|
719 |
^ aMethod |
|
720 |
] |
|
721 |
] |
|
185 | 722 |
]. |
723 |
^ nil |
|
724 |
||
725 |
"Created: 1.8.1997 / 00:01:58 / cg" |
|
726 |
! |
|
727 |
||
5 | 728 |
constantPool |
729 |
^ constantPool |
|
7 | 730 |
! |
731 |
||
2151 | 732 |
ensureHasAnnotations |
733 |
annotations ifNil: [ annotations := JavaAnnotationContainer for: self ]. |
|
734 |
^ annotations |
|
735 |
||
736 |
"Created: / 25-02-2011 / 16:02:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
737 |
"Modified: / 16-03-2011 / 17:13:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
738 |
! |
|
739 |
||
83 | 740 |
fields |
741 |
^ fields |
|
742 |
! |
|
743 |
||
7 | 744 |
fullName |
745 |
^ fullName |
|
8 | 746 |
! |
747 |
||
110 | 748 |
interfaces |
2151 | 749 |
interfaces notNil |
750 |
ifTrue: |
|
751 |
[ interfaces := interfaces collect: |
|
752 |
[:clsRef | clsRef javaClass ] ]. |
|
753 |
||
754 |
^ interfaces ? #() |
|
755 |
||
756 |
"Modified: / 31-05-2011 / 09:40:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
110 | 757 |
! |
758 |
||
90 | 759 |
javaClass |
2151 | 760 |
|
90 | 761 |
^ self |
2151 | 762 |
|
763 |
"Modified: / 22-05-2011 / 13:32:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
764 |
! |
|
765 |
||
766 |
javaComponentClass |
|
767 |
^self. |
|
768 |
||
769 |
"Created: / 20-12-2010 / 22:02:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
770 |
"Modified: / 30-05-2011 / 23:26:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
691 | 771 |
! |
772 |
||
2085 | 773 |
javaName |
774 |
"the javaname - as seen by a java programmer. |
|
775 |
(with '/'s replaced by dots) extract from the fullName" |
|
776 |
||
777 |
^ fullName copyReplaceAll:$/ with:$. |
|
778 |
||
779 |
" |
|
2118 | 780 |
Java allClasses first fullName |
781 |
Java allClasses first name |
|
782 |
Java allClasses first javaName |
|
783 |
Java allClasses first javaPackage |
|
784 |
Java allClasses first package |
|
2085 | 785 |
" |
786 |
! |
|
787 |
||
684 | 788 |
javaPackage |
789 |
"the javaPackage - as seen by a java programmer. |
|
790 |
(with '/'s replaced by dots) extract from the fullName" |
|
791 |
||
792 |
|components| |
|
793 |
||
794 |
components := fullName asCollectionOfSubstringsSeparatedBy:$/. |
|
795 |
components size > 1 ifTrue:[ |
|
2118 | 796 |
^ (components copyWithoutLast:1) asStringWith:$. |
684 | 797 |
]. |
798 |
^ fullName |
|
799 |
||
800 |
" |
|
2118 | 801 |
Java allClasses first fullName |
802 |
Java allClasses first javaPackage |
|
803 |
Java allClasses first package |
|
684 | 804 |
" |
805 |
! |
|
806 |
||
2151 | 807 |
javaPackageAsDirname |
808 |
"the javaPackage - as directory in class path" |
|
809 |
||
810 |
|components| |
|
811 |
||
812 |
components := fullName asCollectionOfSubstringsSeparatedBy:$/. |
|
813 |
components size > 1 ifTrue:[ |
|
814 |
^ (components copyWithoutLast:1) asStringWith: Filename separator |
|
815 |
]. |
|
816 |
^ fullName |
|
817 |
||
818 |
" |
|
819 |
Java allClasses first fullName |
|
820 |
Java allClasses first javaPackage |
|
821 |
Java allClasses first package |
|
822 |
" |
|
823 |
||
824 |
"Created: / 30-11-2010 / 12:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
825 |
! |
|
826 |
||
423 | 827 |
lastName |
828 |
^ fullName copyFrom:(fullName lastIndexOf:$/)+1 |
|
829 |
||
830 |
"Created: / 5.11.1998 / 19:16:00 / cg" |
|
831 |
! |
|
832 |
||
8 | 833 |
name |
27 | 834 |
^ name "/ fullName |
22 | 835 |
! |
836 |
||
130 | 837 |
nameSpace |
838 |
^ JAVA |
|
839 |
||
840 |
"Created: 20.1.1997 / 13:04:30 / cg" |
|
841 |
! |
|
842 |
||
843 |
nameWithoutNameSpacePrefix |
|
844 |
^ fullName |
|
845 |
||
846 |
"Created: 20.1.1997 / 13:05:30 / cg" |
|
847 |
! |
|
848 |
||
849 |
nameWithoutPrefix |
|
850 |
^ fullName |
|
851 |
||
852 |
"Created: 20.1.1997 / 13:06:06 / cg" |
|
853 |
! |
|
854 |
||
22 | 855 |
package |
684 | 856 |
"the package (as seen by a smalltalk programmer) |
857 |
extract from the fullName, (with '/'s) and prepend 'java:'" |
|
22 | 858 |
|
686 | 859 |
|components p i| |
860 |
||
861 |
i := fullName lastIndexOf:$/. |
|
862 |
p := fullName copyTo:i - 1. |
|
2083 | 863 |
p size == 0 ifTrue:[ |
2118 | 864 |
^ 'java' |
2083 | 865 |
]. |
686 | 866 |
"/ components := fullName asCollectionOfSubstringsSeparatedBy:$/. |
867 |
"/ components size > 1 ifTrue:[ |
|
868 |
"/ p := (components copyWithoutLast:1) asStringWith:$/ |
|
869 |
"/ ] ifFalse:[ |
|
870 |
"/ p := fullName |
|
871 |
"/ ]. |
|
872 |
||
684 | 873 |
^ 'java:' , p |
22 | 874 |
|
875 |
" |
|
2118 | 876 |
Java allClasses first fullName |
877 |
Java allClasses first package |
|
878 |
Java allClasses first javaPackage |
|
22 | 879 |
" |
24 | 880 |
! |
881 |
||
2151 | 882 |
protectionDomain |
883 |
^ protectionDomain |
|
884 |
! |
|
885 |
||
886 |
protectionDomain:something |
|
887 |
protectionDomain := something. |
|
888 |
! |
|
889 |
||
890 |
runtimeVisibleAnnotationsAsBytesOrNil |
|
891 |
annotations ifNil:[ ^ nil ]. |
|
892 |
annotations runtimeVisible ifNil:[ ^ nil ]. |
|
893 |
^ annotations runtimeVisible bytes |
|
894 |
||
895 |
"Created: / 25-02-2011 / 16:48:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
896 |
! |
|
897 |
||
898 |
setSignature: aSymbol |
|
899 |
||
900 |
signatureJ := aSymbol |
|
901 |
||
902 |
"Created: / 13-08-2011 / 00:30:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
903 |
! |
|
904 |
||
905 |
signatureJ |
|
906 |
||
907 |
"stupid naming, but superclass defines signature too" |
|
908 |
||
909 |
^signatureJ |
|
910 |
||
911 |
"Created: / 13-08-2011 / 00:30:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
912 |
! |
|
913 |
||
76 | 914 |
source |
915 |
^ Java classSourceOf:self |
|
916 |
||
917 |
" |
|
918 |
(Java at:'java.awt.Frame') source |
|
175 | 919 |
(Java at:'ArcTest') source |
920 |
(Java at:'ArcCanvas') source |
|
76 | 921 |
" |
175 | 922 |
|
923 |
"Modified: 30.7.1997 / 14:31:01 / cg" |
|
76 | 924 |
! |
925 |
||
24 | 926 |
sourceFile |
927 |
^ sourceFile |
|
83 | 928 |
! |
929 |
||
930 |
staticFields |
|
931 |
^ staticFields |
|
132 | 932 |
! |
933 |
||
2151 | 934 |
superinterface |
935 |
||
936 |
| ifaces | |
|
937 |
||
938 |
self assert: self isInterface message: 'Type must be an interface'. |
|
939 |
(ifaces := self interfaces) size == 0 ifTrue:[^nil]. |
|
940 |
ifaces size = 1 ifTrue:[^ifaces first]. |
|
941 |
||
942 |
self error: 'Should not happen!!'. |
|
943 |
^nil |
|
944 |
||
945 |
"Created: / 04-02-2011 / 12:35:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
946 |
! |
|
947 |
||
132 | 948 |
typeOfField:aFieldName |
949 |
||
950 |
fields do:[:aField | |
|
172 | 951 |
aField name = aFieldName ifTrue:[ |
952 |
^ aField type |
|
953 |
] |
|
132 | 954 |
]. |
955 |
self error:'no such field' |
|
956 |
||
957 |
" |
|
2118 | 958 |
(JAVA at:#'java/awt/image/ColorModel') typeOfField:'pixel_bits' |
132 | 959 |
" |
960 |
||
961 |
"Modified: 21.1.1997 / 22:48:28 / cg" |
|
5 | 962 |
! ! |
963 |
||
213 | 964 |
!JavaClass methodsFor:'adding / removing'! |
965 |
||
966 |
removeFromSystem |
|
967 |
Java removeClass:self |
|
968 |
||
969 |
"Created: 12.8.1997 / 02:46:51 / cg" |
|
970 |
! ! |
|
971 |
||
2151 | 972 |
!JavaClass methodsFor:'autoboxing'! |
973 |
||
974 |
javaBox:anObject |
|
975 |
^ anObject |
|
976 |
||
977 |
"Created: / 14-08-2011 / 22:58:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
978 |
! ! |
|
979 |
||
261 | 980 |
!JavaClass methodsFor:'browser interface'! |
981 |
||
982 |
isVisualStartable |
|
983 |
"return true, if this is an application class, |
|
984 |
which can be started via #open" |
|
985 |
||
2118 | 986 |
"/ if I have a main() method, I am |
413 | 987 |
|
988 |
(self compiledMethodAt:#'main([Ljava/lang/String;)V') notNil ifTrue:[ |
|
2118 | 989 |
^ true |
413 | 990 |
]. |
261 | 991 |
|
2087 | 992 |
(self isSubclassOf:(Java at:'java.applet.Applet')) ifTrue:[ |
2118 | 993 |
^ true. |
2087 | 994 |
]. |
413 | 995 |
|
996 |
^ false |
|
261 | 997 |
! |
998 |
||
999 |
open |
|
1000 |
"start a thread for my main method" |
|
1001 |
||
413 | 1002 |
"/ if I have a main, call it ... |
1003 |
||
1004 |
(self compiledMethodAt:#'main([Ljava/lang/String;)V') notNil ifTrue:[ |
|
2118 | 1005 |
^ self startMain |
413 | 1006 |
]. |
1007 |
||
1008 |
"/ otherwise, create a frame and wrap me; |
|
1009 |
"/ as in: |
|
1010 |
||
1011 |
"/ public static void main(String args[]) { |
|
1012 |
"/ Frame f = new Frame("myName"); |
|
1013 |
"/ mySelf me = new mySelf(); |
|
1014 |
"/ |
|
1015 |
"/ me.init(); |
|
1016 |
"/ me.start(); |
|
1017 |
"/ |
|
1018 |
"/ f.add("Center", me); |
|
1019 |
"/ f.setSize(300, 300); |
|
1020 |
"/ f.show(); |
|
1021 |
"/ } |
|
1022 |
||
1023 |
^ self startApplet |
|
261 | 1024 |
|
1025 |
"Created: / 15.1.1998 / 17:18:30 / cg" |
|
413 | 1026 |
"Modified: / 3.11.1998 / 22:51:47 / cg" |
261 | 1027 |
! ! |
1028 |
||
183 | 1029 |
!JavaClass methodsFor:'compiler interface'! |
1030 |
||
566 | 1031 |
browserClass |
2118 | 1032 |
"return the browser to use for this class - |
566 | 1033 |
this can be redefined in special classes, to get different browsers" |
1034 |
||
679 | 1035 |
"/ ^ JavaBrowser |
1036 |
^ super browserClass. |
|
566 | 1037 |
|
1038 |
"Modified: / 14.10.1998 / 15:28:38 / cg" |
|
183 | 1039 |
! ! |
1040 |
||
624 | 1041 |
!JavaClass methodsFor:'compiling'! |
1042 |
||
1043 |
recompileMethodsAccessingGlobal:aGlobalKey |
|
1044 |
"/ dummy for now |
|
1045 |
||
1046 |
"Created: / 9.11.1999 / 16:42:09 / cg" |
|
1047 |
! ! |
|
1048 |
||
160 | 1049 |
!JavaClass methodsFor:'documentation support'! |
1050 |
||
626 | 1051 |
htmlDocumentation |
1052 |
^ nil "/ replace by access to javadoc-generated documentation later |
|
160 | 1053 |
|
626 | 1054 |
"Modified: 22.3.1997 / 14:18:50 / cg" |
160 | 1055 |
! ! |
1056 |
||
312 | 1057 |
!JavaClass methodsFor:'executing programs'! |
1058 |
||
626 | 1059 |
startApplet |
2087 | 1060 |
|f me stub top appFrame| |
1061 |
||
1062 |
top := StandardSystemView new. |
|
1063 |
appFrame := JavaEmbeddedFrameView new. |
|
1064 |
appFrame origin:0.0@0.0 corner:1.0@1.0. |
|
1065 |
top addSubView:appFrame. |
|
1066 |
||
1067 |
appFrame appletIsPreloaded:true. |
|
1068 |
appFrame codeURL:'file:/dummy'. |
|
1069 |
appFrame codeBaseURL:'file:/dummy'. |
|
1070 |
appFrame autoSetupApplet:true. |
|
1071 |
appFrame autoStartApplet:true. |
|
1072 |
appFrame autoDestroyApplet:true. |
|
1073 |
||
1074 |
||
1075 |
top open. |
|
1076 |
^ self. |
|
1077 |
||
1078 |
"/ TODO: setup embeddedAppletFrame correctly |
|
1079 |
"/ (for getParameter to work ...) |
|
1080 |
||
1081 |
"/ create a frame and wrap me; |
|
1082 |
"/ as in: |
|
693 | 1083 |
|
2087 | 1084 |
"/ public static void main(String args[]) { |
1085 |
"/ Frame f = new Frame("myName"); |
|
1086 |
"/ mySelf me = new mySelf(); |
|
1087 |
"/ |
|
1088 |
"/ me.init(); |
|
1089 |
"/ me.start(); |
|
1090 |
"/ |
|
1091 |
"/ f.add("Center", me); |
|
1092 |
"/ f.setSize(300, 300); |
|
1093 |
"/ f.show(); |
|
1094 |
"/ } |
|
1095 |
f := (Java at:'java.awt.Frame') basicNew. |
|
1096 |
f perform:#'<init>(Ljava/lang/String;)V' with:(Java as_String:self name). |
|
1097 |
self halt. |
|
1098 |
me := self basicNew. |
|
1099 |
me perform:#'<init>()V'. |
|
1100 |
self halt. |
|
1101 |
||
1102 |
stub := (Java at:'netscape.applet.EmbeddedAppletFrame') new. |
|
1103 |
me instVarNamed:'stub' put:stub. |
|
1104 |
self halt. |
|
1105 |
||
1106 |
me perform:#'init()V'. |
|
1107 |
me perform:#'start()V'. |
|
1108 |
self halt. |
|
1109 |
||
2118 | 1110 |
f perform:#'add(Ljava/lang/String;Ljava/awt/Component;)Ljava/awt/Component;' |
1111 |
with:(Java as_String:'Center') |
|
1112 |
with:me. |
|
2087 | 1113 |
self halt. |
1114 |
f perform:#'setSize(II)V' with:300 with:300. |
|
1115 |
self halt. |
|
1116 |
f perform:#'show()V'. |
|
1117 |
self halt. |
|
1118 |
||
1119 |
"Modified: / 3.11.1998 / 23:04:41 / cg" |
|
693 | 1120 |
"/ TODO: setup embeddedAppletFrame correctly |
1121 |
"/ (for getParameter to work ...) |
|
1122 |
||
1123 |
"/ create a frame and wrap me; |
|
1124 |
"/ as in: |
|
626 | 1125 |
|
693 | 1126 |
"/ public static void main(String args[]) { |
1127 |
"/ Frame f = new Frame("myName"); |
|
1128 |
"/ mySelf me = new mySelf(); |
|
1129 |
"/ |
|
1130 |
"/ me.init(); |
|
1131 |
"/ me.start(); |
|
1132 |
"/ |
|
1133 |
"/ f.add("Center", me); |
|
1134 |
"/ f.setSize(300, 300); |
|
1135 |
"/ f.show(); |
|
1136 |
"/ } |
|
1137 |
f := (Java at:'java.awt.Frame') basicNew. |
|
1138 |
f perform:#'<init>(Ljava/lang/String;)V' with:(Java as_String:self name). |
|
1139 |
self halt. |
|
1140 |
me := self basicNew. |
|
1141 |
me perform:#'<init>()V'. |
|
1142 |
self halt. |
|
1143 |
||
1144 |
stub := (Java at:'netscape.applet.EmbeddedAppletFrame') new. |
|
1145 |
me instVarNamed:'stub' put:stub. |
|
1146 |
self halt. |
|
1147 |
||
1148 |
me perform:#'init()V'. |
|
1149 |
me perform:#'start()V'. |
|
1150 |
self halt. |
|
1151 |
||
2118 | 1152 |
f perform:#'add(Ljava/lang/String;Ljava/awt/Component;)Ljava/awt/Component;' |
1153 |
with:(Java as_String:'Center') |
|
1154 |
with:me. |
|
626 | 1155 |
self halt. |
413 | 1156 |
f perform:#'setSize(II)V' with:300 with:300. |
1157 |
self halt. |
|
1158 |
f perform:#'show()V'. |
|
1159 |
self halt. |
|
1160 |
||
1161 |
"Modified: / 3.11.1998 / 23:04:41 / cg" |
|
1162 |
! |
|
1163 |
||
626 | 1164 |
startMain |
1165 |
"start a thread for my main() method" |
|
1166 |
||
1167 |
^ self startMainWithArgumentString:nil |
|
1168 |
||
1169 |
"Modified: / 30.12.1998 / 20:24:58 / cg" |
|
1170 |
! |
|
312 | 1171 |
|
626 | 1172 |
startMainWithArgumentString:aCommandLineString |
1173 |
"start a thread for my main() method, passing a string with arguments" |
|
1174 |
||
1175 |
|p| |
|
312 | 1176 |
|
626 | 1177 |
p := Java javaProcessForMainOf:self argumentString:aCommandLineString. |
1178 |
p notNil ifTrue:[ |
|
2118 | 1179 |
p resume. |
1180 |
Object abortSignal handle:[:ex | |
|
626 | 1181 |
p == JavaVM javaScreenUpdaterThread ifTrue:[self halt]. |
654 | 1182 |
p == JavaVM javaEventQueueThread ifTrue:[self halt]. |
2118 | 1183 |
p terminate. |
1184 |
ex reject. |
|
1185 |
] do:[ |
|
1186 |
p waitUntilTerminated |
|
1187 |
]. |
|
508 | 1188 |
] |
1189 |
||
654 | 1190 |
"Modified: / 24.12.1999 / 02:35:04 / cg" |
626 | 1191 |
! ! |
312 | 1192 |
|
626 | 1193 |
!JavaClass methodsFor:'fileOut'! |
1194 |
||
1195 |
basicFileOutDefinitionOn:aStream withNameSpace:nameSpaceBoolean |
|
160 | 1196 |
JavaDecompiler definitionOf:self on:aStream |
1197 |
||
1198 |
"Modified: 22.3.1997 / 14:30:28 / cg" |
|
626 | 1199 |
! |
1200 |
||
1201 |
fileOut |
|
1202 |
self warn:'fileOut not yet supported' |
|
1203 |
||
1204 |
"Modified: 22.3.1997 / 14:30:28 / cg" |
|
1205 |
"Created: 22.3.1997 / 14:35:43 / cg" |
|
130 | 1206 |
! ! |
1207 |
||
43 | 1208 |
!JavaClass methodsFor:'java initialization'! |
1209 |
||
626 | 1210 |
classInit |
1211 |
"call the classes JAVA clinit function" |
|
1212 |
||
2151 | 1213 |
|m| |
626 | 1214 |
|
1215 |
(accessFlags bitAnd:A_INITIALIZED) ~~ 0 ifTrue:[^ self]. |
|
1216 |
||
1217 |
accessFlags := accessFlags bitOr:A_INITIALIZED. |
|
1218 |
||
1219 |
superclass ~~ JavaObject ifTrue:[ |
|
2151 | 1220 |
superclass classInit |
626 | 1221 |
]. |
1222 |
"/ "/ also, all referenced classes must be ... |
|
1223 |
"/ constantPool classReferencesDo:[:aClass | |
|
1224 |
"/ aClass classInit |
|
1225 |
"/ ]. |
|
43 | 1226 |
|
626 | 1227 |
m := self compiledMethodAt:#'<clinit>()V'. |
1228 |
m notNil ifTrue:[ |
|
2151 | 1229 |
"/'calling <clinit>() of ' print. self fullName printNL. |
1230 |
[ |
|
1231 |
OrderOfClassInits notNil ifTrue:[ |
|
1232 |
OrderOfClassInits add:self. |
|
1233 |
]. |
|
1234 |
||
1235 |
m |
|
1236 |
valueWithReceiver:self |
|
1237 |
arguments:#() |
|
1238 |
selector:#'<clinit>()V' |
|
1239 |
search:self class |
|
1240 |
sender:nil |
|
1241 |
] valueOnUnwindDo:[ |
|
1242 |
accessFlags := accessFlags bitXor:A_INITIALIZED. |
|
1243 |
]. |
|
1244 |
"/'calling <clinit>() done ' print. self fullName printNL. |
|
626 | 1245 |
] ifFalse:[ |
1246 |
"/ self fullName print. ' has no clinit()' printNL. |
|
1247 |
]. |
|
1248 |
||
2151 | 1249 |
|
626 | 1250 |
" |
1251 |
JavaVM instructionTrace:true. |
|
1252 |
JavaVM callTrace:true. |
|
1253 |
||
1254 |
(Java classNamed:'java.lang.String') classInit |
|
1255 |
(Java classNamed:'java.lang.System') classInit |
|
1256 |
||
1257 |
(Java classNamed:'java/io/FileDescriptor') classInit |
|
2118 | 1258 |
(Java classNamed:'java.util.Properties') classInit |
43 | 1259 |
" |
175 | 1260 |
|
2151 | 1261 |
"Modified: / 12-11-1998 / 15:41:11 / cg" |
1262 |
"Modified: / 11-12-2010 / 15:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1263 |
"Modified: / 18-08-2011 / 19:37:33 / jv" |
|
626 | 1264 |
! |
1265 |
||
1266 |
initializeStaticFields |
|
1267 |
staticFields isNil ifTrue:[^ self]. |
|
1268 |
||
1269 |
staticFields do:[:f | |
|
1270 |
|val type| |
|
86 | 1271 |
|
626 | 1272 |
(val := f constantValue) isNil ifTrue:[ |
1273 |
"/ careful: int/long etc. constants must be initialized |
|
1274 |
"/ with correct type. |
|
1275 |
type := f type. |
|
1276 |
type == #long ifTrue:[ |
|
1277 |
val := 0. |
|
1278 |
] ifFalse:[type == #int ifTrue:[ |
|
1279 |
val := 0. |
|
1280 |
] ifFalse:[type == #float ifTrue:[ |
|
1281 |
val := 0.0 asShortFloat |
|
1282 |
] ifFalse:[type == #double ifTrue:[ |
|
2118 | 1283 |
val := 0.0 |
626 | 1284 |
] ifFalse:[type == #byte ifTrue:[ |
1285 |
val := 0. |
|
1286 |
] ifFalse:[type == #char ifTrue:[ |
|
1287 |
val := 0. |
|
1288 |
] ifFalse:[type == #'unsigned short' ifTrue:[ |
|
1289 |
val := 0. |
|
1290 |
] ifFalse:[type == #boolean ifTrue:[ |
|
172 | 1291 |
val := 0. |
1292 |
]]]]]]]]. |
|
1293 |
]. |
|
1294 |
self instVarNamed:(f name) put:val. |
|
60 | 1295 |
]. |
626 | 1296 |
! ! |
1297 |
||
1298 |
!JavaClass methodsFor:'java instance creation'! |
|
29 | 1299 |
|
626 | 1300 |
initValueFor:instVarName |
1301 |
|idx field| |
|
1302 |
||
1303 |
idx := fields findFirst:[:field | field name = instVarName]. |
|
1304 |
idx == 0 ifTrue:[ |
|
1305 |
superclass ~~ JavaObject ifTrue:[ |
|
172 | 1306 |
^ superclass initValueFor:instVarName |
1307 |
]. |
|
1308 |
self halt |
|
52 | 1309 |
] ifFalse:[ |
172 | 1310 |
field := fields at:idx. |
1311 |
^ field initialValue |
|
52 | 1312 |
]. |
1313 |
! |
|
1314 |
||
626 | 1315 |
new |
1316 |
"create a new instance, preset its fields, |
|
1317 |
and call its JAVA init function" |
|
1318 |
||
1319 |
|newJavaObject| |
|
1320 |
||
1321 |
newJavaObject := self newCleared. |
|
1322 |
newJavaObject perform:#'<init>()V'. |
|
1323 |
^ newJavaObject |
|
1324 |
||
1325 |
" |
|
1326 |
(Java classNamed:'java.lang.String') basicNew inspect |
|
1327 |
(Java classNamed:'java.lang.String') newCleared inspect |
|
52 | 1328 |
(Java classNamed:'java.lang.String') new inspect |
1329 |
" |
|
1330 |
||
415 | 1331 |
"Modified: / 4.11.1998 / 18:04:34 / cg" |
52 | 1332 |
! |
1333 |
||
626 | 1334 |
newCleared |
1335 |
"create a new cleared JAVA instance. |
|
1336 |
Its instVars are cleared to the corresponding typed values; |
|
1337 |
however, <init> is not invoked for it." |
|
2151 | 1338 |
|
1339 |
| newJavaObject |
|
1340 |
sz "{ Class: SmallInteger }" | |
|
1341 |
||
1342 |
(accessFlags bitAnd: A_ABSTRACT_OR_INTERFACE) ~~ 0 |
|
1343 |
ifTrue: |
|
1344 |
[ JavaVM throwInstantiationExceptionFor: self. |
|
1345 |
^ nil ]. |
|
626 | 1346 |
newJavaObject := super basicNew. |
2151 | 1347 |
initValues notNil |
1348 |
ifTrue: |
|
1349 |
[ sz := self instSize. |
|
1350 |
1 to: sz do: [:i | newJavaObject instVarAt: i put: (initValues at: i) ]. ]. |
|
626 | 1351 |
^ newJavaObject |
1352 |
||
1353 |
" |
|
1354 |
(Java classNamed:'java.lang.String') basicNew inspect |
|
1355 |
(Java classNamed:'java.lang.String') newCleared inspect |
|
2151 | 1356 |
(Java classNamed:'java.lang.String') new inspect" |
1357 |
||
1358 |
"Modified: / 13-11-1998 / 14:10:45 / cg" |
|
1359 |
"Modified: / 10-03-2011 / 22:38:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
451 | 1360 |
! |
1361 |
||
626 | 1362 |
newWith_String:argString |
1363 |
"create a new instance, preset its fields, |
|
1364 |
and call its JAVA init function passing a String arg" |
|
1365 |
||
1366 |
|newJavaObject| |
|
1367 |
||
1368 |
newJavaObject := self newCleared. |
|
2118 | 1369 |
newJavaObject |
1370 |
perform:#'<init>(Ljava/lang/String;)V' |
|
1371 |
with:(Java as_String:argString). |
|
626 | 1372 |
^ newJavaObject |
1373 |
||
1374 |
" |
|
1375 |
((Java classNamed:'java.lang.ArrayStoreException') newWith_String:'foo') inspect |
|
1376 |
" |
|
1377 |
||
1378 |
"Modified: / 4.11.1998 / 18:04:34 / cg" |
|
1379 |
"Created: / 13.11.1998 / 14:17:01 / cg" |
|
1380 |
! |
|
1381 |
||
1382 |
newWith_int:arg |
|
1383 |
"create a new instance, preset its fields, |
|
1384 |
and call its JAVA init function passing an int arg" |
|
1385 |
||
1386 |
|newJavaObject| |
|
1387 |
||
1388 |
newJavaObject := self newCleared. |
|
1389 |
newJavaObject perform:#'<init>(I)V' with:arg. |
|
1390 |
^ newJavaObject |
|
1391 |
||
1392 |
" |
|
1393 |
((Java classNamed:'java.lang.Integer') newWith_int:123) inspect |
|
451 | 1394 |
" |
1395 |
||
1396 |
"Modified: / 4.11.1998 / 18:04:34 / cg" |
|
1397 |
"Created: / 13.11.1998 / 14:17:01 / cg" |
|
43 | 1398 |
! ! |
1399 |
||
229 | 1400 |
!JavaClass methodsFor:'message sending'! |
43 | 1401 |
|
626 | 1402 |
doesNotUnderstand:aMessage |
1403 |
"as a courtesy to the smalltalker, try to map static methods as |
|
1404 |
Smalltalk-class methods" |
|
1405 |
||
1406 |
|r args numArgs methods javaMethod sel anyMethodsFound argType |
|
1407 |
argSignature newArgs oArgIdx nArgIdx canConvert |
|
1408 |
retVal| |
|
1409 |
||
1410 |
args := aMessage arguments. |
|
1411 |
numArgs := args size. |
|
1412 |
sel := aMessage selector. |
|
1413 |
||
1414 |
methods := JavaClass lookupMethods:sel numArgs:numArgs in:self static:true. |
|
1415 |
methods size == 1 ifTrue:[ |
|
2118 | 1416 |
javaMethod := methods first. |
1417 |
"/ there is only one - try that one. |
|
626 | 1418 |
] ifFalse:[ |
2118 | 1419 |
methods size > 1 ifTrue:[ |
1420 |
"/ more than one - select the ones that could be used. |
|
1421 |
methods := methods select:[:aMethod | |
|
1422 |
|argSignature| |
|
626 | 1423 |
|
2118 | 1424 |
argSignature := aMethod argSignature. |
1425 |
(JavaClass canConvertArgsToJava:args asSpecifiedIn:argSignature) |
|
1426 |
]. |
|
1427 |
methods size == 1 ifTrue:[ |
|
1428 |
javaMethod := methods first. |
|
1429 |
] |
|
1430 |
] |
|
626 | 1431 |
]. |
79 | 1432 |
|
626 | 1433 |
javaMethod notNil ifTrue:[ |
2118 | 1434 |
(ArgumentConversionErrorSignal catch:[ |
1435 |
args notNil ifTrue:[ |
|
1436 |
args := JavaClass |
|
1437 |
convertArgsToJava:args |
|
1438 |
asSpecifiedIn:(javaMethod argSignature) |
|
1439 |
numArgs:numArgs. |
|
1440 |
]. |
|
1441 |
]) ifFalse:[ |
|
1442 |
retVal := javaMethod |
|
1443 |
valueWithReceiver:self "/ (javaMethod javaClass) |
|
1444 |
arguments:args |
|
1445 |
selector:(javaMethod selector) |
|
1446 |
search:self "/ (javaMethod javaClass class) |
|
1447 |
sender:nil. |
|
1448 |
^ JavaClass convertToSmalltalk:retVal type:(javaMethod returnType). |
|
1449 |
]. |
|
1450 |
^ MessageNotUnderstoodSignal |
|
1451 |
raiseRequestWith:aMessage |
|
1452 |
errorString:'no method for given argument(s)' |
|
1453 |
in:thisContext "sender" |
|
626 | 1454 |
]. |
1455 |
||
1456 |
anyMethodsFound := false. |
|
1457 |
||
1458 |
"/ try all with that name (the number of args could be different ... |
|
415 | 1459 |
|
626 | 1460 |
methods := JavaClass lookupMethods:sel numArgs:nil in:self static:true. |
1461 |
methods size > 0 ifTrue:[ |
|
2118 | 1462 |
anyMethodsFound := true. |
1463 |
numArgs > 0 ifTrue:[ |
|
1464 |
methods do:[:methodToTry | |
|
1465 |
(ArgumentConversionErrorSignal catch:[ |
|
1466 |
newArgs := JavaClass |
|
1467 |
convertArgsToJava:args |
|
1468 |
asSpecifiedIn:(methodToTry argSignature) |
|
1469 |
numArgs:methodToTry numArgs. |
|
1470 |
]) ifFalse:[ |
|
1471 |
retVal := methodToTry |
|
1472 |
valueWithReceiver:self "/ (methodToTry javaClass) |
|
1473 |
arguments:newArgs |
|
1474 |
selector:(methodToTry selector) |
|
1475 |
search:self "/ (methodToTry javaClass class) |
|
1476 |
sender:nil. |
|
1477 |
^ JavaClass convertToSmalltalk:retVal type:(methodToTry returnType). |
|
1478 |
]. |
|
1479 |
]. |
|
1480 |
] |
|
626 | 1481 |
]. |
1482 |
||
1483 |
anyMethodsFound ifTrue:[ |
|
2118 | 1484 |
methods size == 1 ifTrue:[ |
1485 |
javaMethod := methods first. |
|
626 | 1486 |
|
2118 | 1487 |
^ MessageNotUnderstoodSignal |
1488 |
raiseRequestWith:aMessage |
|
1489 |
errorString:(sel , ' expects ' , javaMethod argSignature size printString , ' argument(s)') |
|
1490 |
in:thisContext "sender" |
|
1491 |
]. |
|
1492 |
^ MessageNotUnderstoodSignal |
|
1493 |
raiseRequestWith:aMessage |
|
1494 |
errorString:'no method for given argument count or type' |
|
1495 |
in:thisContext "sender" |
|
415 | 1496 |
]. |
1497 |
^ super doesNotUnderstand:aMessage |
|
1498 |
||
426 | 1499 |
"Modified: / 6.11.1998 / 00:57:22 / cg" |
79 | 1500 |
! |
1501 |
||
626 | 1502 |
lookupMethodFor:selector |
2151 | 1503 |
|method cls sel queue | |
626 | 1504 |
|
1505 |
sel := selector asSymbolIfInterned. |
|
1506 |
sel notNil ifTrue:[ |
|
2151 | 1507 |
queue := OrderedCollection with: self. |
1508 |
[ queue isEmpty ] whileFalse:[ |
|
1509 |
cls := queue removeFirst. |
|
1510 |
method := cls compiledMethodAt:sel. |
|
1511 |
method notNil ifTrue:[ ^ method ]. |
|
1512 |
queue addAll: cls interfaces. |
|
1513 |
cls isInterface ifFalse:[ |
|
1514 |
cls superclass ~~ JavaObject ifTrue:[queue add: cls superclass] |
|
1515 |
] |
|
1516 |
]. |
|
43 | 1517 |
]. |
2151 | 1518 |
"/cls ifNotNil:[^super lookupMethodFor: selector]. |
43 | 1519 |
^ nil |
2151 | 1520 |
|
1521 |
"Modified: / 10-08-2011 / 22:40:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
438 | 1522 |
! |
1523 |
||
626 | 1524 |
performStatic:selector |
1525 |
"send a static message, without args." |
|
1526 |
||
1527 |
|javaMethod sel| |
|
1528 |
||
1529 |
sel := selector asSymbolIfInterned. |
|
1530 |
sel notNil ifTrue:[ |
|
2118 | 1531 |
javaMethod := methodDictionary at:sel. |
1532 |
javaMethod notNil ifTrue:[ |
|
1533 |
javaMethod isStatic ifTrue:[ |
|
1534 |
^ javaMethod |
|
1535 |
valueWithReceiver:self |
|
1536 |
arguments:#() |
|
1537 |
] |
|
1538 |
]. |
|
626 | 1539 |
]. |
1540 |
||
1541 |
^ self doesNotUnderstand:(Message selector:selector) |
|
438 | 1542 |
|
1543 |
"Modified: / 15.1.1998 / 00:31:27 / cg" |
|
1544 |
"Created: / 12.11.1998 / 16:29:20 / cg" |
|
626 | 1545 |
! |
1546 |
||
1547 |
performStatic:selector with:arg |
|
1548 |
"send a static message, with one args." |
|
1549 |
||
1550 |
|javaMethod sel| |
|
1551 |
||
1552 |
sel := selector asSymbolIfInterned. |
|
1553 |
sel notNil ifTrue:[ |
|
2118 | 1554 |
javaMethod := methodDictionary at:sel. |
1555 |
javaMethod notNil ifTrue:[ |
|
1556 |
javaMethod isStatic ifTrue:[ |
|
1557 |
^ javaMethod |
|
1558 |
valueWithReceiver:self |
|
1559 |
arguments:(Array with:arg) |
|
1560 |
selector:selector |
|
1561 |
search:nil |
|
1562 |
sender:nil |
|
1563 |
] |
|
1564 |
]. |
|
626 | 1565 |
]. |
1566 |
||
1567 |
^ self doesNotUnderstand:(Message selector:selector argument:arg) |
|
1568 |
||
1569 |
"Modified: / 15.1.1998 / 00:31:27 / cg" |
|
1570 |
"Created: / 10.12.1998 / 21:50:29 / cg" |
|
29 | 1571 |
! ! |
1572 |
||
2151 | 1573 |
!JavaClass methodsFor:'misc ui support'! |
1574 |
||
1575 |
iconInBrowserSymbol |
|
1576 |
<resource: #programImage> |
|
1577 |
||
1578 |
||
1579 |
^#javaClassBrowserIcon |
|
1580 |
||
1581 |
"Created: / 20-12-2010 / 19:11:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1582 |
! ! |
|
1583 |
||
160 | 1584 |
!JavaClass methodsFor:'printOut'! |
1585 |
||
626 | 1586 |
printNameInHierarchy |
1587 |
"return my name as printed in the hierarchy" |
|
160 | 1588 |
|
626 | 1589 |
^ self displayString |
1590 |
||
1591 |
"Modified: 22.3.1997 / 14:16:55 / cg" |
|
160 | 1592 |
! |
1593 |
||
626 | 1594 |
printOutOn:aStream |
1595 |
self warn:'printOut not yet supported' |
|
160 | 1596 |
|
626 | 1597 |
"Created: 22.3.1997 / 14:36:12 / cg" |
1598 |
! |
|
160 | 1599 |
|
626 | 1600 |
printOutProtocolOn:aStream |
160 | 1601 |
self warn:'printOut not yet supported' |
1602 |
||
1603 |
"Created: 22.3.1997 / 14:36:28 / cg" |
|
1604 |
! ! |
|
1605 |
||
626 | 1606 |
!JavaClass methodsFor:'printing & storing'! |
1 | 1607 |
|
626 | 1608 |
displayString |
1609 |
^ fullName copyReplaceAll:$/ with:$. |
|
1610 |
||
1611 |
"/ ^ 'JAVA-' , name . |
|
1612 |
"/ ^ name , '(Java)' "/ 'JavaClass(' , name , ')' |
|
1 | 1613 |
|
360 | 1614 |
"Created: / 15.4.1996 / 16:02:48 / cg" |
1615 |
"Modified: / 18.7.1998 / 22:56:30 / cg" |
|
626 | 1616 |
! ! |
1617 |
||
1618 |
!JavaClass methodsFor:'private accessing'! |
|
1619 |
||
1620 |
addMethod:m name:name signature:signature |
|
1621 |
|sel| |
|
63 | 1622 |
|
626 | 1623 |
sel := (name , signature) asSymbol. |
1624 |
self addSelector:sel withMethod:m. |
|
1625 |
^ self. |
|
1626 |
||
1627 |
"/ selectorArray isNil ifTrue:[ |
|
1628 |
"/ selectorArray := #(). |
|
1629 |
"/ methodArray := #() |
|
1630 |
"/ ]. |
|
1631 |
"/ selectorArray := selectorArray copyWith:(name , signature) asSymbol. "/ name. |
|
1632 |
"/"/ selectorArray := selectorArray copyWith:name asSymbol. "/ name. |
|
98 | 1633 |
"/ methodArray := methodArray copyWith:m |
5 | 1634 |
|
1635 |
"Created: 15.4.1996 / 16:42:52 / cg" |
|
98 | 1636 |
|
1637 |
||
5 | 1638 |
! |
1639 |
||
626 | 1640 |
addSelector:newSelector withMethod:newMethod |
1641 |
"redefined to not flush smalltalk caches and send NO smalltalk-class |
|
1642 |
change notification. Will eventually flush Java caches." |
|
1643 |
||
1644 |
|nargs oldMethod| |
|
1645 |
||
1646 |
oldMethod := self compiledMethodAt:newSelector. |
|
130 | 1647 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false]. |
1648 |
||
1649 |
^ true |
|
1650 |
||
1651 |
"Created: 20.1.1997 / 13:00:48 / cg" |
|
1652 |
! |
|
1653 |
||
626 | 1654 |
setAccessFlags:flags |
3 | 1655 |
accessFlags := flags. |
1 | 1656 |
|
1657 |
"Created: 15.4.1996 / 16:42:52 / cg" |
|
5 | 1658 |
! |
1659 |
||
626 | 1660 |
setBinaryFilePath:aPathName |
73 | 1661 |
binaryFilePath := aPathName |
1662 |
! |
|
1663 |
||
626 | 1664 |
setFields:f |
1665 |
|vals| |
|
1666 |
||
1667 |
JavaClass setInstanceVariableStringFromFields:f in:self. |
|
1668 |
||
1669 |
instSize := superclass instSize + f size. |
|
1670 |
fields := f. |
|
2151 | 1671 |
|
1672 |
f withIndexDo:[:field :index| |
|
1673 |
field setClass: self. |
|
1674 |
field setIndex: superclass instSize + index. |
|
1675 |
]. |
|
1676 |
||
2118 | 1677 |
vals := self allInstVarNames |
2151 | 1678 |
collect:[:nm | |
1679 |
self initValueFor:nm |
|
1680 |
]. |
|
626 | 1681 |
vals isEmpty ifTrue:[ |
2151 | 1682 |
initValues := nil |
626 | 1683 |
] ifFalse:[ |
2151 | 1684 |
(vals detect:[:el | el notNil] ifNone:nil) isNil ifTrue:[ |
1685 |
initValues := nil |
|
1686 |
] ifFalse:[ |
|
1687 |
initValues := vals asArray |
|
1688 |
] |
|
426 | 1689 |
] |
27 | 1690 |
|
2151 | 1691 |
"Created: / 15-04-1996 / 16:42:52 / cg" |
1692 |
"Modified: / 06-11-1998 / 01:53:01 / cg" |
|
1693 |
"Modified: / 27-07-2011 / 09:26:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
27 | 1694 |
! |
1695 |
||
626 | 1696 |
setFullName:aString |
1697 |
|nameComponents| |
|
1698 |
||
1699 |
fullName := aString asSymbol. |
|
686 | 1700 |
"/ nameComponents := aString asCollectionOfSubstringsSeparatedBy:$/. |
1701 |
"/ name := nameComponents last asSymbol. |
|
1702 |
name := fullName. |
|
7 | 1703 |
|
423 | 1704 |
"Created: / 15.4.1996 / 16:42:52 / cg" |
1705 |
"Modified: / 5.11.1998 / 19:14:39 / cg" |
|
7 | 1706 |
! |
1707 |
||
626 | 1708 |
setInterfaces:i |
1709 |
i size > 0 ifTrue:[ |
|
1710 |
interfaces := i |
|
1711 |
] ifFalse:[ |
|
1712 |
interfaces := nil |
|
110 | 1713 |
] |
1714 |
||
168 | 1715 |
"Modified: 7.4.1997 / 15:44:53 / cg" |
110 | 1716 |
! |
1717 |
||
626 | 1718 |
setSourceFile:aFilename |
1719 |
sourceFile := aFilename. |
|
1720 |
||
1721 |
"Created: 15.4.1996 / 16:42:52 / cg" |
|
1722 |
! |
|
1723 |
||
1724 |
setStaticFields:f |
|
1725 |
JavaClass setInstanceVariableStringFromFields:f in:self class. |
|
1726 |
||
1727 |
staticFields := f. |
|
1728 |
||
2151 | 1729 |
"Modified: / 17-08-2011 / 09:26:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
626 | 1730 |
! |
60 | 1731 |
|
626 | 1732 |
setSuperclass:aClass |
1733 |
|iVars numIvars| |
|
247 | 1734 |
|
626 | 1735 |
aClass isNil ifTrue:[ |
1736 |
super setSuperclass:JavaObject |
|
1737 |
] ifFalse:[ |
|
1738 |
(aClass isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ |
|
1739 |
self halt. |
|
1740 |
]. |
|
1741 |
super setSuperclass:aClass. |
|
1742 |
]. |
|
1743 |
||
1744 |
iVars := self instVarNames. |
|
1745 |
((numIvars := iVars size) > 0) ifTrue:[ |
|
1746 |
(superclass notNil and:[(superclass isMemberOf:JavaUnresolvedClassConstant) not]) ifTrue:[ |
|
1747 |
instSize := superclass instSize + numIvars |
|
1748 |
] ifFalse:[ |
|
1749 |
instSize := numIvars |
|
252 | 1750 |
] |
29 | 1751 |
]. |
27 | 1752 |
|
1753 |
"Created: 15.4.1996 / 16:42:52 / cg" |
|
247 | 1754 |
"Modified: 22.8.1997 / 15:06:45 / cg" |
626 | 1755 |
! ! |
1 | 1756 |
|
2151 | 1757 |
!JavaClass methodsFor:'private-changes management'! |
1758 |
||
1759 |
writingChangeWithTimeStamp:doStampIt do:aBlock |
|
1760 |
||
1761 |
"No changes for Java classes now" |
|
1762 |
||
1763 |
"Created: / 14-12-2010 / 18:07:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1764 |
! ! |
|
1765 |
||
626 | 1766 |
!JavaClass methodsFor:'queries'! |
1767 |
||
1768 |
canBeSubclassed |
|
1769 |
"return true, if its allowed to create subclasses of the receiver." |
|
426 | 1770 |
|
1771 |
self isFinal ifTrue:[^ false]. |
|
1772 |
self isInterface ifTrue:[^ false]. |
|
1773 |
^ true |
|
1774 |
||
1775 |
"Created: / 5.11.1998 / 23:04:50 / cg" |
|
1776 |
! |
|
1777 |
||
2151 | 1778 |
containsMethodsAnnotatedWith:aJavaTypeName |
1779 |
| methods | |
|
1780 |
||
1781 |
methods := self selectMethodsAnnotatedWith:aJavaTypeName. |
|
1782 |
methods size > 0 ifTrue:[ ^ true ]. |
|
1783 |
(self name ~= #'java/lang/Object') |
|
1784 |
ifTrue:[ ^ superclass containsMethodsAnnotatedWith:aJavaTypeName. ]. |
|
1785 |
^ false. |
|
1786 |
||
1787 |
"Created: / 02-03-2011 / 23:01:14 / Marcel Hlopko <hlopik@gmail.com>" |
|
1788 |
! |
|
1789 |
||
626 | 1790 |
hasInterface:aJavaInterface |
1791 |
"return true, if I respond to all methods as |
|
1792 |
required by the argument, an aJavaInterface" |
|
1793 |
||
1794 |
interfaces size > 0 ifTrue:[ |
|
2118 | 1795 |
self interfaces do:[:if | |
1796 |
aJavaInterface == if ifTrue:[ |
|
1797 |
^ true |
|
1798 |
]. |
|
1799 |
] |
|
626 | 1800 |
]. |
1801 |
superclass isJavaClass ifTrue:[ |
|
2118 | 1802 |
^ superclass hasInterface:aJavaInterface |
626 | 1803 |
]. |
1804 |
^ false. |
|
1805 |
||
1806 |
"/ aJavaInterface methodDictionary keysAndValuesDo:[:sel :mthd | |
|
587 | 1807 |
"/ (self canUnderstand:sel) ifFalse:[ |
1808 |
"/ ^ false. |
|
1809 |
"/ ] |
|
1810 |
"/ ]. |
|
53 | 1811 |
^ true |
281 | 1812 |
|
1813 |
"Modified: / 28.1.1998 / 01:46:16 / cg" |
|
587 | 1814 |
|
52 | 1815 |
! |
1816 |
||
2151 | 1817 |
isAnonymous |
1818 |
||
1819 |
| i | |
|
1820 |
i := name lastIndexOf: $$. |
|
1821 |
i ~~ 0 ifTrue:[ |
|
1822 |
i + 1 to: name size do:[:i| |
|
1823 |
(name at:i) isDigit ifFalse:[^false]. |
|
1824 |
]. |
|
1825 |
^true |
|
1826 |
]. |
|
1827 |
^false |
|
1828 |
||
1829 |
" |
|
1830 |
(Java at:'java.io.Console') isAnonymous |
|
1831 |
(Java at:'java.io.Console$1') isAnonymous |
|
1832 |
(Java at:'java.io.Console$1$1') isAnonymous |
|
1833 |
(Java at:'sun.misc.Launcher$ExtClassLoader') isAnonymous |
|
1834 |
||
1835 |
" |
|
1836 |
||
1837 |
"Created: / 18-03-1997 / 17:48:01 / cg" |
|
1838 |
"Created: / 07-08-2011 / 15:50:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1839 |
! |
|
1840 |
||
1841 |
isJavaArrayClass |
|
1842 |
||
1843 |
^false |
|
1844 |
||
1845 |
"Created: / 05-02-2011 / 22:20:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1846 |
! |
|
1847 |
||
626 | 1848 |
isJavaClass |
148 | 1849 |
^ self ~~ JavaClass |
1850 |
||
1851 |
"Created: 18.3.1997 / 17:48:01 / cg" |
|
1852 |
! |
|
1853 |
||
2151 | 1854 |
isJavaClassType |
1855 |
||
1856 |
^self isInterface not |
|
1857 |
||
1858 |
" |
|
1859 |
(Java classForName:'java.lang.Class') isJavaClassType |
|
1860 |
" |
|
1861 |
||
1862 |
"Created: / 11-02-2011 / 08:09:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1863 |
! |
|
1864 |
||
1865 |
isJavaInterfaceType |
|
1866 |
||
1867 |
^self isInterface |
|
1868 |
||
1869 |
" |
|
1870 |
(Java classForName:'java.lang.Class') isJavaInterfaceType |
|
1871 |
" |
|
1872 |
||
1873 |
"Created: / 11-02-2011 / 08:09:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1874 |
! |
|
1875 |
||
626 | 1876 |
isJavaMethodRef |
1877 |
^ false |
|
1878 |
||
1879 |
"Created: / 9.11.1999 / 15:42:10 / cg" |
|
1880 |
! |
|
1881 |
||
2151 | 1882 |
isJavaPrimitiveType |
1883 |
||
1884 |
^false |
|
1885 |
||
1886 |
" |
|
1887 |
(Java classForName:'java.lang.Class') isJavaPrimitiveType |
|
1888 |
ByteArray isJavaPrimitiveType |
|
1889 |
" |
|
1890 |
||
1891 |
"Created: / 21-12-2010 / 23:03:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1892 |
! |
|
1893 |
||
1894 |
isJavaReferenceType |
|
1895 |
||
1896 |
^true |
|
1897 |
||
1898 |
" |
|
1899 |
(Java classForName:'java.lang.Class') isJavaReferenceType |
|
1900 |
" |
|
1901 |
||
1902 |
"Created: / 20-12-2010 / 21:54:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1903 |
! |
|
1904 |
||
1905 |
isJavaType |
|
1906 |
||
1907 |
^true |
|
1908 |
||
1909 |
" |
|
1910 |
(Java classForName:'java.lang.Class') isJavaType |
|
1911 |
" |
|
1912 |
||
1913 |
"Created: / 20-12-2010 / 21:53:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1914 |
! |
|
1915 |
||
626 | 1916 |
isUnresolved |
1917 |
"return true, if the receiver is unresolved; |
|
2118 | 1918 |
javaClasses are never; JavaUnresolvedClasses are always" |
345 | 1919 |
|
90 | 1920 |
^ false |
345 | 1921 |
|
2151 | 1922 |
"Modified: / 07-05-1998 / 12:23:14 / cg" |
1923 |
"Created: / 06-03-2011 / 22:57:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
175 | 1924 |
! |
1925 |
||
679 | 1926 |
nameInBrowser |
1927 |
"return a nameString as shown in browsers" |
|
1928 |
||
1929 |
^ self name copyReplaceAll:$/ with:$. |
|
1930 |
! |
|
1931 |
||
626 | 1932 |
nameSpacePath |
1933 |
|parts s| |
|
1934 |
||
1935 |
parts := self fullName asCollectionOfSubstringsSeparatedBy:$/. |
|
1936 |
s := '' writeStream. |
|
1937 |
s nextPutAll:'JAVA'. |
|
1938 |
parts from:1 to:(parts size - 1) do:[:aPart | |
|
2118 | 1939 |
s nextPutAll:'::'. |
1940 |
s nextPutAll:aPart |
|
626 | 1941 |
]. |
1942 |
^ s contents |
|
1943 |
||
1944 |
" |
|
2118 | 1945 |
JAVA::java::lang::Object fullName |
1946 |
JAVA::java::lang::Object nameSpacePath |
|
1947 |
JAVA::java::lang::Object name |
|
393 | 1948 |
" |
1949 |
||
1950 |
"Modified: / 19.10.1998 / 20:07:24 / cg" |
|
1951 |
! |
|
1952 |
||
2151 | 1953 |
selectMethodsAnnotatedWith:aJavaTypeName |
1954 |
^ self methodDictionary values select: |
|
1955 |
[:method | |
|
1956 |
(method annotations |
|
1957 |
ifNotNil:[ method annotations runtimeVisible at:aJavaTypeName ifAbsent:nil ]) |
|
1958 |
isNil not ] |
|
1959 |
||
1960 |
"Created: / 02-03-2011 / 23:06:42 / Marcel Hlopko <hlopik@gmail.com>" |
|
1961 |
! |
|
1962 |
||
626 | 1963 |
supportsMethodCategories |
1964 |
^ self isJavaClass not |
|
175 | 1965 |
|
626 | 1966 |
"Created: / 30.7.1997 / 14:58:58 / cg" |
1967 |
"Modified: / 7.5.1998 / 12:25:54 / cg" |
|
1968 |
! |
|
321 | 1969 |
|
626 | 1970 |
typeName |
2151 | 1971 |
^ 'L' , self fullName , ';'. |
321 | 1972 |
|
1973 |
" |
|
2151 | 1974 |
(Java at:'java.util.Stack') typeName" |
1975 |
||
1976 |
"Modified: / 10-02-1998 / 17:13:26 / cg" |
|
1977 |
"Modified: / 02-03-2011 / 22:48:40 / Marcel Hlopko <hlopik@gmail.com>" |
|
1978 |
! ! |
|
1979 |
||
1980 |
!JavaClass methodsFor:'queries-protocol'! |
|
1981 |
||
1982 |
equalsOrIsSubclassOf: aJavaClass |
|
1983 |
self = aJavaClass ifTrue: [^true]. |
|
1984 |
^ self isSubclassOf:aJavaClass. |
|
1985 |
||
1986 |
"Created: / 30-05-2011 / 23:07:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1987 |
! |
|
1988 |
||
1989 |
includesBehavior: aClass |
|
1990 |
||
1991 |
^(aClass isJavaClass not or:[aClass isInterface not]) |
|
1992 |
ifTrue:[super includesBehavior: aClass] |
|
1993 |
ifFalse:[self == aClass or:[self allInterfaces includes: aClass]]. |
|
1994 |
||
1995 |
"Created: / 05-02-2011 / 23:44:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1996 |
"Modified: / 11-02-2011 / 09:12:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1997 |
! |
|
1998 |
||
1999 |
isSubclassOf: aJavaClass |
|
2000 |
|tmpClass| |
|
2001 |
||
2002 |
tmpClass := self superclass. |
|
2003 |
[tmpClass isJavaClass] whileTrue: [tmpClass = aJavaClass ifTrue:[^true]. tmpClass := tmpClass superclass]. |
|
2004 |
^false. |
|
2005 |
||
2006 |
"Created: / 13-04-2011 / 23:18:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2007 |
! ! |
|
2008 |
||
2009 |
!JavaClass methodsFor:'reflection'! |
|
2010 |
||
2011 |
lookupFieldByNameAndType: aJavaNameAndType |
|
2012 |
||
2013 |
| field cls | |
|
2014 |
||
2015 |
cls := self. |
|
2016 |
[ cls ~= JavaObject ] whileTrue: [ |
|
2017 |
field := cls fields detect: |
|
2018 |
[:each | |
|
2019 |
each name = aJavaNameAndType name |
|
2020 |
"and: [ each signatureWithoutTypeVariables = aJavaNameAndType descriptor ]"] |
|
2021 |
ifNone:[nil]. |
|
2022 |
field ifNotNil:[^field]. |
|
2023 |
cls := cls superclass. |
|
2024 |
]. |
|
2025 |
self breakPoint: #jv. |
|
2026 |
^nil |
|
2027 |
||
2028 |
"Created: / 11-04-2011 / 21:27:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2029 |
"Modified: / 04-06-2011 / 17:06:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2030 |
"Modified: / 13-08-2011 / 00:46:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2031 |
! |
|
2032 |
||
2033 |
lookupMethodByNameAndType: aJavaNameAndType |
|
2034 |
^ self lookupMethodFor: aJavaNameAndType selector. |
|
2035 |
||
2036 |
"Created: / 11-04-2011 / 21:28:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2037 |
! |
|
2038 |
||
2039 |
lookupStaticFieldByNameAndType: aJavaNameAndType |
|
2040 |
||
2041 |
| field cls | |
|
2042 |
||
2043 |
cls := self. |
|
2044 |
[ cls ~= JavaObject ] whileTrue: [ |
|
2045 |
field := cls staticFields detect: |
|
2046 |
[:each | |
|
2047 |
each name = aJavaNameAndType name |
|
2048 |
"and: [ each signature = aJavaNameAndType descriptor ]"] |
|
2049 |
ifNone:[nil]. |
|
2050 |
field ifNotNil:[^field]. |
|
2051 |
cls := cls superclass. |
|
2052 |
]. |
|
2053 |
self breakPoint: #jv. |
|
2054 |
^nil |
|
2055 |
||
2056 |
"Created: / 11-04-2011 / 21:27:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2057 |
"Modified: / 04-06-2011 / 17:06:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2058 |
"Modified: / 13-08-2011 / 00:46:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2059 |
! |
|
2060 |
||
2061 |
lookupStaticMethodByNameAndType: aJavaNameAndType |
|
2062 |
^ self lookupMethodFor: aJavaNameAndType selector. |
|
2063 |
||
2064 |
"Created: / 28-04-2011 / 22:50:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
626 | 2065 |
! ! |
2066 |
||
2067 |
!JavaClass methodsFor:'special'! |
|
2068 |
||
2069 |
asClassPointerRef |
|
2070 |
"/ self halt. |
|
2071 |
^ self |
|
2072 |
||
2073 |
"Created: / 10.11.1998 / 02:07:01 / cg" |
|
2074 |
"Modified: / 8.1.1999 / 14:11:26 / cg" |
|
428 | 2075 |
! |
2076 |
||
2151 | 2077 |
deinit |
2078 |
||
2079 |
accessFlags := accessFlags bitClear: A_INITIALIZED. |
|
2080 |
||
2081 |
"Created: / 25-10-2010 / 12:28:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2082 |
! |
|
2083 |
||
626 | 2084 |
deref |
2118 | 2085 |
^ self |
428 | 2086 |
|
626 | 2087 |
"Created: / 10.11.1998 / 02:08:06 / cg" |
428 | 2088 |
! |
2089 |
||
2151 | 2090 |
javaArrayClass |
2091 |
"/ self halt. |
|
2092 |
"/ ^ Array |
|
2093 |
||
2094 |
^ JavaVM javaArrayClassFor:self |
|
2095 |
||
2096 |
"Created: / 10-11-1998 / 02:07:32 / cg" |
|
2097 |
"Modified: / 08-01-1999 / 14:11:34 / cg" |
|
2098 |
"Modified: / 19-12-2010 / 16:13:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2099 |
! |
|
2100 |
||
626 | 2101 |
updateClassRefsFrom:oldClass to:newClass |
2102 |
self == oldClass ifTrue:[ |
|
2118 | 2103 |
self makeObsolete. |
2104 |
^ self |
|
626 | 2105 |
]. |
2106 |
||
2107 |
constantPool updateClassRefsFrom:oldClass to:newClass. |
|
2108 |
interfaces notNil ifTrue:[ |
|
2118 | 2109 |
interfaces := interfaces collect:[:anInterface | |
2110 |
anInterface == oldClass ifTrue:[ |
|
2111 |
newClass isNil ifTrue:[ |
|
2112 |
nil "/ replace by an unresolvedInterface |
|
2113 |
] ifFalse:[ |
|
2114 |
newClass |
|
2115 |
] |
|
2116 |
] ifFalse:[ |
|
2117 |
anInterface |
|
2118 |
] |
|
2119 |
] |
|
626 | 2120 |
] |
2121 |
||
2122 |
"Modified: / 4.2.1998 / 22:08:19 / cg" |
|
203 | 2123 |
! ! |
2124 |
||
2151 | 2125 |
!JavaClass methodsFor:'support - refactorings'! |
2126 |
||
2127 |
directlyDefinesMethod: aSelector |
|
2128 |
||
2129 |
^self methodDictionary includes: aSelector. |
|
2130 |
||
2131 |
"Created: / 16-03-2011 / 14:21:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2132 |
! |
|
2133 |
||
2134 |
metaclass |
|
2135 |
||
2136 |
^self class |
|
2137 |
||
2138 |
"Created: / 16-03-2011 / 14:22:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2139 |
! ! |
|
2140 |
||
2141 |
!JavaClass methodsFor:'support - sUnit'! |
|
2142 |
||
2143 |
asTestCase |
|
2144 |
self isTestletLike |
|
2145 |
ifTrue: [^ TestletTestCaseProxy for: self ]. |
|
2146 |
^ JUnitTestCaseProxy for: self. |
|
2147 |
||
2148 |
"Created: / 04-03-2011 / 08:20:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2149 |
"Modified: / 29-04-2011 / 17:52:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2150 |
"Modified: / 07-05-2011 / 18:59:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2151 |
! |
|
2152 |
||
2153 |
asTestlet |
|
2154 |
^ TestletTestCaseProxy for: self |
|
2155 |
||
2156 |
"Created: / 29-04-2011 / 16:53:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2157 |
! |
|
2158 |
||
2159 |
buildSuite |
|
2160 |
self isTestletLike ifTrue: [ ^(TestletTestCaseProxy for: self) buildSuite ]. |
|
2161 |
^ (JUnitTestCaseProxy for: self) buildSuite |
|
2162 |
||
2163 |
"Created: / 29-05-2011 / 22:45:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2164 |
! |
|
2165 |
||
2166 |
isTestCaseLike |
|
2167 |
| junit_framework_TestCase org_junit_Test | |
|
2168 |
||
2169 |
"try JUnit 4.x" |
|
2170 |
[ org_junit_Test := JavaVM classForName: 'org.junit.Test' ] on: Error |
|
2171 |
do: |
|
2172 |
[ "nothing" |
|
2173 |
]. |
|
2174 |
(org_junit_Test notNil |
|
2175 |
and: [ self containsMethodsAnnotatedWith: org_junit_Test typeName ]) |
|
2176 |
ifTrue: [ ^ true ]. |
|
2177 |
"Try jUnit 3.x" |
|
2178 |
||
2179 |
[ junit_framework_TestCase := JavaVM |
|
2180 |
classForName: 'junit.framework.TestCase' ] on: Error |
|
2181 |
do: |
|
2182 |
[ "nothing" |
|
2183 |
]. |
|
2184 |
junit_framework_TestCase ifNotNil: |
|
2185 |
[ self == org_junit_Test ifTrue: [ ^ false ]. |
|
2186 |
(self includesBehavior: junit_framework_TestCase) ifTrue: [ ^ true ] ]. |
|
2187 |
^ self isTestletLike. |
|
2188 |
||
2189 |
" |
|
2190 |
JAVA::java::lang::Object isTestCaseLike |
|
2191 |
JAVA::stx::libjava::tests::junit::JUnit3Tests isTestCaseLike" |
|
2192 |
||
2193 |
"Created: / 28-02-2011 / 21:31:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2194 |
"Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>" |
|
2195 |
"Modified: / 06-03-2011 / 14:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2196 |
"Modified: / 29-05-2011 / 22:48:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2197 |
! |
|
2198 |
||
2199 |
isTestSelector: selector |
|
2200 |
||
2201 |
"Hack, you're right, blame on me" |
|
2202 |
||
2203 |
| junit_framework_TestCase m | |
|
2204 |
||
2205 |
((selector == #'test(Lgnu/testlet/TestHarness;)V') |
|
2206 |
and:[self ~~ (Java at:'gnu.testlet.Testlet')]) |
|
2207 |
ifTrue:[^true]. |
|
2208 |
||
2209 |
||
2210 |
junit_framework_TestCase := Java at:'junit.framework.TestCase'. |
|
2211 |
(junit_framework_TestCase notNil and: |
|
2212 |
[self includesBehavior:junit_framework_TestCase]) |
|
2213 |
ifTrue:[^selector startsWith: 'test']. |
|
2214 |
||
2215 |
m := self lookupSelector: selector. |
|
2216 |
"Sorry fo that, but I need this method to be fast" |
|
2217 |
^m annotations runtimeVisible includesKey: 'Lorg/junit/Test;'. |
|
2218 |
||
2219 |
"Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>" |
|
2220 |
"Created: / 04-03-2011 / 07:07:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2221 |
! |
|
2222 |
||
2223 |
isTestletLike |
|
2224 |
| testlet | |
|
2225 |
||
2226 |
||
2227 |
[ testlet := JavaVM classForName: 'gnu.testlet.Testlet' ] on: Error |
|
2228 |
do: |
|
2229 |
[ "nothing" |
|
2230 |
]. |
|
2231 |
testlet ifNil:[^ false]. |
|
2232 |
self == testlet ifTrue: [ ^ false ]. |
|
2233 |
(self includesBehavior: testlet) ifTrue: [ ^ true ]. |
|
2234 |
^ false. |
|
2235 |
||
2236 |
"Modified: / 02-03-2011 / 23:08:02 / Marcel Hlopko <hlopik@gmail.com>" |
|
2237 |
"Modified: / 06-03-2011 / 14:27:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2238 |
"Created: / 29-04-2011 / 17:02:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2239 |
! ! |
|
2240 |
||
130 | 2241 |
!JavaClass class methodsFor:'documentation'! |
1 | 2242 |
|
2243 |
version |
|
2151 | 2244 |
^ '$Id: JavaClass.st,v 1.127 2011-08-18 18:42:48 vrany Exp $' |
2245 |
! |
|
2246 |
||
2247 |
version_SVN |
|
2248 |
^ '$Id: JavaClass.st,v 1.127 2011-08-18 18:42:48 vrany Exp $' |
|
1 | 2249 |
! ! |
2151 | 2250 |
|
2251 |
JavaClass initialize! |