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:[
|
255
|
23 |
^ #void
|
29
|
24 |
].
|
|
25 |
retValSignature = 'boolean' ifTrue:[
|
255
|
26 |
val == 0 ifTrue:[^ false].
|
|
27 |
^ true
|
29
|
28 |
].
|
|
29 |
retValSignature = 'int' ifTrue:[
|
255
|
30 |
val isInteger ifFalse:[
|
|
31 |
self halt
|
|
32 |
].
|
|
33 |
^ val
|
29
|
34 |
].
|
34
|
35 |
retValSignature = 'char[]' ifTrue:[
|
255
|
36 |
"/ these are ST-strings
|
|
37 |
^ val
|
34
|
38 |
].
|
|
39 |
|
|
40 |
retValSignature = 'char' ifTrue:[
|
255
|
41 |
"/ these are ST-characters
|
|
42 |
val isInteger ifTrue:[
|
|
43 |
^ Character value:val
|
|
44 |
].
|
|
45 |
self halt.
|
|
46 |
^ val
|
34
|
47 |
].
|
|
48 |
|
29
|
49 |
retValSignature = 'Object' ifTrue:[
|
255
|
50 |
^ val
|
29
|
51 |
].
|
|
52 |
|
44
|
53 |
retValSignature = 'String' ifTrue:[
|
255
|
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 |
|
255
|
88 |
self instVarAt:i put:(initialValues at:i)
|
52
|
89 |
]
|
|
90 |
!
|
|
91 |
|
43
|
92 |
initializeToZero
|
52
|
93 |
|sz|
|
|
94 |
|
|
95 |
sz := self class instSize.
|
|
96 |
1 to:sz do:[:i |
|
255
|
97 |
self instVarAt:i put:0
|
43
|
98 |
]
|
|
99 |
! !
|
|
100 |
|
175
|
101 |
!JavaObject methodsFor:'interpreter interface'!
|
|
102 |
|
|
103 |
invoke:selector interpreter:i sender:aContext with:argument
|
|
104 |
"send a message, with 1 argument.
|
|
105 |
TEMPORARY: This method needs more work."
|
|
106 |
|
|
107 |
|sel method cls argClass jSel|
|
|
108 |
|
|
109 |
sel := selector asSymbolIfInterned.
|
|
110 |
sel notNil ifTrue:[
|
255
|
111 |
"/
|
|
112 |
"/ hard to do - must find a matching method probably
|
|
113 |
"/
|
|
114 |
(argument isKindOf:JavaObject) ifTrue:[
|
|
115 |
argClass := argument class.
|
|
116 |
] ifFalse:[
|
|
117 |
"/
|
|
118 |
"/ map to Java:
|
|
119 |
"/ String -> [c
|
|
120 |
"/
|
|
121 |
(argument isMemberOf:String) ifTrue:[
|
|
122 |
jSel := (selector , '([C)V') asSymbolIfInterned.
|
|
123 |
jSel notNil ifTrue:[
|
|
124 |
^ self
|
|
125 |
invoke:jSel
|
|
126 |
interpreter:i
|
|
127 |
sender:aContext
|
|
128 |
with:argument
|
|
129 |
]
|
|
130 |
]
|
|
131 |
].
|
175
|
132 |
|
255
|
133 |
method := JavaClass lookupMethod:sel numArgs:1 in:self class static:false.
|
|
134 |
"/ method := self lookupMethod:sel numArgs:1.
|
|
135 |
method notNil ifTrue:[
|
|
136 |
^ method
|
|
137 |
valueWithReceiver:self
|
|
138 |
arguments:(Array with:argument)
|
252
|
139 |
"/ ^ self
|
|
140 |
"/ invokeJavaMethod:method
|
|
141 |
"/ interpreter:i
|
|
142 |
"/ sender:aContext
|
|
143 |
"/ selector:sel
|
|
144 |
"/ with:argument
|
255
|
145 |
].
|
175
|
146 |
|
|
147 |
"/ cls := self class.
|
|
148 |
"/ [cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
149 |
"/ cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
|
150 |
"/ aMethod name == sel ifTrue:[
|
|
151 |
"/ aMethod numArgs == 1 ifTrue:[
|
|
152 |
"/ "/
|
|
153 |
"/ "/ this is not completely correct:
|
|
154 |
"/ "/ must look for the best type-match,
|
|
155 |
"/ "/ (especially: have to look for best match
|
|
156 |
"/ "/ over whole superclass chain ...)
|
|
157 |
"/ "/ for now take the first with matching number of args
|
|
158 |
"/ "/
|
|
159 |
"/ ^ self invokeJavaMethod:aMethod with:argument
|
|
160 |
"/ ]
|
|
161 |
"/ ]
|
|
162 |
"/ ].
|
|
163 |
"/ cls := cls superclass.
|
|
164 |
"/ ].
|
|
165 |
].
|
|
166 |
|
|
167 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
168 |
|
|
169 |
"
|
|
170 |
|stack|
|
|
171 |
|
|
172 |
stack := (Java at:'java/util/Stack') new.
|
|
173 |
stack invoke:#push with:1.
|
|
174 |
"
|
|
175 |
"
|
|
176 |
|stack|
|
|
177 |
|
|
178 |
stack := (Java at:'java/util/Stack') new.
|
|
179 |
stack invoke:#push with:1.
|
|
180 |
stack invoke:#push with:2.
|
|
181 |
stack invoke:#pop.
|
|
182 |
stack invoke:#pop.
|
|
183 |
stack invoke:#pop.
|
|
184 |
"
|
|
185 |
|
252
|
186 |
"Modified: / 5.1.1998 / 02:21:22 / cg"
|
175
|
187 |
! !
|
|
188 |
|
43
|
189 |
!JavaObject methodsFor:'message sending'!
|
|
190 |
|
133
|
191 |
doesNotUnderstand:aMessage
|
415
|
192 |
"as a courtesy to the smalltalker, try to map methods"
|
|
193 |
|
255
|
194 |
|args numArgs javaMethod sel|
|
133
|
195 |
|
|
196 |
args := aMessage arguments.
|
|
197 |
numArgs := args size.
|
144
|
198 |
sel := aMessage selector.
|
133
|
199 |
|
255
|
200 |
javaMethod := JavaClass lookupMethod:sel numArgs:numArgs in:self class static:false.
|
|
201 |
javaMethod notNil ifTrue:[
|
337
|
202 |
args notNil ifTrue:[
|
|
203 |
args := JavaClass convertArgsToJava:args.
|
|
204 |
].
|
|
205 |
^ javaMethod
|
|
206 |
valueWithReceiver:self
|
|
207 |
arguments:args
|
|
208 |
selector:sel
|
|
209 |
search:nil
|
|
210 |
sender:nil
|
133
|
211 |
].
|
|
212 |
^ super doesNotUnderstand:aMessage
|
|
213 |
|
415
|
214 |
"Modified: / 4.11.1998 / 17:10:43 / cg"
|
43
|
215 |
!
|
|
216 |
|
175
|
217 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel
|
|
218 |
"invoke a java method, without arguments."
|
54
|
219 |
|
101
|
220 |
|val|
|
54
|
221 |
|
|
222 |
aJavaMethod numArgs ~~ 0 ifTrue:[
|
255
|
223 |
self halt:'argument count'
|
54
|
224 |
].
|
|
225 |
aJavaMethod isStatic ifTrue:[
|
255
|
226 |
self halt:'static function'
|
54
|
227 |
].
|
|
228 |
|
175
|
229 |
val := aJavaMethod valueWithReceiver:self arguments:#() selector:sel.
|
|
230 |
val notNil ifTrue:[^ val].
|
|
231 |
|
54
|
232 |
i push:self.
|
78
|
233 |
|
175
|
234 |
val := i interpret:aJavaMethod sender:s.
|
54
|
235 |
|
|
236 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
175
|
237 |
|
|
238 |
"Modified: 30.7.1997 / 13:20:29 / cg"
|
|
239 |
"Created: 30.7.1997 / 13:37:25 / cg"
|
54
|
240 |
!
|
|
241 |
|
175
|
242 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1
|
101
|
243 |
"invoke a java method, with two arguments.
|
|
244 |
CAVEAT: these cannot be long or doubles currently."
|
43
|
245 |
|
101
|
246 |
|val|
|
43
|
247 |
|
|
248 |
aJavaMethod numArgs ~~ 1 ifTrue:[
|
255
|
249 |
self halt:'argument count'
|
43
|
250 |
].
|
|
251 |
aJavaMethod isStatic ifTrue:[
|
255
|
252 |
self halt:'static function'
|
43
|
253 |
].
|
|
254 |
|
175
|
255 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1) selector:sel.
|
|
256 |
val notNil ifTrue:[^ val].
|
|
257 |
|
43
|
258 |
i push:self.
|
101
|
259 |
i push:arg1.
|
43
|
260 |
|
101
|
261 |
val := i interpret:aJavaMethod sender:s.
|
43
|
262 |
|
|
263 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
264 |
|
175
|
265 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
266 |
"Created: 30.7.1997 / 13:41:01 / cg"
|
|
267 |
!
|
|
268 |
|
|
269 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2
|
|
270 |
"invoke a java method, with two arguments.
|
|
271 |
CAVEAT: these cannot be long or doubles currently."
|
|
272 |
|
|
273 |
|val|
|
|
274 |
|
|
275 |
aJavaMethod numArgs ~~ 2 ifTrue:[
|
255
|
276 |
self halt:'argument count'
|
175
|
277 |
].
|
|
278 |
aJavaMethod isStatic ifTrue:[
|
255
|
279 |
self halt:'static function'
|
175
|
280 |
].
|
|
281 |
|
|
282 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) selector:sel.
|
|
283 |
val notNil ifTrue:[^ val].
|
|
284 |
|
|
285 |
i push:self.
|
|
286 |
i push:arg1.
|
|
287 |
i push:arg2.
|
|
288 |
|
|
289 |
val := i interpret:aJavaMethod sender:s.
|
|
290 |
|
|
291 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
292 |
|
|
293 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
294 |
"Created: 30.7.1997 / 13:36:02 / cg"
|
44
|
295 |
!
|
|
296 |
|
202
|
297 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4
|
|
298 |
"invoke a java method, with 4 arguments.
|
|
299 |
CAVEAT: these cannot be long or doubles currently."
|
|
300 |
|
|
301 |
|val|
|
|
302 |
|
|
303 |
aJavaMethod numArgs ~~ 4 ifTrue:[
|
255
|
304 |
self halt:'argument count'
|
202
|
305 |
].
|
|
306 |
aJavaMethod isStatic ifTrue:[
|
255
|
307 |
self halt:'static function'
|
202
|
308 |
].
|
|
309 |
|
|
310 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) selector:sel.
|
|
311 |
val notNil ifTrue:[^ val].
|
|
312 |
|
|
313 |
i push:self.
|
|
314 |
i push:arg1.
|
|
315 |
i push:arg2.
|
|
316 |
i push:arg3.
|
|
317 |
i push:arg4.
|
|
318 |
|
|
319 |
val := i interpret:aJavaMethod sender:s.
|
|
320 |
|
|
321 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
322 |
|
|
323 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
324 |
"Created: 6.8.1997 / 02:41:32 / cg"
|
|
325 |
!
|
|
326 |
|
197
|
327 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
|
|
328 |
"invoke a java method, with 5 arguments.
|
|
329 |
CAVEAT: these cannot be long or doubles currently."
|
|
330 |
|
|
331 |
|val|
|
|
332 |
|
|
333 |
aJavaMethod numArgs ~~ 5 ifTrue:[
|
255
|
334 |
self halt:'argument count'
|
197
|
335 |
].
|
|
336 |
aJavaMethod isStatic ifTrue:[
|
255
|
337 |
self halt:'static function'
|
197
|
338 |
].
|
|
339 |
|
|
340 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) selector:sel.
|
|
341 |
val notNil ifTrue:[^ val].
|
|
342 |
|
|
343 |
i push:self.
|
|
344 |
i push:arg1.
|
|
345 |
i push:arg2.
|
|
346 |
i push:arg3.
|
|
347 |
i push:arg4.
|
|
348 |
i push:arg5.
|
|
349 |
|
|
350 |
val := i interpret:aJavaMethod sender:s.
|
|
351 |
|
|
352 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
353 |
|
|
354 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
355 |
"Created: 3.8.1997 / 20:32:03 / cg"
|
|
356 |
!
|
|
357 |
|
206
|
358 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
|
|
359 |
"invoke a java method, with 6 arguments.
|
|
360 |
CAVEAT: these cannot be long or doubles currently."
|
|
361 |
|
|
362 |
|val|
|
|
363 |
|
|
364 |
aJavaMethod numArgs ~~ 6 ifTrue:[
|
255
|
365 |
self halt:'argument count'
|
206
|
366 |
].
|
|
367 |
aJavaMethod isStatic ifTrue:[
|
255
|
368 |
self halt:'static function'
|
206
|
369 |
].
|
|
370 |
|
|
371 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) selector:sel.
|
|
372 |
val notNil ifTrue:[^ val].
|
|
373 |
|
|
374 |
i push:self.
|
|
375 |
i push:arg1.
|
|
376 |
i push:arg2.
|
|
377 |
i push:arg3.
|
|
378 |
i push:arg4.
|
|
379 |
i push:arg5.
|
|
380 |
i push:arg6.
|
|
381 |
|
|
382 |
val := i interpret:aJavaMethod sender:s.
|
|
383 |
|
|
384 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
385 |
|
|
386 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
|
387 |
"Created: 7.8.1997 / 20:57:55 / cg"
|
|
388 |
!
|
|
389 |
|
101
|
390 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2
|
78
|
391 |
"invoke a java method, with two arguments.
|
|
392 |
CAVEAT: these cannot be long or doubles currently."
|
44
|
393 |
|
101
|
394 |
|val|
|
44
|
395 |
|
|
396 |
aJavaMethod numArgs ~~ 2 ifTrue:[
|
255
|
397 |
self halt:'argument count'
|
44
|
398 |
].
|
|
399 |
aJavaMethod isStatic ifTrue:[
|
255
|
400 |
self halt:'static function'
|
44
|
401 |
].
|
|
402 |
|
175
|
403 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2).
|
|
404 |
val notNil ifTrue:[^ val].
|
|
405 |
|
44
|
406 |
i push:self.
|
|
407 |
i push:arg1.
|
|
408 |
i push:arg2.
|
|
409 |
|
101
|
410 |
val := i interpret:aJavaMethod sender:s.
|
44
|
411 |
|
|
412 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
413 |
|
175
|
414 |
"Modified: 30.7.1997 / 13:20:35 / cg"
|
83
|
415 |
!
|
|
416 |
|
113
|
417 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2 with:arg3
|
|
418 |
"invoke a java method, with 3 arguments.
|
|
419 |
CAVEAT: these cannot be long or doubles currently."
|
|
420 |
|
|
421 |
|val|
|
|
422 |
|
|
423 |
aJavaMethod numArgs ~~ 3 ifTrue:[
|
255
|
424 |
self halt:'argument count'
|
113
|
425 |
].
|
|
426 |
aJavaMethod isStatic ifTrue:[
|
255
|
427 |
self halt:'static function'
|
113
|
428 |
].
|
|
429 |
|
175
|
430 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3).
|
|
431 |
val notNil ifTrue:[^ val].
|
|
432 |
|
113
|
433 |
i push:self.
|
|
434 |
i push:arg1.
|
|
435 |
i push:arg2.
|
|
436 |
i push:arg3.
|
|
437 |
|
|
438 |
val := i interpret:aJavaMethod sender:s.
|
|
439 |
|
|
440 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
441 |
|
175
|
442 |
"Modified: 30.7.1997 / 13:20:44 / cg"
|
113
|
443 |
!
|
|
444 |
|
112
|
445 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s with:arg1 with:arg2 with:arg3 with:arg4
|
|
446 |
"invoke a java method, with 4 arguments.
|
|
447 |
CAVEAT: these cannot be long or doubles currently."
|
|
448 |
|
|
449 |
|val|
|
|
450 |
|
|
451 |
aJavaMethod numArgs ~~ 4 ifTrue:[
|
255
|
452 |
self halt:'argument count'
|
112
|
453 |
].
|
|
454 |
aJavaMethod isStatic ifTrue:[
|
255
|
455 |
self halt:'static function'
|
112
|
456 |
].
|
|
457 |
|
175
|
458 |
val := aJavaMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4).
|
|
459 |
val notNil ifTrue:[^ val].
|
|
460 |
|
112
|
461 |
i push:self.
|
|
462 |
i push:arg1.
|
|
463 |
i push:arg2.
|
|
464 |
i push:arg3.
|
|
465 |
i push:arg4.
|
|
466 |
|
|
467 |
val := i interpret:aJavaMethod sender:s.
|
|
468 |
|
|
469 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
470 |
|
175
|
471 |
"Modified: 30.7.1997 / 13:20:51 / cg"
|
112
|
472 |
!
|
|
473 |
|
101
|
474 |
invokeJavaMethod:aJavaMethod interpreter:i sender:s withAll:args
|
|
475 |
"invoke a java method, with two arguments.
|
83
|
476 |
CAVEAT: these cannot be long or doubles currently."
|
|
477 |
|
101
|
478 |
|val|
|
83
|
479 |
|
101
|
480 |
aJavaMethod numArgs ~~ args size ifTrue:[
|
255
|
481 |
self halt:'argument count'
|
83
|
482 |
].
|
|
483 |
aJavaMethod isStatic ifTrue:[
|
255
|
484 |
self halt:'static function'
|
83
|
485 |
].
|
|
486 |
|
175
|
487 |
val := aJavaMethod valueWithReceiver:self arguments:args.
|
|
488 |
val notNil ifTrue:[^ val].
|
|
489 |
|
83
|
490 |
i push:self.
|
101
|
491 |
args do:[:arg |
|
255
|
492 |
i push:arg.
|
101
|
493 |
].
|
83
|
494 |
|
101
|
495 |
val := i interpret:aJavaMethod sender:s.
|
83
|
496 |
|
|
497 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
498 |
|
175
|
499 |
"Modified: 30.7.1997 / 13:20:58 / cg"
|
101
|
500 |
!
|
|
501 |
|
|
502 |
invokeJavaMethod:aJavaMethod with:arg1 with:arg2
|
|
503 |
"invoke a java method, with two arguments.
|
|
504 |
CAVEAT: these cannot be long or doubles currently."
|
|
505 |
|
175
|
506 |
^ self
|
255
|
507 |
invokeJavaMethod:aJavaMethod
|
|
508 |
interpreter:JavaInterpreter new
|
|
509 |
sender:thisContext sender
|
|
510 |
with:arg1
|
|
511 |
with:arg2
|
101
|
512 |
|
175
|
513 |
"Modified: 30.7.1997 / 13:25:36 / cg"
|
43
|
514 |
! !
|
|
515 |
|
|
516 |
!JavaObject methodsFor:'printing & storing'!
|
|
517 |
|
|
518 |
displayString
|
166
|
519 |
self class == Java java_lang_String ifTrue:[
|
310
|
520 |
^ '''' , (Java as_ST_String:self) , ''''
|
|
521 |
].
|
|
522 |
|
|
523 |
self class == (Java at:'java.lang.Class') ifTrue:[
|
|
524 |
^ super displayString , '(' , (JavaVM classForJavaClassObject:self) displayString , ')'
|
48
|
525 |
].
|
|
526 |
|
407
|
527 |
self class == (Java at:'java.lang.reflect.Method') ifTrue:[
|
|
528 |
^ super displayString , '(' , (JavaVM methodForJavaMethodObject:self) displayString , ')'
|
|
529 |
].
|
|
530 |
|
415
|
531 |
"/ Object errorSignal handle:[:ex |
|
|
532 |
"/ ^ super displayString.
|
|
533 |
"/ ] do:[
|
|
534 |
"/ ^ Java as_ST_String:(self perform:#toString).
|
|
535 |
"/ ].
|
|
536 |
|
101
|
537 |
^ super displayString.
|
|
538 |
|
415
|
539 |
"Modified: / 4.11.1998 / 18:35:00 / cg"
|
168
|
540 |
!
|
|
541 |
|
|
542 |
javaDisplayString
|
|
543 |
Object errorSignal handle:[:ex |
|
419
|
544 |
ex return.
|
168
|
545 |
] do:[
|
419
|
546 |
^ Java as_ST_String:(self perform:#toString).
|
168
|
547 |
].
|
|
548 |
|
|
549 |
^ super displayString.
|
|
550 |
|
419
|
551 |
"Created: / 7.4.1997 / 17:38:13 / cg"
|
|
552 |
"Modified: / 4.11.1998 / 21:07:19 / cg"
|
166
|
553 |
! !
|
|
554 |
|
|
555 |
!JavaObject methodsFor:'queries'!
|
|
556 |
|
|
557 |
isJavaObject
|
|
558 |
^ true
|
|
559 |
|
|
560 |
"Created: 26.3.1997 / 13:34:17 / cg"
|
43
|
561 |
! !
|
|
562 |
|
|
563 |
!JavaObject methodsFor:'smalltalk interface'!
|
|
564 |
|
29
|
565 |
invoke:selector
|
|
566 |
"send a message, without args"
|
|
567 |
|
255
|
568 |
|method|
|
|
569 |
|
|
570 |
method := JavaClass lookupMethod:selector numArgs:0 in:self class static:false.
|
|
571 |
method notNil ifTrue:[
|
|
572 |
^ method
|
|
573 |
valueWithReceiver:self
|
|
574 |
arguments:#()
|
|
575 |
selector:(method selector)
|
|
576 |
search:nil
|
|
577 |
sender:nil
|
|
578 |
].
|
|
579 |
|
|
580 |
^ super doesNotUnderstand:(Message selector:selector)
|
29
|
581 |
|
|
582 |
"
|
|
583 |
|stack|
|
|
584 |
|
|
585 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
586 |
stack invoke:#'<init>'.
|
|
587 |
"
|
|
588 |
"
|
|
589 |
|stack|
|
|
590 |
|
43
|
591 |
stack := (Java at:'java/util/Stack') new.
|
29
|
592 |
stack invoke:#isEmpty.
|
|
593 |
"
|
|
594 |
"
|
|
595 |
|stack|
|
|
596 |
|
43
|
597 |
stack := (Java at:'java/util/Stack') new.
|
29
|
598 |
stack invoke:#size.
|
|
599 |
"
|
133
|
600 |
|
255
|
601 |
"Modified: / 7.1.1998 / 14:04:03 / cg"
|
29
|
602 |
!
|
|
603 |
|
175
|
604 |
invoke:selector with:arg
|
43
|
605 |
"send a message, with 1 argument.
|
|
606 |
TEMPORARY: This method needs more work."
|
33
|
607 |
|
175
|
608 |
^ self
|
255
|
609 |
invoke:selector
|
|
610 |
interpreter:(JavaInterpreter new)
|
|
611 |
sender:thisContext sender
|
|
612 |
with:arg
|
29
|
613 |
|
|
614 |
"
|
|
615 |
|stack|
|
|
616 |
|
33
|
617 |
stack := (Java at:'java/util/Stack') new.
|
29
|
618 |
stack invoke:#push with:1.
|
|
619 |
"
|
78
|
620 |
"
|
|
621 |
|stack|
|
|
622 |
|
|
623 |
stack := (Java at:'java/util/Stack') new.
|
|
624 |
stack invoke:#push with:1.
|
|
625 |
stack invoke:#push with:2.
|
|
626 |
stack invoke:#pop.
|
|
627 |
stack invoke:#pop.
|
|
628 |
stack invoke:#pop.
|
|
629 |
"
|
133
|
630 |
|
229
|
631 |
"Modified: 17.8.1997 / 18:07:39 / cg"
|
83
|
632 |
!
|
|
633 |
|
78
|
634 |
lookupMethod:selector numArgs:nargs
|
|
635 |
"lookup a method"
|
|
636 |
|
|
637 |
|method cls sel|
|
|
638 |
|
133
|
639 |
sel := selector.
|
|
640 |
(sel includes:$:) ifTrue:[
|
255
|
641 |
sel := sel copyTo:(sel indexOf:$:)-1
|
133
|
642 |
].
|
|
643 |
|
|
644 |
sel := sel asSymbolIfInterned.
|
78
|
645 |
sel notNil ifTrue:[
|
255
|
646 |
cls := self class.
|
|
647 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
648 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod |
|
|
649 |
(jSel == sel ) ifTrue:[
|
|
650 |
^ aMethod
|
|
651 |
]
|
|
652 |
].
|
|
653 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod |
|
|
654 |
(aMethod name = sel
|
|
655 |
or:[aMethod signatureNameWithoutReturnType = sel]) ifTrue:[
|
|
656 |
aMethod numArgs == nargs ifTrue:[
|
|
657 |
^ aMethod
|
|
658 |
]
|
|
659 |
]
|
|
660 |
].
|
|
661 |
cls := cls superclass.
|
|
662 |
].
|
78
|
663 |
].
|
|
664 |
|
|
665 |
^ nil
|
|
666 |
|
|
667 |
"
|
|
668 |
|stack|
|
|
669 |
|
113
|
670 |
stack := (Java at:'java.util.Stack') basicNew.
|
78
|
671 |
stack lookupMethod:#'<init>' numArgs:0.
|
|
672 |
"
|
|
673 |
"
|
|
674 |
|stack|
|
|
675 |
|
113
|
676 |
stack := (Java at:'java.util.Stack') new.
|
78
|
677 |
stack lookupMethod:#isEmpty numArgs:0.
|
|
678 |
"
|
113
|
679 |
"
|
|
680 |
|frame|
|
|
681 |
|
|
682 |
frame := (Java at:'java.awt.Frame') new.
|
|
683 |
frame lookupMethod:#'<init> (String)' numArgs:1.
|
|
684 |
"
|
|
685 |
|
159
|
686 |
"Modified: 22.3.1997 / 00:56:54 / cg"
|
26
|
687 |
! !
|
|
688 |
|
133
|
689 |
!JavaObject class methodsFor:'documentation'!
|
26
|
690 |
|
|
691 |
version
|
419
|
692 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaObject.st,v 1.41 1998/11/04 20:58:03 cg Exp $'
|
26
|
693 |
! !
|