author | vranyj1 |
Thu, 15 Dec 2011 23:34:23 +0000 | |
branch | jk_new_structure |
changeset 1288 | 444181770028 |
parent 1263 | 451695d79afa |
child 1328 | 06e2e372ebb0 |
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 |
||
1109
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
128 |
!JavaObject methodsFor:'finalization'! |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
129 |
|
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
130 |
finalize |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
131 |
|
1217 | 132 |
Logger log: 'Finalizing ', self printString severity: #info facility: #JVM. |
1109
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
133 |
[ self perform: #'finalize()V' ] on: Error do:["Nothing. see spec"] |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
134 |
|
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
135 |
"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
|
136 |
! ! |
9bd0544f9046
Initial version of finalize() support - may crash VM!
vranyj1
parents:
1093
diff
changeset
|
137 |
|
752 | 138 |
!JavaObject methodsFor:'initialization'! |
139 |
||
140 |
initializeToZero |
|
141 |
|sz| |
|
142 |
||
143 |
sz := self class instSize. |
|
144 |
1 to:sz do:[:i | |
|
145 |
self instVarAt:i put:0 |
|
146 |
] |
|
147 |
! ! |
|
148 |
||
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
149 |
!JavaObject methodsFor:'inspecting'! |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
150 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
151 |
inspectorExtraAttributes |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
152 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
153 |
| attrs nm | |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
154 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
155 |
attrs := super inspectorExtraAttributes. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
156 |
nm := self class name. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
157 |
nm == #'java/lang/reflect/Method' ifTrue:[ |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
158 |
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
|
159 |
^attrs. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
160 |
]. |
1242 | 161 |
nm == #'java/lang/Class' ifTrue:[ |
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
162 |
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
|
163 |
^attrs. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
164 |
]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
165 |
^attrs |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
166 |
|
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
167 |
"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
|
168 |
! ! |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
169 |
|
752 | 170 |
!JavaObject methodsFor:'message sending'! |
171 |
||
172 |
doesNotUnderstand:aMessage |
|
1263 | 173 |
|
174 |
| method selector class args| |
|
175 |
selector := aMessage selector. |
|
176 |
args := aMessage arguments. |
|
177 |
class := self class. |
|
178 |
||
179 |
JavaLookup isNil ifTrue:[ |
|
180 |
(Smalltalk loadPackage: 'stx:libjava/experiments') ifFalse:[ |
|
181 |
self error: 'You should load package stx:libjava/experiments if you want some interop - still experimental' mayProceed: true. |
|
182 |
^nil |
|
183 |
] |
|
184 |
]. |
|
1001 | 185 |
|
1263 | 186 |
method := JavaLookup instance lookupMethodForSelector: selector |
187 |
directedTo: class |
|
188 |
for: self |
|
189 |
withArguments: args |
|
1288 | 190 |
from: thisContext sender sender |
1263 | 191 |
ilc: nil. |
192 |
||
193 |
method isNil ifTrue:[ |
|
194 |
^super doesNotUnderstand:aMessage |
|
195 |
] ifFalse:[ |
|
196 |
^ method valueWithReceiver: self arguments: args |
|
197 |
]. |
|
752 | 198 |
|
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
199 |
"Modified: / 16-11-1998 / 16:50:56 / cg" |
1001 | 200 |
"Modified: / 19-09-2011 / 23:43:56 / Jan Kurs <kursjan@fit.cvut.cz>" |
1288 | 201 |
"Modified: / 15-12-2011 / 23:43:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 202 |
! ! |
203 |
||
204 |
!JavaObject methodsFor:'printing & storing'! |
|
205 |
||
206 |
displayString |
|
207 |
||
1213
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
208 |
^String streamContents:[:s|self basicPrintOn: s]. |
fc90769151e8
- fix in reflection over methods (signature is nil for non-generic methods)
vranyj1
parents:
1209
diff
changeset
|
209 |
|
1209 | 210 |
JavaVM booted ifTrue:[ |
211 |
| toString | |
|
212 |
[ toString := Java as_ST_String:(self perform:#'toString()Ljava/lang/String;').] |
|
213 |
on: Error do: [ toString := nil ]. |
|
214 |
toString notNil ifTrue:[ |
|
215 |
^toString |
|
216 |
] |
|
752 | 217 |
]. |
218 |
||
219 |
"Modified: / 04-11-1998 / 18:35:00 / cg" |
|
220 |
"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
|
221 |
"Modified: / 04-12-2011 / 20:16:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 222 |
! |
223 |
||
1209 | 224 |
printOn: aStream |
225 |
|myClassName | |
|
752 | 226 |
|
1209 | 227 |
myClassName := self class name. |
228 |
myClassName == #'java/lang/String' ifTrue:[ |
|
229 |
aStream nextPut:$". |
|
230 |
aStream nextPutAll: (Java as_ST_String: self). |
|
231 |
aStream nextPut:$". |
|
232 |
^self. |
|
752 | 233 |
]. |
1209 | 234 |
myClassName == #'java/lang/Class' ifTrue:[ |
235 |
super printOn: aStream. |
|
236 |
aStream nextPut: $(. |
|
237 |
(JavaVM reflection classForJavaClassObject:self) javaName printOn: aStream. |
|
238 |
aStream nextPut: $). |
|
239 |
^self. |
|
752 | 240 |
]. |
1209 | 241 |
myClassName == #'java.lang.reflect.Method' ifTrue:[ |
242 |
super printOn: aStream. |
|
243 |
aStream nextPut: $(. |
|
244 |
(JavaVM reflection methodForJavaMethodObject:self) printOn: aStream. |
|
245 |
aStream nextPut: $). |
|
246 |
^self. |
|
752 | 247 |
]. |
248 |
||
1209 | 249 |
JavaVM booted ifTrue:[ |
250 |
| toString | |
|
251 |
[ toString := Java as_ST_String:(self perform:#'toString()Ljava/lang/String;').] |
|
252 |
on: Error do: [ toString := nil ]. |
|
253 |
toString notNil ifTrue:[ |
|
254 |
"/super printOn: aStream. |
|
255 |
"/aStream nextPut: $(. |
|
256 |
aStream nextPutAll: toString. |
|
257 |
"/aStream nextPut: $). |
|
258 |
^self. |
|
259 |
] |
|
260 |
]. |
|
261 |
super printOn: aStream. |
|
262 |
||
263 |
"Created: / 04-12-2011 / 10:29:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 264 |
! ! |
265 |
||
266 |
!JavaObject methodsFor:'queries'! |
|
267 |
||
268 |
isJavaClassRef |
|
269 |
^ false |
|
270 |
||
271 |
"Created: / 9.11.1999 / 17:13:37 / cg" |
|
272 |
! |
|
273 |
||
274 |
isJavaMethodRef |
|
275 |
^ false |
|
276 |
||
277 |
"Created: / 9.11.1999 / 15:43:21 / cg" |
|
278 |
! |
|
279 |
||
280 |
isJavaObject |
|
281 |
^ true |
|
282 |
||
283 |
"Created: 26.3.1997 / 13:34:17 / cg" |
|
284 |
! ! |
|
285 |
||
286 |
!JavaObject methodsFor:'smalltalk interface'! |
|
287 |
||
288 |
lookupMethod:selector numArgs:nargs |
|
289 |
"lookup a method" |
|
290 |
||
291 |
|method cls sel| |
|
292 |
||
293 |
sel := selector. |
|
294 |
(sel includes:$:) ifTrue:[ |
|
295 |
sel := sel copyTo:(sel indexOf:$:)-1 |
|
296 |
]. |
|
297 |
||
298 |
sel := sel asSymbolIfInterned. |
|
299 |
sel notNil ifTrue:[ |
|
300 |
cls := self class. |
|
301 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[ |
|
302 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
303 |
(jSel == sel ) ifTrue:[ |
|
304 |
^ aMethod |
|
305 |
] |
|
306 |
]. |
|
307 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod | |
|
308 |
(aMethod name = sel |
|
309 |
or:[aMethod signatureNameWithoutReturnType = sel]) ifTrue:[ |
|
310 |
aMethod numArgs == nargs ifTrue:[ |
|
311 |
^ aMethod |
|
312 |
] |
|
313 |
] |
|
314 |
]. |
|
315 |
cls := cls superclass. |
|
316 |
]. |
|
317 |
]. |
|
318 |
||
319 |
^ nil |
|
320 |
||
321 |
" |
|
322 |
|stack| |
|
323 |
||
324 |
stack := (Java at:'java.util.Stack') basicNew. |
|
325 |
stack lookupMethod:#'<init>' numArgs:0. |
|
326 |
" |
|
327 |
" |
|
328 |
|stack| |
|
329 |
||
330 |
stack := (Java at:'java.util.Stack') new. |
|
331 |
stack lookupMethod:#isEmpty numArgs:0. |
|
332 |
" |
|
333 |
" |
|
334 |
|frame| |
|
335 |
||
336 |
frame := (Java at:'java.awt.Frame') new. |
|
337 |
frame lookupMethod:#'<init> (String)' numArgs:1. |
|
338 |
" |
|
339 |
||
340 |
"Modified: 22.3.1997 / 00:56:54 / cg" |
|
341 |
! ! |
|
342 |
||
1093 | 343 |
!JavaObject methodsFor:'unwind'! |
344 |
||
345 |
unwindHandlerInContext: aContext |
|
346 |
"given a context which has been marked for unwind, |
|
347 |
retrieve the handler block. This method is called when ST |
|
348 |
exception raises and stack is unwinding. JavaClass instance |
|
349 |
has an opportunity to clean up monitors" |
|
350 |
||
351 |
^ JavaVM unwindHandlerForJavaContext: aContext. |
|
352 |
||
353 |
"Created: / 08-11-2011 / 12:25:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
354 |
! ! |
|
355 |
||
752 | 356 |
!JavaObject class methodsFor:'documentation'! |
357 |
||
358 |
version |
|
1022 | 359 |
^ '$Id$' |
752 | 360 |
! |
361 |
||
362 |
version_SVN |
|
1022 | 363 |
^ '$Id$' |
949
8452984ed807
New Implementation of JavaLookup. Slow, no boxing, unboxing is old and needs to be rewritten.
kursjan
parents:
923
diff
changeset
|
364 |
! ! |