26
|
1 |
Object subclass:#JavaObject
|
|
2 |
instanceVariableNames:''
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Java-Classes'
|
|
6 |
!
|
|
7 |
|
|
8 |
|
133
|
9 |
!JavaObject class methodsFor:'misc'!
|
29
|
10 |
|
|
11 |
resolveClassRefs
|
54
|
12 |
!
|
|
13 |
|
|
14 |
resolveClassRefsIgnoring:setOfClasses
|
29
|
15 |
! !
|
|
16 |
|
133
|
17 |
!JavaObject class methodsFor:'smalltalk interface'!
|
29
|
18 |
|
|
19 |
convertJavaObject:val signature:retValSignature
|
91
|
20 |
^ val.
|
206
|
21 |
|
29
|
22 |
retValSignature = 'void' ifTrue:[
|
|
23 |
^ #void
|
|
24 |
].
|
|
25 |
retValSignature = 'boolean' ifTrue:[
|
|
26 |
val == 0 ifTrue:[^ false].
|
|
27 |
^ true
|
|
28 |
].
|
|
29 |
retValSignature = 'int' ifTrue:[
|
|
30 |
val isInteger ifFalse:[
|
|
31 |
self halt
|
|
32 |
].
|
|
33 |
^ val
|
|
34 |
].
|
34
|
35 |
retValSignature = 'char[]' ifTrue:[
|
|
36 |
"/ these are ST-strings
|
|
37 |
^ val
|
|
38 |
].
|
|
39 |
|
|
40 |
retValSignature = 'char' ifTrue:[
|
|
41 |
"/ these are ST-characters
|
40
|
42 |
val isInteger ifTrue:[
|
|
43 |
^ Character value:val
|
|
44 |
].
|
|
45 |
self halt.
|
34
|
46 |
^ val
|
|
47 |
].
|
|
48 |
|
29
|
49 |
retValSignature = 'Object' ifTrue:[
|
|
50 |
^ val
|
|
51 |
].
|
|
52 |
|
44
|
53 |
retValSignature = 'String' ifTrue:[
|
206
|
54 |
^ Java as_ST_String:val
|
44
|
55 |
].
|
|
56 |
|
29
|
57 |
'no conversion for: ' print. val class name print. ' to: ' print. retValSignature printNL.
|
|
58 |
^ val.
|
43
|
59 |
|
206
|
60 |
"Modified: 8.8.1997 / 12:07:23 / cg"
|
29
|
61 |
!
|
|
62 |
|
43
|
63 |
javaStringFrom:aString
|
|
64 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
65 |
|
206
|
66 |
self halt.
|
|
67 |
^ Java as_String:aString
|
43
|
68 |
|
206
|
69 |
"Modified: 7.8.1997 / 21:17:32 / cg"
|
44
|
70 |
!
|
|
71 |
|
|
72 |
stringFromJavaString:aJavaString
|
|
73 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
74 |
|
206
|
75 |
self halt.
|
|
76 |
^ Java as_ST_String:aJavaString
|
139
|
77 |
|
206
|
78 |
"Modified: 8.8.1997 / 12:07:29 / cg"
|
43
|
79 |
! !
|
|
80 |
|
|
81 |
!JavaObject methodsFor:'initialization'!
|
|
82 |
|
52
|
83 |
initializeFields:initialValues
|
|
84 |
|sz|
|
|
85 |
|
|
86 |
sz := self class instSize.
|
|
87 |
1 to:sz do:[:i |
|
|
88 |
self instVarAt:i put:(initialValues at:i)
|
|
89 |
]
|
|
90 |
!
|
|
91 |
|
43
|
92 |
initializeToZero
|
52
|
93 |
|sz|
|
|
94 |
|
|
95 |
sz := self class instSize.
|
|
96 |
1 to:sz do:[:i |
|
43
|
97 |
self instVarAt:i put:0
|
|
98 |
]
|
|
99 |
! !
|
|
100 |
|
175
|
101 |
!JavaObject methodsFor:'interpreter interface'!
|
|
102 |
|
|
103 |
invoke:selector interpreter:i sender:aContext
|
|
104 |
"send a message, without args"
|
|
105 |
|
|
106 |
|method cls sel|
|
|
107 |
|
|
108 |
method := self lookupMethod:selector numArgs:0.
|
|
109 |
method notNil ifTrue:[
|
|
110 |
^ self
|
|
111 |
invokeJavaMethod:method
|
|
112 |
interpreter:i
|
|
113 |
sender:aContext
|
|
114 |
selector:selector
|
|
115 |
].
|
|
116 |
|
|
117 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
118 |
|
|
119 |
"
|
|
120 |
|stack|
|
|
121 |
|
|
122 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
123 |
stack invoke:#'<init>'.
|
|
124 |
"
|
|
125 |
"
|
|
126 |
|stack|
|
|
127 |
|
|
128 |
stack := (Java at:'java/util/Stack') new.
|
|
129 |
stack invoke:#isEmpty.
|
|
130 |
"
|
|
131 |
"
|
|
132 |
|stack|
|
|
133 |
|
|
134 |
stack := (Java at:'java/util/Stack') new.
|
|
135 |
stack invoke:#size.
|
|
136 |
"
|
|
137 |
|
193
|
138 |
"Modified: 1.8.1997 / 21:50:53 / cg"
|
175
|
139 |
!
|
|
140 |
|
|
141 |
invoke:selector interpreter:i sender:aContext with:argument
|
|
142 |
"send a message, with 1 argument.
|
|
143 |
TEMPORARY: This method needs more work."
|
|
144 |
|
|
145 |
|sel method cls argClass jSel|
|
|
146 |
|
|
147 |
sel := selector asSymbolIfInterned.
|
|
148 |
sel notNil ifTrue:[
|
|
149 |
"/
|
|
150 |
"/ hard to do - must find a matching method probably
|
|
151 |
"/
|
|
152 |
(argument isKindOf:JavaObject) ifTrue:[
|
|
153 |
argClass := argument class.
|
|
154 |
] ifFalse:[
|
|
155 |
"/
|
|
156 |
"/ map to Java:
|
|
157 |
"/ String -> [c
|
|
158 |
"/
|
|
159 |
(argument isMemberOf:String) ifTrue:[
|
|
160 |
jSel := (selector , '([C)V') asSymbolIfInterned.
|
|
161 |
jSel notNil ifTrue:[
|
|
162 |
^ self
|
|
163 |
invoke:jSel
|
|
164 |
interpreter:i
|
|
165 |
sender:aContext
|
|
166 |
with:argument
|
|
167 |
]
|
|
168 |
]
|
|
169 |
].
|
|
170 |
|
|
171 |
method := self lookupMethod:sel numArgs:1.
|
|
172 |
method notNil ifTrue:[
|
|
173 |
^ self
|
|
174 |
invokeJavaMethod:method
|
|
175 |
interpreter:i
|
|
176 |
sender:aContext
|
|
177 |
selector:sel
|
|
178 |
with:argument
|
|
179 |
].
|
|
180 |
|
|
181 |
"/ cls := self class.
|
|
182 |
"/ [cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
183 |
"/ cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
|
184 |
"/ aMethod name == sel ifTrue:[
|
|
185 |
"/ aMethod numArgs == 1 ifTrue:[
|
|
186 |
"/ "/
|
|
187 |
"/ "/ this is not completely correct:
|
|
188 |
"/ "/ must look for the best type-match,
|
|
189 |
"/ "/ (especially: have to look for best match
|
|
190 |
"/ "/ over whole superclass chain ...)
|
|
191 |
"/ "/ for now take the first with matching number of args
|
|
192 |
"/ "/
|
|
193 |
"/ ^ self invokeJavaMethod:aMethod with:argument
|
|
194 |
"/ ]
|
|
195 |
"/ ]
|
|
196 |
"/ ].
|
|
197 |
"/ cls := cls superclass.
|
|
198 |
"/ ].
|
|
199 |
].
|
|
200 |
|
|
201 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
202 |
|
|
203 |
"
|
|
204 |
|stack|
|
|
205 |
|
|
206 |
stack := (Java at:'java/util/Stack') new.
|
|
207 |
stack invoke:#push with:1.
|
|
208 |
"
|
|
209 |
"
|
|
210 |
|stack|
|
|
211 |
|
|
212 |
stack := (Java at:'java/util/Stack') new.
|
|
213 |
stack invoke:#push with:1.
|
|
214 |
stack invoke:#push with:2.
|
|
215 |
stack invoke:#pop.
|
|
216 |
stack invoke:#pop.
|
|
217 |
stack invoke:#pop.
|
|
218 |
"
|
|
219 |
|
197
|
220 |
"Modified: 5.8.1997 / 02:52:42 / cg"
|
175
|
221 |
!
|
|
222 |
|
|
223 |
invoke:selector interpreter:i sender:aContext with:arg1 with:arg2
|
|
224 |
"send a message, with 2 arguments.
|
|
225 |
TEMPORARY: This method needs more work."
|
|
226 |
|
|
227 |
|sel method cls argClass jSel|
|
|
228 |
|
|
229 |
sel := selector asSymbolIfInterned.
|
|
230 |
sel notNil ifTrue:[
|
|
231 |
method := self lookupMethod:sel numArgs:2.
|
|
232 |
method notNil ifTrue:[
|
|
233 |
^ self
|
|
234 |
invokeJavaMethod:method
|
|
235 |
interpreter:i
|
|
236 |
sender:aContext
|
|
237 |
selector:selector
|
|
238 |
with:arg1 with:arg2
|
|
239 |
].
|
|
240 |
].
|
|
241 |
|
|
242 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
243 |
|
|
244 |
"Modified: 30.7.1997 / 13:47:05 / cg"
|
|
245 |
!
|
|
246 |
|
|
247 |
invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3
|
|
248 |
"send a message, with 3 arguments.
|
|
249 |
TEMPORARY: This method needs more work."
|
|
250 |
|
|
251 |
|sel method cls argClass jSel|
|
|
252 |
|
|
253 |
sel := selector asSymbolIfInterned.
|
|
254 |
sel notNil ifTrue:[
|
|
255 |
method := self lookupMethod:sel numArgs:3.
|
|
256 |
method notNil ifTrue:[
|
|
257 |
^ self
|
|
258 |
invokeJavaMethod:method
|
|
259 |
interpreter:i
|
|
260 |
sender:aContext
|
|
261 |
selector:selector
|
|
262 |
with:arg1 with:arg2 with:arg3
|
|
263 |
].
|
|
264 |
].
|
|
265 |
|
|
266 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
267 |
|
|
268 |
"Modified: 30.7.1997 / 13:47:22 / cg"
|
|
269 |
!
|
|
270 |
|
|
271 |
invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4
|
|
272 |
"send a message, with 4 arguments.
|
|
273 |
TEMPORARY: This method needs more work."
|
|
274 |
|
|
275 |
|sel method cls argClass jSel|
|
|
276 |
|
|
277 |
sel := selector asSymbolIfInterned.
|
|
278 |
sel notNil ifTrue:[
|
|
279 |
method := self lookupMethod:sel numArgs:4.
|
|
280 |
method notNil ifTrue:[
|
|
281 |
^ self
|
|
282 |
invokeJavaMethod:method
|
|
283 |
interpreter:i
|
|
284 |
sender:aContext
|
|
285 |
selector:selector
|
|
286 |
with:arg1 with:arg2 with:arg3 with:arg4
|
|
287 |
].
|
|
288 |
].
|
|
289 |
|
|
290 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
291 |
|
|
292 |
"Modified: 30.7.1997 / 13:47:45 / cg"
|
|
293 |
!
|
|
294 |
|
197
|
295 |
invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
|
|
296 |
"send a message, with 5 arguments.
|
|
297 |
TEMPORARY: This method needs more work."
|
|
298 |
|
|
299 |
|sel method cls argClass jSel|
|
|
300 |
|
|
301 |
sel := selector asSymbolIfInterned.
|
|
302 |
sel notNil ifTrue:[
|
|
303 |
method := self lookupMethod:sel numArgs:5.
|
|
304 |
method notNil ifTrue:[
|
|
305 |
^ self
|
|
306 |
invokeJavaMethod:method
|
|
307 |
interpreter:i
|
|
308 |
sender:aContext
|
|
309 |
selector:selector
|
|
310 |
with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
|
|
311 |
].
|
|
312 |
].
|
|
313 |
|
|
314 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
315 |
|
|
316 |
"Modified: 3.8.1997 / 20:31:03 / cg"
|
|
317 |
!
|
|
318 |
|
206
|
319 |
invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
|
|
320 |
"send a message, with 6 arguments.
|
|
321 |
TEMPORARY: This method needs more work."
|
|
322 |
|
|
323 |
|sel method cls argClass jSel|
|
|
324 |
|
|
325 |
sel := selector asSymbolIfInterned.
|
|
326 |
sel notNil ifTrue:[
|
|
327 |
method := self lookupMethod:sel numArgs:6.
|
|
328 |
method notNil ifTrue:[
|
|
329 |
^ self
|
|
330 |
invokeJavaMethod:method
|
|
331 |
interpreter:i
|
|
332 |
sender:aContext
|
|
333 |
selector:selector
|
|
334 |
with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
|
|
335 |
].
|
|
336 |
].
|
|
337 |
|
|
338 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
339 |
|
|
340 |
"Modified: 3.8.1997 / 20:31:03 / cg"
|
|
341 |
"Created: 7.8.1997 / 20:57:12 / cg"
|
|
342 |
!
|
|
343 |
|
175
|
344 |
invoke:selector interpreter:i sender:aContext withAll:arguments
|
|
345 |
"send a message, with arguments.
|
|
346 |
TEMPORARY: This method needs more work."
|
|
347 |
|
|
348 |
|sel method cls argClass jSel|
|
|
349 |
|
|
350 |
sel := selector asSymbolIfInterned.
|
|
351 |
sel notNil ifTrue:[
|
|
352 |
method := self lookupMethod:sel numArgs:arguments size.
|
|
353 |
method notNil ifTrue:[
|
|
354 |
^ self
|
|
355 |
invokeJavaMethod:method
|
|
356 |
interpreter:i
|
|
357 |
sender:aContext
|
|
358 |
selector:selector
|
|
359 |
withAll:arguments
|
|
360 |
].
|
|
361 |
].
|
|
362 |
|
|
363 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
364 |
|
|
365 |
"Modified: 30.7.1997 / 13:48:02 / cg"
|
|
366 |
! !
|
|
367 |
|
43
|
368 |
!JavaObject methodsFor:'message sending'!
|
|
369 |
|
133
|
370 |
doesNotUnderstand:aMessage
|
144
|
371 |
|args numArgs javaMethod sel arg1 arg2|
|
133
|
372 |
|
|
373 |
args := aMessage arguments.
|
|
374 |
numArgs := args size.
|
144
|
375 |
sel := aMessage selector.
|
133
|
376 |
|
|
377 |
numArgs == 0 ifTrue:[
|
144
|
378 |
^ self invoke:sel.
|
133
|
379 |
].
|
144
|
380 |
arg1 := args at:1.
|
133
|
381 |
numArgs == 1 ifTrue:[
|
144
|
382 |
^ self invoke:sel with:arg1.
|
133
|
383 |
].
|
144
|
384 |
arg2 := args at:2.
|
133
|
385 |
numArgs == 2 ifTrue:[
|
144
|
386 |
^ self invoke:sel with:arg1 with:arg2.
|
133
|
387 |
].
|
|
388 |
^ super doesNotUnderstand:aMessage
|
|
389 |
|
193
|
390 |
"Modified: 1.8.1997 / 21:42:31 / cg"
|
43
|
391 |
!
|
|
392 |
|
175
|
393 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel
|
|
394 |
"invoke a java method, without arguments."
|
54
|
395 |
|
101
|
396 |
|val|
|
54
|
397 |
|
|
398 |
aJavaMethod numArgs ~~ 0 ifTrue:[
|
175
|
399 |
self halt:'argument count'
|
54
|
400 |
].
|
|
401 |
aJavaMethod isStatic ifTrue:[
|
|
402 |
self halt:'static function'
|
|
403 |
].
|
|
404 |
|
175
|
405 |
val := aJavaMethod valueWithReceiver:self arguments:#() selector:sel.
|
|
406 |
val notNil ifTrue:[^ val].
|
|
407 |
|
54
|
408 |
i push:self.
|
78
|
409 |
|
175
|
410 |
val := i interpret:aJavaMethod sender:s.
|
54
|
411 |
|
|
412 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
175
|
413 |
|
|
414 |
"Modified: 30.7.1997 / 13:20:29 / cg"
|
|
415 |
"Created: 30.7.1997 / 13:37:25 / cg"
|
54
|
416 |
!
|
|
417 |
|
175
|
418 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1
|
101
|
419 |
"invoke a java method, with two arguments.
|
|
420 |
CAVEAT: these cannot be long or doubles currently."
|
43
|
421 |
|
101
|
422 |
|val|
|
43
|
423 |
|
|
424 |
aJavaMethod numArgs ~~ 1 ifTrue:[
|
|
425 |
self halt:'argument count'
|
|
426 |
].
|
|
427 |
aJavaMethod isStatic ifTrue:[
|
|
428 |
self halt:'static function'
|
|
429 |
].
|
|
430 |
|
175
|
431 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1) selector:sel.
|
|
432 |
val notNil ifTrue:[^ val].
|
|
433 |
|
43
|
434 |
i push:self.
|
101
|
435 |
i push:arg1.
|
43
|
436 |
|
101
|
437 |
val := i interpret:aJavaMethod sender:s.
|
43
|
438 |
|
|
439 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
440 |
|
175
|
441 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
442 |
"Created: 30.7.1997 / 13:41:01 / cg"
|
|
443 |
!
|
|
444 |
|
|
445 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2
|
|
446 |
"invoke a java method, with two arguments.
|
|
447 |
CAVEAT: these cannot be long or doubles currently."
|
|
448 |
|
|
449 |
|val|
|
|
450 |
|
|
451 |
aJavaMethod numArgs ~~ 2 ifTrue:[
|
|
452 |
self halt:'argument count'
|
|
453 |
].
|
|
454 |
aJavaMethod isStatic ifTrue:[
|
|
455 |
self halt:'static function'
|
|
456 |
].
|
|
457 |
|
|
458 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) selector:sel.
|
|
459 |
val notNil ifTrue:[^ val].
|
|
460 |
|
|
461 |
i push:self.
|
|
462 |
i push:arg1.
|
|
463 |
i push:arg2.
|
|
464 |
|
|
465 |
val := i interpret:aJavaMethod sender:s.
|
|
466 |
|
|
467 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
468 |
|
|
469 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
470 |
"Created: 30.7.1997 / 13:36:02 / cg"
|
44
|
471 |
!
|
|
472 |
|
202
|
473 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4
|
|
474 |
"invoke a java method, with 4 arguments.
|
|
475 |
CAVEAT: these cannot be long or doubles currently."
|
|
476 |
|
|
477 |
|val|
|
|
478 |
|
|
479 |
aJavaMethod numArgs ~~ 4 ifTrue:[
|
|
480 |
self halt:'argument count'
|
|
481 |
].
|
|
482 |
aJavaMethod isStatic ifTrue:[
|
|
483 |
self halt:'static function'
|
|
484 |
].
|
|
485 |
|
|
486 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) selector:sel.
|
|
487 |
val notNil ifTrue:[^ val].
|
|
488 |
|
|
489 |
i push:self.
|
|
490 |
i push:arg1.
|
|
491 |
i push:arg2.
|
|
492 |
i push:arg3.
|
|
493 |
i push:arg4.
|
|
494 |
|
|
495 |
val := i interpret:aJavaMethod sender:s.
|
|
496 |
|
|
497 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
498 |
|
|
499 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
500 |
"Created: 6.8.1997 / 02:41:32 / cg"
|
|
501 |
!
|
|
502 |
|
197
|
503 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
|
|
504 |
"invoke a java method, with 5 arguments.
|
|
505 |
CAVEAT: these cannot be long or doubles currently."
|
|
506 |
|
|
507 |
|val|
|
|
508 |
|
|
509 |
aJavaMethod numArgs ~~ 5 ifTrue:[
|
|
510 |
self halt:'argument count'
|
|
511 |
].
|
|
512 |
aJavaMethod isStatic ifTrue:[
|
|
513 |
self halt:'static function'
|
|
514 |
].
|
|
515 |
|
|
516 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) selector:sel.
|
|
517 |
val notNil ifTrue:[^ val].
|
|
518 |
|
|
519 |
i push:self.
|
|
520 |
i push:arg1.
|
|
521 |
i push:arg2.
|
|
522 |
i push:arg3.
|
|
523 |
i push:arg4.
|
|
524 |
i push:arg5.
|
|
525 |
|
|
526 |
val := i interpret:aJavaMethod sender:s.
|
|
527 |
|
|
528 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
529 |
|
|
530 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
531 |
"Created: 3.8.1997 / 20:32:03 / cg"
|
|
532 |
!
|
|
533 |
|
206
|
534 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
|
|
535 |
"invoke a java method, with 6 arguments.
|
|
536 |
CAVEAT: these cannot be long or doubles currently."
|
|
537 |
|
|
538 |
|val|
|
|
539 |
|
|
540 |
aJavaMethod numArgs ~~ 6 ifTrue:[
|
|
541 |
self halt:'argument count'
|
|
542 |
].
|
|
543 |
aJavaMethod isStatic ifTrue:[
|
|
544 |
self halt:'static function'
|
|
545 |
].
|
|
546 |
|
|
547 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) selector:sel.
|
|
548 |
val notNil ifTrue:[^ val].
|
|
549 |
|
|
550 |
i push:self.
|
|
551 |
i push:arg1.
|
|
552 |
i push:arg2.
|
|
553 |
i push:arg3.
|
|
554 |
i push:arg4.
|
|
555 |
i push:arg5.
|
|
556 |
i push:arg6.
|
|
557 |
|
|
558 |
val := i interpret:aJavaMethod sender:s.
|
|
559 |
|
|
560 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
561 |
|
|
562 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
563 |
"Created: 7.8.1997 / 20:57:55 / cg"
|
|
564 |
!
|
|
565 |
|
101
|
566 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2
|
78
|
567 |
"invoke a java method, with two arguments.
|
|
568 |
CAVEAT: these cannot be long or doubles currently."
|
44
|
569 |
|
101
|
570 |
|val|
|
44
|
571 |
|
|
572 |
aJavaMethod numArgs ~~ 2 ifTrue:[
|
|
573 |
self halt:'argument count'
|
|
574 |
].
|
|
575 |
aJavaMethod isStatic ifTrue:[
|
|
576 |
self halt:'static function'
|
|
577 |
].
|
|
578 |
|
175
|
579 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2).
|
|
580 |
val notNil ifTrue:[^ val].
|
|
581 |
|
44
|
582 |
i push:self.
|
|
583 |
i push:arg1.
|
|
584 |
i push:arg2.
|
|
585 |
|
101
|
586 |
val := i interpret:aJavaMethod sender:s.
|
44
|
587 |
|
|
588 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
589 |
|
175
|
590 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
83
|
591 |
!
|
|
592 |
|
113
|
593 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2 with:arg3
|
|
594 |
"invoke a java method, with 3 arguments.
|
|
595 |
CAVEAT: these cannot be long or doubles currently."
|
|
596 |
|
|
597 |
|val|
|
|
598 |
|
|
599 |
aJavaMethod numArgs ~~ 3 ifTrue:[
|
|
600 |
self halt:'argument count'
|
|
601 |
].
|
|
602 |
aJavaMethod isStatic ifTrue:[
|
|
603 |
self halt:'static function'
|
|
604 |
].
|
|
605 |
|
175
|
606 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3).
|
|
607 |
val notNil ifTrue:[^ val].
|
|
608 |
|
113
|
609 |
i push:self.
|
|
610 |
i push:arg1.
|
|
611 |
i push:arg2.
|
|
612 |
i push:arg3.
|
|
613 |
|
|
614 |
val := i interpret:aJavaMethod sender:s.
|
|
615 |
|
|
616 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
617 |
|
175
|
618 |
"Modified: 30.7.1997 / 13:20:44 / cg"
|
113
|
619 |
!
|
|
620 |
|
112
|
621 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2 with:arg3 with:arg4
|
|
622 |
"invoke a java method, with 4 arguments.
|
|
623 |
CAVEAT: these cannot be long or doubles currently."
|
|
624 |
|
|
625 |
|val|
|
|
626 |
|
|
627 |
aJavaMethod numArgs ~~ 4 ifTrue:[
|
|
628 |
self halt:'argument count'
|
|
629 |
].
|
|
630 |
aJavaMethod isStatic ifTrue:[
|
|
631 |
self halt:'static function'
|
|
632 |
].
|
|
633 |
|
175
|
634 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4).
|
|
635 |
val notNil ifTrue:[^ val].
|
|
636 |
|
112
|
637 |
i push:self.
|
|
638 |
i push:arg1.
|
|
639 |
i push:arg2.
|
|
640 |
i push:arg3.
|
|
641 |
i push:arg4.
|
|
642 |
|
|
643 |
val := i interpret:aJavaMethod sender:s.
|
|
644 |
|
|
645 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
646 |
|
175
|
647 |
"Modified: 30.7.1997 / 13:20:51 / cg"
|
112
|
648 |
!
|
|
649 |
|
101
|
650 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s withAll:args
|
|
651 |
"invoke a java method, with two arguments.
|
83
|
652 |
CAVEAT: these cannot be long or doubles currently."
|
|
653 |
|
101
|
654 |
|val|
|
83
|
655 |
|
101
|
656 |
aJavaMethod numArgs ~~ args size ifTrue:[
|
83
|
657 |
self halt:'argument count'
|
|
658 |
].
|
|
659 |
aJavaMethod isStatic ifTrue:[
|
|
660 |
self halt:'static function'
|
|
661 |
].
|
|
662 |
|
175
|
663 |
val := aJavaMethod valueWithReceiver:self arguments:args.
|
|
664 |
val notNil ifTrue:[^ val].
|
|
665 |
|
83
|
666 |
i push:self.
|
101
|
667 |
args do:[:arg |
|
|
668 |
i push:arg.
|
|
669 |
].
|
83
|
670 |
|
101
|
671 |
val := i interpret:aJavaMethod sender:s.
|
83
|
672 |
|
|
673 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
674 |
|
175
|
675 |
"Modified: 30.7.1997 / 13:20:58 / cg"
|
101
|
676 |
!
|
|
677 |
|
|
678 |
invokeJavaMethod:aJavaMethod with:arg1 with:arg2
|
|
679 |
"invoke a java method, with two arguments.
|
|
680 |
CAVEAT: these cannot be long or doubles currently."
|
|
681 |
|
175
|
682 |
^ self
|
|
683 |
invokeJavaMethod:aJavaMethod
|
|
684 |
interpreter:JavaInterpreter new
|
|
685 |
sender:thisContext sender
|
|
686 |
with:arg1
|
|
687 |
with:arg2
|
101
|
688 |
|
175
|
689 |
"Modified: 30.7.1997 / 13:25:36 / cg"
|
43
|
690 |
! !
|
|
691 |
|
|
692 |
!JavaObject methodsFor:'printing & storing'!
|
|
693 |
|
|
694 |
displayString
|
166
|
695 |
self class == Java java_lang_String ifTrue:[
|
206
|
696 |
^ '''' , (Java as_ST_String:self) , ''''
|
48
|
697 |
].
|
|
698 |
|
101
|
699 |
^ super displayString.
|
|
700 |
|
96
|
701 |
Object errorSignal handle:[:ex |
|
|
702 |
^ super displayString.
|
|
703 |
] do:[
|
206
|
704 |
^ Java as_ST_String:(self invoke:#toString).
|
96
|
705 |
].
|
|
706 |
|
43
|
707 |
^ super displayString. "/ ^ 'a JavaObject(' , self class name , ')'
|
166
|
708 |
|
206
|
709 |
"Modified: 8.8.1997 / 12:07:36 / cg"
|
168
|
710 |
!
|
|
711 |
|
|
712 |
javaDisplayString
|
|
713 |
Object errorSignal handle:[:ex |
|
|
714 |
ex return.
|
|
715 |
] do:[
|
206
|
716 |
^ Java as_ST_String:(self invoke:#toString).
|
168
|
717 |
].
|
|
718 |
|
|
719 |
^ super displayString.
|
|
720 |
|
|
721 |
"Created: 7.4.1997 / 17:38:13 / cg"
|
206
|
722 |
"Modified: 8.8.1997 / 12:07:39 / cg"
|
166
|
723 |
! !
|
|
724 |
|
|
725 |
!JavaObject methodsFor:'queries'!
|
|
726 |
|
|
727 |
isJavaObject
|
|
728 |
^ true
|
|
729 |
|
|
730 |
"Created: 26.3.1997 / 13:34:17 / cg"
|
43
|
731 |
! !
|
|
732 |
|
|
733 |
!JavaObject methodsFor:'smalltalk interface'!
|
|
734 |
|
29
|
735 |
invoke:selector
|
|
736 |
"send a message, without args"
|
|
737 |
|
175
|
738 |
^ self
|
|
739 |
invoke:selector
|
|
740 |
interpreter:(JavaInterpreter new)
|
|
741 |
sender:thisContext sender
|
29
|
742 |
|
|
743 |
"
|
|
744 |
|stack|
|
|
745 |
|
|
746 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
747 |
stack invoke:#'<init>'.
|
|
748 |
"
|
|
749 |
"
|
|
750 |
|stack|
|
|
751 |
|
43
|
752 |
stack := (Java at:'java/util/Stack') new.
|
29
|
753 |
stack invoke:#isEmpty.
|
|
754 |
"
|
|
755 |
"
|
|
756 |
|stack|
|
|
757 |
|
43
|
758 |
stack := (Java at:'java/util/Stack') new.
|
29
|
759 |
stack invoke:#size.
|
|
760 |
"
|
133
|
761 |
|
175
|
762 |
"Modified: 30.7.1997 / 13:44:34 / cg"
|
29
|
763 |
!
|
|
764 |
|
175
|
765 |
invoke:selector sender:aContext
|
|
766 |
"send a message, without args"
|
|
767 |
|
|
768 |
^ self
|
|
769 |
invoke:selector
|
|
770 |
interpreter:(JavaInterpreter new)
|
|
771 |
sender:aContext
|
|
772 |
|
|
773 |
"Modified: 30.7.1997 / 13:59:18 / cg"
|
|
774 |
!
|
|
775 |
|
|
776 |
invoke:selector with:arg
|
43
|
777 |
"send a message, with 1 argument.
|
|
778 |
TEMPORARY: This method needs more work."
|
33
|
779 |
|
175
|
780 |
^ self
|
|
781 |
invoke:selector
|
|
782 |
interpreter:JavaInterpreter new
|
|
783 |
sender:thisContext sender
|
|
784 |
with:arg
|
29
|
785 |
|
|
786 |
"
|
|
787 |
|stack|
|
|
788 |
|
33
|
789 |
stack := (Java at:'java/util/Stack') new.
|
29
|
790 |
stack invoke:#push with:1.
|
|
791 |
"
|
78
|
792 |
"
|
|
793 |
|stack|
|
|
794 |
|
|
795 |
stack := (Java at:'java/util/Stack') new.
|
|
796 |
stack invoke:#push with:1.
|
|
797 |
stack invoke:#push with:2.
|
|
798 |
stack invoke:#pop.
|
|
799 |
stack invoke:#pop.
|
|
800 |
stack invoke:#pop.
|
|
801 |
"
|
133
|
802 |
|
175
|
803 |
"Modified: 30.7.1997 / 13:44:44 / cg"
|
83
|
804 |
!
|
|
805 |
|
113
|
806 |
invoke:selector with:arg1 with:arg2
|
175
|
807 |
"send a message, with 2 argument.
|
113
|
808 |
TEMPORARY: This method needs more work."
|
|
809 |
|
|
810 |
^ self
|
|
811 |
invoke:selector
|
|
812 |
interpreter:JavaInterpreter new
|
|
813 |
sender:thisContext sender
|
|
814 |
with:arg1
|
|
815 |
with:arg2
|
|
816 |
|
175
|
817 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
818 |
!
|
|
819 |
|
|
820 |
invoke:selector with:arg1 with:arg2 with:arg3
|
|
821 |
"send a message, with 3 argument.
|
|
822 |
TEMPORARY: This method needs more work."
|
|
823 |
|
|
824 |
^ self
|
|
825 |
invoke:selector
|
|
826 |
interpreter:JavaInterpreter new
|
|
827 |
sender:thisContext sender
|
|
828 |
with:arg1
|
|
829 |
with:arg2
|
|
830 |
with:arg3
|
113
|
831 |
|
175
|
832 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
833 |
"Created: 30.7.1997 / 13:48:24 / cg"
|
|
834 |
!
|
|
835 |
|
202
|
836 |
invoke:selector with:arg1 with:arg2 with:arg3 with:arg4
|
|
837 |
"send a message, with 5 argument.
|
|
838 |
TEMPORARY: This method needs more work."
|
|
839 |
|
|
840 |
^ self
|
|
841 |
invoke:selector
|
|
842 |
interpreter:JavaInterpreter new
|
|
843 |
sender:thisContext sender
|
|
844 |
with:arg1
|
|
845 |
with:arg2
|
|
846 |
with:arg3
|
|
847 |
with:arg4
|
|
848 |
|
|
849 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
850 |
"Created: 6.8.1997 / 02:38:44 / cg"
|
|
851 |
!
|
|
852 |
|
197
|
853 |
invoke:selector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
|
|
854 |
"send a message, with 5 argument.
|
|
855 |
TEMPORARY: This method needs more work."
|
|
856 |
|
|
857 |
^ self
|
|
858 |
invoke:selector
|
|
859 |
interpreter:JavaInterpreter new
|
|
860 |
sender:thisContext sender
|
|
861 |
with:arg1
|
|
862 |
with:arg2
|
|
863 |
with:arg3
|
|
864 |
with:arg4
|
|
865 |
with:arg5
|
|
866 |
|
|
867 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
868 |
"Created: 3.8.1997 / 20:30:22 / cg"
|
|
869 |
!
|
|
870 |
|
206
|
871 |
invoke:selector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
|
|
872 |
"send a message, with 6 argument.
|
|
873 |
TEMPORARY: This method needs more work."
|
|
874 |
|
|
875 |
^ self
|
|
876 |
invoke:selector
|
|
877 |
interpreter:JavaInterpreter new
|
|
878 |
sender:thisContext sender
|
|
879 |
with:arg1
|
|
880 |
with:arg2
|
|
881 |
with:arg3
|
|
882 |
with:arg4
|
|
883 |
with:arg5
|
|
884 |
with:arg6
|
|
885 |
|
|
886 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
887 |
"Created: 7.8.1997 / 20:56:49 / cg"
|
|
888 |
!
|
|
889 |
|
175
|
890 |
invoke:selector withAll:args
|
|
891 |
"send a message, with anumber of arguments.
|
|
892 |
TEMPORARY: This method needs more work."
|
113
|
893 |
|
175
|
894 |
^ self
|
|
895 |
invoke:selector
|
|
896 |
interpreter:JavaInterpreter new
|
|
897 |
sender:thisContext sender
|
|
898 |
withAll:args
|
|
899 |
|
|
900 |
"Modified: 30.7.1997 / 13:44:58 / cg"
|
|
901 |
"Created: 30.7.1997 / 13:56:33 / cg"
|
113
|
902 |
!
|
|
903 |
|
78
|
904 |
lookupMethod:selector numArgs:nargs
|
|
905 |
"lookup a method"
|
|
906 |
|
|
907 |
|method cls sel|
|
|
908 |
|
133
|
909 |
sel := selector.
|
|
910 |
(sel includes:$:) ifTrue:[
|
|
911 |
sel := sel copyTo:(sel indexOf:$:)-1
|
|
912 |
].
|
|
913 |
|
|
914 |
sel := sel asSymbolIfInterned.
|
78
|
915 |
sel notNil ifTrue:[
|
|
916 |
cls := self class.
|
|
917 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
133
|
918 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod |
|
159
|
919 |
(jSel == sel ) ifTrue:[
|
|
920 |
^ aMethod
|
|
921 |
]
|
|
922 |
].
|
|
923 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod |
|
133
|
924 |
(aMethod name = sel
|
|
925 |
or:[aMethod signatureNameWithoutReturnType = sel]) ifTrue:[
|
78
|
926 |
aMethod numArgs == nargs ifTrue:[
|
|
927 |
^ aMethod
|
|
928 |
]
|
|
929 |
]
|
|
930 |
].
|
|
931 |
cls := cls superclass.
|
|
932 |
].
|
|
933 |
].
|
|
934 |
|
|
935 |
^ nil
|
|
936 |
|
|
937 |
"
|
|
938 |
|stack|
|
|
939 |
|
113
|
940 |
stack := (Java at:'java.util.Stack') basicNew.
|
78
|
941 |
stack lookupMethod:#'<init>' numArgs:0.
|
|
942 |
"
|
|
943 |
"
|
|
944 |
|stack|
|
|
945 |
|
113
|
946 |
stack := (Java at:'java.util.Stack') new.
|
78
|
947 |
stack lookupMethod:#isEmpty numArgs:0.
|
|
948 |
"
|
113
|
949 |
"
|
|
950 |
|frame|
|
|
951 |
|
|
952 |
frame := (Java at:'java.awt.Frame') new.
|
|
953 |
frame lookupMethod:#'<init> (String)' numArgs:1.
|
|
954 |
"
|
|
955 |
|
159
|
956 |
"Modified: 22.3.1997 / 00:56:54 / cg"
|
26
|
957 |
! !
|
|
958 |
|
133
|
959 |
!JavaObject class methodsFor:'documentation'!
|
26
|
960 |
|
|
961 |
version
|
206
|
962 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaObject.st,v 1.32 1997/08/08 11:34:22 cg Exp $'
|
26
|
963 |
! !
|