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