author | kursjan |
Fri, 30 Dec 2011 14:38:09 +0000 | |
branch | jk_new_structure |
changeset 1328 | 06e2e372ebb0 |
parent 1288 | 444181770028 |
child 1356 | 0dd28400803e |
permissions | -rw-r--r-- |
752 | 1 |
" |
877 | 2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
877 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
752 | 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 |
|
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
752 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaObject |
|
24 |
instanceVariableNames:'' |
|
25 |
classVariableNames:'' |
|
26 |
poolDictionaries:'' |
|
27 |
category:'Languages-Java-Classes' |
|
28 |
! |
|
29 |
||
30 |
!JavaObject class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
877 | 34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
877 | 38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
39 |
SWING Research Group, Czech Technical University in Prague |
|
40 |
||
752 | 41 |
This software is furnished under a license and may be used |
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
877 | 47 |
|
1155 | 48 |
[1] Code written at SWING Research Group contains a signature |
49 |
of one of the above copright owners. For exact set of such code, |
|
50 |
see the differences between this version and version stx:libjava |
|
1152 | 51 |
as of 1.9.2010 |
877 | 52 |
|
752 | 53 |
" |
54 |
! ! |
|
55 |
||
56 |
!JavaObject class methodsFor:'misc'! |
|
57 |
||
58 |
resolveClassRefs |
|
59 |
! |
|
60 |
||
61 |
resolveClassRefsIgnoring:setOfClasses |
|
62 |
! ! |
|
63 |
||
64 |
!JavaObject class methodsFor:'smalltalk interface'! |
|
65 |
||
66 |
convertJavaObject:val signature:retValSignature |
|
67 |
^ val. |
|
68 |
||
69 |
retValSignature = 'void' ifTrue:[ |
|
70 |
^ #void |
|
71 |
]. |
|
72 |
retValSignature = 'boolean' ifTrue:[ |
|
73 |
val == 0 ifTrue:[^ false]. |
|
74 |
^ true |
|
75 |
]. |
|
76 |
retValSignature = 'int' ifTrue:[ |
|
77 |
val isInteger ifFalse:[ |
|
78 |
self halt |
|
79 |
]. |
|
80 |
^ val |
|
81 |
]. |
|
82 |
retValSignature = 'char[]' ifTrue:[ |
|
83 |
"/ these are ST-strings |
|
84 |
^ val |
|
85 |
]. |
|
86 |
||
87 |
retValSignature = 'char' ifTrue:[ |
|
88 |
"/ these are ST-characters |
|
89 |
val isInteger ifTrue:[ |
|
90 |
^ Character value:val |
|
91 |
]. |
|
92 |
self halt. |
|
93 |
^ val |
|
94 |
]. |
|
95 |
||
96 |
retValSignature = 'Object' ifTrue:[ |
|
97 |
^ val |
|
98 |
]. |
|
99 |
||
100 |
retValSignature = 'String' ifTrue:[ |
|
101 |
^ Java as_ST_String:val |
|
102 |
]. |
|
103 |
||
104 |
'no conversion for: ' print. val class name print. ' to: ' print. retValSignature printNL. |
|
105 |
^ val. |
|
106 |
||
107 |
"Modified: 8.8.1997 / 12:07:23 / cg" |
|
108 |
! |
|
109 |
||
110 |
javaStringFrom:aString |
|
111 |
"hard-coding internas of java.lang.String here is bad ..." |
|
112 |
||
113 |
self halt. |
|
114 |
^ Java as_String:aString |
|
115 |
||
116 |
"Modified: 7.8.1997 / 21:17:32 / cg" |
|
117 |
! |
|
118 |
||
119 |
stringFromJavaString:aJavaString |
|
120 |
"hard-coding internas of java.lang.String here is bad ..." |
|
121 |
||
122 |
self halt. |
|
123 |
^ Java as_ST_String:aJavaString |
|
124 |
||
125 |
"Modified: 8.8.1997 / 12:07:29 / cg" |
|
126 |
! ! |
|
127 |
||
1328 | 128 |
!JavaObject methodsFor:'autoboxing'! |
129 |
||
130 |
javaUnwrapFrom: javaType |
|
131 |
^ self class javaUnwrap: self. |
|
132 |
||
133 |
"Created: / 30-12-2011 / 15:21:09 / kursjan <kursjan@fit.cvut.cz>" |
|
134 |
! ! |
|
135 |
||
1109
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
136 |
!JavaObject methodsFor:'finalization'! |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
137 |
|
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
138 |
finalize |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
139 |
|
1217 | 140 |
Logger log: 'Finalizing ', self printString severity: #info facility: #JVM. |
1109
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
141 |
[ self perform: #'finalize()V' ] on: Error do:["Nothing. see spec"] |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
142 |
|
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
143 |
"Created: / 14-11-2011 / 12:32:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
144 |
! ! |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
145 |
|
752 | 146 |
!JavaObject methodsFor:'initialization'! |
147 |
||
148 |
initializeToZero |
|
149 |
|sz| |
|
150 |
||
151 |
sz := self class instSize. |
|
152 |
1 to:sz do:[:i | |
|
153 |
self instVarAt:i put:0 |
|
154 |
] |
|
155 |
! ! |
|
156 |
||
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
157 |
!JavaObject methodsFor:'inspecting'! |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
158 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
159 |
inspectorExtraAttributes |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
160 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
161 |
| attrs nm | |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
162 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
163 |
attrs := super inspectorExtraAttributes. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
164 |
nm := self class name. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
165 |
nm == #'java/lang/reflect/Method' ifTrue:[ |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
166 |
attrs at:'-method' put: (JavaVM reflection methodForJavaMethodObject: self). |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
167 |
^attrs. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
168 |
]. |
1242 | 169 |
nm == #'java/lang/Class' ifTrue:[ |
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
170 |
attrs at:'-class' put: (JavaVM reflection classForJavaClassObject: self). |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
171 |
^attrs. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
172 |
]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
173 |
^attrs |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
174 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
175 |
"Created: / 04-12-2011 / 19:28:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
176 |
! ! |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
177 |
|
752 | 178 |
!JavaObject methodsFor:'message sending'! |
179 |
||
180 |
doesNotUnderstand:aMessage |
|
1263 | 181 |
|
182 |
| method selector class args| |
|
183 |
selector := aMessage selector. |
|
184 |
args := aMessage arguments. |
|
185 |
class := self class. |
|
186 |
||
187 |
JavaLookup isNil ifTrue:[ |
|
188 |
(Smalltalk loadPackage: 'stx:libjava/experiments') ifFalse:[ |
|
189 |
self error: 'You should load package stx:libjava/experiments if you want some interop - still experimental' mayProceed: true. |
|
190 |
^nil |
|
191 |
] |
|
192 |
]. |
|
1001 | 193 |
|
1263 | 194 |
method := JavaLookup instance lookupMethodForSelector: selector |
195 |
directedTo: class |
|
196 |
for: self |
|
197 |
withArguments: args |
|
1288 | 198 |
from: thisContext sender sender |
1263 | 199 |
ilc: nil. |
200 |
||
201 |
method isNil ifTrue:[ |
|
202 |
^super doesNotUnderstand:aMessage |
|
203 |
] ifFalse:[ |
|
204 |
^ method valueWithReceiver: self arguments: args |
|
205 |
]. |
|
752 | 206 |
|
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
207 |
"Modified: / 16-11-1998 / 16:50:56 / cg" |
1001 | 208 |
"Modified: / 19-09-2011 / 23:43:56 / Jan Kurs <kursjan@fit.cvut.cz>" |
1288 | 209 |
"Modified: / 15-12-2011 / 23:43:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 210 |
! ! |
211 |
||
212 |
!JavaObject methodsFor:'printing & storing'! |
|
213 |
||
214 |
displayString |
|
215 |
||
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
216 |
^String streamContents:[:s|self basicPrintOn: s]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
217 |
|
1209 | 218 |
JavaVM booted ifTrue:[ |
219 |
| toString | |
|
220 |
[ toString := Java as_ST_String:(self perform:#'toString()Ljava/lang/String;').] |
|
221 |
on: Error do: [ toString := nil ]. |
|
222 |
toString notNil ifTrue:[ |
|
223 |
^toString |
|
224 |
] |
|
752 | 225 |
]. |
226 |
||
227 |
"Modified: / 04-11-1998 / 18:35:00 / cg" |
|
228 |
"Modified: / 28-01-2011 / 15:10:05 / Marcel Hlopko <hlopik@gmail.com>" |
|
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
229 |
"Modified: / 04-12-2011 / 20:16:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 230 |
! |
231 |
||
1209 | 232 |
printOn: aStream |
233 |
|myClassName | |
|
752 | 234 |
|
1209 | 235 |
myClassName := self class name. |
236 |
myClassName == #'java/lang/String' ifTrue:[ |
|
237 |
aStream nextPut:$". |
|
238 |
aStream nextPutAll: (Java as_ST_String: self). |
|
239 |
aStream nextPut:$". |
|
240 |
^self. |
|
752 | 241 |
]. |
1209 | 242 |
myClassName == #'java/lang/Class' ifTrue:[ |
243 |
super printOn: aStream. |
|
244 |
aStream nextPut: $(. |
|
245 |
(JavaVM reflection classForJavaClassObject:self) javaName printOn: aStream. |
|
246 |
aStream nextPut: $). |
|
247 |
^self. |
|
752 | 248 |
]. |
1209 | 249 |
myClassName == #'java.lang.reflect.Method' ifTrue:[ |
250 |
super printOn: aStream. |
|
251 |
aStream nextPut: $(. |
|
252 |
(JavaVM reflection methodForJavaMethodObject:self) printOn: aStream. |
|
253 |
aStream nextPut: $). |
|
254 |
^self. |
|
752 | 255 |
]. |
256 |
||
1209 | 257 |
JavaVM booted ifTrue:[ |
258 |
| toString | |
|
259 |
[ toString := Java as_ST_String:(self perform:#'toString()Ljava/lang/String;').] |
|
260 |
on: Error do: [ toString := nil ]. |
|
261 |
toString notNil ifTrue:[ |
|
262 |
"/super printOn: aStream. |
|
263 |
"/aStream nextPut: $(. |
|
264 |
aStream nextPutAll: toString. |
|
265 |
"/aStream nextPut: $). |
|
266 |
^self. |
|
267 |
] |
|
268 |
]. |
|
269 |
super printOn: aStream. |
|
270 |
||
271 |
"Created: / 04-12-2011 / 10:29:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 272 |
! ! |
273 |
||
274 |
!JavaObject methodsFor:'queries'! |
|
275 |
||
276 |
isJavaClassRef |
|
277 |
^ false |
|
278 |
||
279 |
"Created: / 9.11.1999 / 17:13:37 / cg" |
|
280 |
! |
|
281 |
||
282 |
isJavaMethodRef |
|
283 |
^ false |
|
284 |
||
285 |
"Created: / 9.11.1999 / 15:43:21 / cg" |
|
286 |
! |
|
287 |
||
288 |
isJavaObject |
|
289 |
^ true |
|
290 |
||
291 |
"Created: 26.3.1997 / 13:34:17 / cg" |
|
292 |
! ! |
|
293 |
||
294 |
!JavaObject methodsFor:'smalltalk interface'! |
|
295 |
||
296 |
lookupMethod:selector numArgs:nargs |
|
297 |
"lookup a method" |
|
298 |
||
299 |
|method cls sel| |
|
300 |
||
301 |
sel := selector. |
|
302 |
(sel includes:$:) ifTrue:[ |
|
303 |
sel := sel copyTo:(sel indexOf:$:)-1 |
|
304 |
]. |
|
305 |
||
306 |
sel := sel asSymbolIfInterned. |
|
307 |
sel notNil ifTrue:[ |
|
308 |
cls := self class. |
|
309 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[ |
|
310 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
311 |
(jSel == sel ) ifTrue:[ |
|
312 |
^ aMethod |
|
313 |
] |
|
314 |
]. |
|
315 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
316 |
(aMethod name = sel |
|
317 |
or:[aMethod signatureNameWithoutReturnType = sel]) ifTrue:[ |
|
318 |
aMethod numArgs == nargs ifTrue:[ |
|
319 |
^ aMethod |
|
320 |
] |
|
321 |
] |
|
322 |
]. |
|
323 |
cls := cls superclass. |
|
324 |
]. |
|
325 |
]. |
|
326 |
||
327 |
^ nil |
|
328 |
||
329 |
" |
|
330 |
|stack| |
|
331 |
||
332 |
stack := (Java at:'java.util.Stack') basicNew. |
|
333 |
stack lookupMethod:#'<init>' numArgs:0. |
|
334 |
" |
|
335 |
" |
|
336 |
|stack| |
|
337 |
||
338 |
stack := (Java at:'java.util.Stack') new. |
|
339 |
stack lookupMethod:#isEmpty numArgs:0. |
|
340 |
" |
|
341 |
" |
|
342 |
|frame| |
|
343 |
||
344 |
frame := (Java at:'java.awt.Frame') new. |
|
345 |
frame lookupMethod:#'<init> (String)' numArgs:1. |
|
346 |
" |
|
347 |
||
348 |
"Modified: 22.3.1997 / 00:56:54 / cg" |
|
349 |
! ! |
|
350 |
||
1093 | 351 |
!JavaObject methodsFor:'unwind'! |
352 |
||
353 |
unwindHandlerInContext: aContext |
|
354 |
"given a context which has been marked for unwind, |
|
355 |
retrieve the handler block. This method is called when ST |
|
356 |
exception raises and stack is unwinding. JavaClass instance |
|
357 |
has an opportunity to clean up monitors" |
|
358 |
||
359 |
^ JavaVM unwindHandlerForJavaContext: aContext. |
|
360 |
||
361 |
"Created: / 08-11-2011 / 12:25:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
362 |
! ! |
|
363 |
||
752 | 364 |
!JavaObject class methodsFor:'documentation'! |
365 |
||
366 |
version |
|
1022 | 367 |
^ '$Id$' |
752 | 368 |
! |
369 |
||
370 |
version_SVN |
|
1022 | 371 |
^ '$Id$' |
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
372 |
! ! |