author | hlopkmar |
Tue, 08 Nov 2011 13:48:55 +0000 | |
branch | jk_new_structure |
changeset 1093 | 255c230a1c55 |
parent 1022 | 38b710d7dfbc |
child 1109 | 9bd0544f9046 |
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 |
Object subclass:#JavaObject |
|
45 |
instanceVariableNames:'' |
|
46 |
classVariableNames:'' |
|
47 |
poolDictionaries:'' |
|
48 |
category:'Languages-Java-Classes' |
|
49 |
! |
|
50 |
||
51 |
!JavaObject class methodsFor:'documentation'! |
|
52 |
||
53 |
copyright |
|
54 |
" |
|
877 | 55 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
56 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
57 |
SWING Research Group, Czech Technical University in Prague |
|
58 |
||
59 |
Parts of the code written by Claus Gittinger are under following |
|
60 |
license: |
|
752 | 61 |
|
62 |
This software is furnished under a license and may be used |
|
63 |
only in accordance with the terms of that license and with the |
|
64 |
inclusion of the above copyright notice. This software may not |
|
65 |
be provided or otherwise made available to, or used by, any |
|
66 |
other person. No title to or ownership of the software is |
|
67 |
hereby transferred. |
|
877 | 68 |
|
69 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
70 |
||
71 |
Permission is hereby granted, free of charge, to any person |
|
72 |
obtaining a copy of this software and associated documentation |
|
73 |
files (the 'Software'), to deal in the Software without |
|
74 |
restriction, including without limitation the rights to use, |
|
75 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
76 |
copies of the Software, and to permit persons to whom the |
|
77 |
Software is furnished to do so, subject to the following |
|
78 |
conditions: |
|
79 |
||
80 |
The above copyright notice and this permission notice shall be |
|
81 |
included in all copies or substantial portions of the Software. |
|
82 |
||
83 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
84 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
85 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
86 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
87 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
88 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
89 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
90 |
OTHER DEALINGS IN THE SOFTWARE. |
|
91 |
||
92 |
[1] Code written at SWING Research Group contain a signature |
|
93 |
of one of the above copright owners. |
|
94 |
||
752 | 95 |
" |
96 |
! ! |
|
97 |
||
98 |
!JavaObject class methodsFor:'misc'! |
|
99 |
||
100 |
resolveClassRefs |
|
101 |
! |
|
102 |
||
103 |
resolveClassRefsIgnoring:setOfClasses |
|
104 |
! ! |
|
105 |
||
106 |
!JavaObject class methodsFor:'smalltalk interface'! |
|
107 |
||
108 |
convertJavaObject:val signature:retValSignature |
|
109 |
^ val. |
|
110 |
||
111 |
retValSignature = 'void' ifTrue:[ |
|
112 |
^ #void |
|
113 |
]. |
|
114 |
retValSignature = 'boolean' ifTrue:[ |
|
115 |
val == 0 ifTrue:[^ false]. |
|
116 |
^ true |
|
117 |
]. |
|
118 |
retValSignature = 'int' ifTrue:[ |
|
119 |
val isInteger ifFalse:[ |
|
120 |
self halt |
|
121 |
]. |
|
122 |
^ val |
|
123 |
]. |
|
124 |
retValSignature = 'char[]' ifTrue:[ |
|
125 |
"/ these are ST-strings |
|
126 |
^ val |
|
127 |
]. |
|
128 |
||
129 |
retValSignature = 'char' ifTrue:[ |
|
130 |
"/ these are ST-characters |
|
131 |
val isInteger ifTrue:[ |
|
132 |
^ Character value:val |
|
133 |
]. |
|
134 |
self halt. |
|
135 |
^ val |
|
136 |
]. |
|
137 |
||
138 |
retValSignature = 'Object' ifTrue:[ |
|
139 |
^ val |
|
140 |
]. |
|
141 |
||
142 |
retValSignature = 'String' ifTrue:[ |
|
143 |
^ Java as_ST_String:val |
|
144 |
]. |
|
145 |
||
146 |
'no conversion for: ' print. val class name print. ' to: ' print. retValSignature printNL. |
|
147 |
^ val. |
|
148 |
||
149 |
"Modified: 8.8.1997 / 12:07:23 / cg" |
|
150 |
! |
|
151 |
||
152 |
javaStringFrom:aString |
|
153 |
"hard-coding internas of java.lang.String here is bad ..." |
|
154 |
||
155 |
self halt. |
|
156 |
^ Java as_String:aString |
|
157 |
||
158 |
"Modified: 7.8.1997 / 21:17:32 / cg" |
|
159 |
! |
|
160 |
||
161 |
stringFromJavaString:aJavaString |
|
162 |
"hard-coding internas of java.lang.String here is bad ..." |
|
163 |
||
164 |
self halt. |
|
165 |
^ Java as_ST_String:aJavaString |
|
166 |
||
167 |
"Modified: 8.8.1997 / 12:07:29 / cg" |
|
168 |
! ! |
|
169 |
||
170 |
!JavaObject methodsFor:'initialization'! |
|
171 |
||
172 |
initializeToZero |
|
173 |
|sz| |
|
174 |
||
175 |
sz := self class instSize. |
|
176 |
1 to:sz do:[:i | |
|
177 |
self instVarAt:i put:0 |
|
178 |
] |
|
179 |
! ! |
|
180 |
||
181 |
!JavaObject methodsFor:'message sending'! |
|
182 |
||
183 |
doesNotUnderstand:aMessage |
|
184 |
"as a courtesy to the smalltalker, try to map methods" |
|
1001 | 185 |
^ JavaClass |
186 |
perform: aMessage |
|
187 |
onReceiver: self |
|
188 |
from: thisContext sender |
|
189 |
ifNotFound: [ super doesNotUnderstand: aMessage] |
|
190 |
||
191 |
"/ [ |
|
192 |
"/ ^ JavaLookup instance |
|
193 |
"/ perform: aMessage onReceiver: self from: thisContext sender. |
|
194 |
"/ ] on: JavaDoesNotUnderstandException |
|
195 |
"/ do: [:e | |
|
196 |
"/ ^ super doesNotUnderstand: aMessage. |
|
197 |
"/ ] |
|
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
198 |
"/ |args numArgs javaMethod sel retVal m| |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
199 |
"/ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
200 |
"/ args := aMessage arguments. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
201 |
"/ numArgs := args size. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
202 |
"/ sel := aMessage selector. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
203 |
"/ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
204 |
"/ javaMethod := JavaClass lookupMethod:sel numArgs:numArgs in:self class static:false. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
205 |
"/ javaMethod notNil ifTrue:[ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
206 |
"/ args notNil ifTrue:[ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
207 |
"/ args := JavaClass |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
208 |
"/ convertArgsToJava:args |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
209 |
"/ asSpecifiedIn:(javaMethod argSignature) |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
210 |
"/ numArgs:numArgs. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
211 |
"/ ]. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
212 |
"/ javaMethod isWrapped ifTrue:[ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
213 |
"/ m := javaMethod originalMethod |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
214 |
"/ ] ifFalse:[ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
215 |
"/ m := javaMethod |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
216 |
"/ ]. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
217 |
"/ retVal := javaMethod |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
218 |
"/ valueWithReceiver:self |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
219 |
"/ arguments:args |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
220 |
"/ selector:m selector |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
221 |
"/ search:m javaClass |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
222 |
"/ sender:nil. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
223 |
"/ |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
224 |
"/ ^ JavaClass convertToSmalltalk:retVal type:(m returnType). |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
225 |
"/ ]. |
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
226 |
"/ ^ super doesNotUnderstand:aMessage |
752 | 227 |
|
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
228 |
"Modified: / 16-11-1998 / 16:50:56 / cg" |
1001 | 229 |
"Modified: / 19-09-2011 / 23:43:56 / Jan Kurs <kursjan@fit.cvut.cz>" |
752 | 230 |
! ! |
231 |
||
232 |
!JavaObject methodsFor:'printing & storing'! |
|
233 |
||
234 |
displayString |
|
235 |
|myClass javaString| |
|
236 |
||
237 |
myClass := self class. |
|
238 |
myClass == Java java_lang_String ifTrue:[ |
|
239 |
^ '''' , (Java as_ST_String:self) , '''' |
|
240 |
]. |
|
241 |
myClass == (Java at:'java.lang.Class') ifTrue:[ |
|
242 |
^ super displayString , '(' |
|
243 |
, (JavaVM reflection classForJavaClassObject:self) displayString , ')' |
|
244 |
]. |
|
245 |
myClass == (Java at:'java.lang.reflect.Method') ifTrue:[ |
|
246 |
^ super displayString , '(' |
|
247 |
, (JavaVM methodForJavaMethodObject:self) displayString , ')' |
|
248 |
]. |
|
249 |
Object errorSignal |
|
250 |
handle:[:ex | javaString := ''.] |
|
251 |
do:[ |
|
252 |
javaString := Java |
|
253 |
as_ST_String:(self perform:#'toString()Ljava/lang/String;'). |
|
254 |
]. |
|
255 |
^ super displayString , ' (' , javaString , ')'. |
|
256 |
||
257 |
"Modified: / 04-11-1998 / 18:35:00 / cg" |
|
258 |
"Modified: / 28-01-2011 / 15:10:05 / Marcel Hlopko <hlopik@gmail.com>" |
|
259 |
! |
|
260 |
||
261 |
javaDisplayString |
|
262 |
Object errorSignal handle:[:ex | |
|
263 |
ex return. |
|
264 |
] do:[ |
|
265 |
^ Java as_ST_String:(self perform:#toString). |
|
266 |
]. |
|
267 |
||
268 |
^ super displayString. |
|
269 |
||
270 |
"Created: / 7.4.1997 / 17:38:13 / cg" |
|
271 |
"Modified: / 4.11.1998 / 21:07:19 / cg" |
|
272 |
! |
|
273 |
||
274 |
printString |
|
275 |
|myClass javaString| |
|
276 |
||
277 |
myClass := self class. |
|
278 |
myClass == Java java_lang_String ifTrue:[ |
|
279 |
^ '''' , (Java as_ST_String:self) , '''' |
|
280 |
]. |
|
281 |
myClass == (Java at:'java.lang.Class') ifTrue:[ |
|
282 |
^ super printString , '(' |
|
283 |
, (JavaVM reflection classForJavaClassObject:self) displayString , ')' |
|
284 |
]. |
|
285 |
myClass == (Java at:'java.lang.reflect.Method') ifTrue:[ |
|
286 |
^ super printString , '(' |
|
287 |
, (JavaVM methodForJavaMethodObject:self) displayString , ')' |
|
288 |
]. |
|
289 |
Object errorSignal |
|
290 |
handle:[:ex | javaString := ''.] |
|
291 |
do:[ |
|
292 |
javaString := Java |
|
293 |
as_ST_String:(self perform:#'toString()Ljava/lang/String;'). |
|
294 |
]. |
|
295 |
^ super printString , ' (' , javaString , ')'. |
|
296 |
||
297 |
"Modified: / 04-11-1998 / 18:35:00 / cg" |
|
298 |
"Created: / 20-12-2010 / 23:10:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
299 |
"Modified: / 28-01-2011 / 15:10:17 / Marcel Hlopko <hlopik@gmail.com>" |
|
300 |
! ! |
|
301 |
||
302 |
!JavaObject methodsFor:'queries'! |
|
303 |
||
304 |
isJavaClassRef |
|
305 |
^ false |
|
306 |
||
307 |
"Created: / 9.11.1999 / 17:13:37 / cg" |
|
308 |
! |
|
309 |
||
310 |
isJavaMethodRef |
|
311 |
^ false |
|
312 |
||
313 |
"Created: / 9.11.1999 / 15:43:21 / cg" |
|
314 |
! |
|
315 |
||
316 |
isJavaObject |
|
317 |
^ true |
|
318 |
||
319 |
"Created: 26.3.1997 / 13:34:17 / cg" |
|
320 |
! ! |
|
321 |
||
322 |
!JavaObject methodsFor:'smalltalk interface'! |
|
323 |
||
324 |
lookupMethod:selector numArgs:nargs |
|
325 |
"lookup a method" |
|
326 |
||
327 |
|method cls sel| |
|
328 |
||
329 |
sel := selector. |
|
330 |
(sel includes:$:) ifTrue:[ |
|
331 |
sel := sel copyTo:(sel indexOf:$:)-1 |
|
332 |
]. |
|
333 |
||
334 |
sel := sel asSymbolIfInterned. |
|
335 |
sel notNil ifTrue:[ |
|
336 |
cls := self class. |
|
337 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[ |
|
338 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
339 |
(jSel == sel ) ifTrue:[ |
|
340 |
^ aMethod |
|
341 |
] |
|
342 |
]. |
|
343 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
344 |
(aMethod name = sel |
|
345 |
or:[aMethod signatureNameWithoutReturnType = sel]) ifTrue:[ |
|
346 |
aMethod numArgs == nargs ifTrue:[ |
|
347 |
^ aMethod |
|
348 |
] |
|
349 |
] |
|
350 |
]. |
|
351 |
cls := cls superclass. |
|
352 |
]. |
|
353 |
]. |
|
354 |
||
355 |
^ nil |
|
356 |
||
357 |
" |
|
358 |
|stack| |
|
359 |
||
360 |
stack := (Java at:'java.util.Stack') basicNew. |
|
361 |
stack lookupMethod:#'<init>' numArgs:0. |
|
362 |
" |
|
363 |
" |
|
364 |
|stack| |
|
365 |
||
366 |
stack := (Java at:'java.util.Stack') new. |
|
367 |
stack lookupMethod:#isEmpty numArgs:0. |
|
368 |
" |
|
369 |
" |
|
370 |
|frame| |
|
371 |
||
372 |
frame := (Java at:'java.awt.Frame') new. |
|
373 |
frame lookupMethod:#'<init> (String)' numArgs:1. |
|
374 |
" |
|
375 |
||
376 |
"Modified: 22.3.1997 / 00:56:54 / cg" |
|
377 |
! ! |
|
378 |
||
1093 | 379 |
!JavaObject methodsFor:'unwind'! |
380 |
||
381 |
unwindHandlerInContext: aContext |
|
382 |
"given a context which has been marked for unwind, |
|
383 |
retrieve the handler block. This method is called when ST |
|
384 |
exception raises and stack is unwinding. JavaClass instance |
|
385 |
has an opportunity to clean up monitors" |
|
386 |
||
387 |
^ JavaVM unwindHandlerForJavaContext: aContext. |
|
388 |
||
389 |
"Created: / 08-11-2011 / 12:25:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
390 |
! ! |
|
391 |
||
752 | 392 |
!JavaObject class methodsFor:'documentation'! |
393 |
||
394 |
version |
|
1022 | 395 |
^ '$Id$' |
752 | 396 |
! |
397 |
||
398 |
version_SVN |
|
1022 | 399 |
^ '$Id$' |
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
400 |
! ! |