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