author | vranyj1 |
Tue, 18 Oct 2011 15:52:12 +0000 | |
branch | jk_new_structure |
changeset 1022 | 38b710d7dfbc |
parent 985 | 8d63abcb4308 |
child 1026 | 5badd1d31864 |
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 |
CompiledCode variableSubclass:#JavaMethod |
|
948 | 45 |
instanceVariableNames:'accessFlags selector javaClass descriptor signature lookupObject |
46 |
lineNumberTable localVariableTable sourceLineNumber annotations' |
|
47 |
classVariableNames:'AbstractMethodInvokationSignal SignatureTypeCodes |
|
48 |
ForceByteCodeDisplay UnresolvedClassSignal A_PUBLIC A_PRIVATE |
|
49 |
A_PROTECTED A_STATIC A_FINAL A_SYNCHRONIZED A_ABSTRACT A_NATIVE |
|
50 |
A_BREAKPOINT R_VOID R_LONG R_DOUBLE A_HASHANDLER A_BRIDGE |
|
51 |
A_VARARGS A_STRICT A_SYNTHETIC' |
|
52 |
poolDictionaries:'' |
|
53 |
category:'Languages-Java-Classes' |
|
752 | 54 |
! |
55 |
||
56 |
!JavaMethod class methodsFor:'documentation'! |
|
57 |
||
58 |
copyright |
|
59 |
" |
|
877 | 60 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
61 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
62 |
SWING Research Group, Czech Technical University in Prague |
|
63 |
||
64 |
Parts of the code written by Claus Gittinger are under following |
|
65 |
license: |
|
752 | 66 |
|
67 |
This software is furnished under a license and may be used |
|
68 |
only in accordance with the terms of that license and with the |
|
69 |
inclusion of the above copyright notice. This software may not |
|
70 |
be provided or otherwise made available to, or used by, any |
|
71 |
other person. No title to or ownership of the software is |
|
72 |
hereby transferred. |
|
877 | 73 |
|
74 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
75 |
||
76 |
Permission is hereby granted, free of charge, to any person |
|
77 |
obtaining a copy of this software and associated documentation |
|
78 |
files (the 'Software'), to deal in the Software without |
|
79 |
restriction, including without limitation the rights to use, |
|
80 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
81 |
copies of the Software, and to permit persons to whom the |
|
82 |
Software is furnished to do so, subject to the following |
|
83 |
conditions: |
|
84 |
||
85 |
The above copyright notice and this permission notice shall be |
|
86 |
included in all copies or substantial portions of the Software. |
|
87 |
||
88 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
89 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
90 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
91 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
92 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
93 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
94 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
95 |
OTHER DEALINGS IN THE SOFTWARE. |
|
96 |
||
97 |
[1] Code written at SWING Research Group contain a signature |
|
98 |
of one of the above copright owners. |
|
99 |
||
752 | 100 |
" |
101 |
! ! |
|
102 |
||
103 |
!JavaMethod class methodsFor:'initialization'! |
|
104 |
||
105 |
initialize |
|
106 |
AbstractMethodInvokationSignal isNil ifTrue:[ |
|
107 |
AbstractMethodInvokationSignal := ExecutionError newSignalMayProceed:true. |
|
108 |
AbstractMethodInvokationSignal nameClass:self message:#abstractMethodInvokationSignal. |
|
109 |
AbstractMethodInvokationSignal notifierString:'attempt to execute abstract method'. |
|
110 |
||
111 |
UnresolvedClassSignal := ExecutionError newSignalMayProceed:true. |
|
112 |
UnresolvedClassSignal nameClass:self message:#unresolvedClassSignal. |
|
113 |
UnresolvedClassSignal notifierString:'unresolved class'. |
|
114 |
]. |
|
115 |
||
116 |
A_PUBLIC := 16r0001. |
|
117 |
A_PRIVATE := 16r0002. |
|
118 |
A_PROTECTED := 16r0004. |
|
119 |
A_STATIC := 16r0008. |
|
120 |
A_FINAL := 16r0010. |
|
121 |
A_SYNCHRONIZED := 16r0020. |
|
122 |
A_BRIDGE := 16r0040. |
|
123 |
A_VARARGS := 16r0080. |
|
124 |
A_NATIVE := 16r0100. |
|
125 |
A_ABSTRACT := 16r0400. |
|
126 |
A_STRICT := 16r0800. |
|
127 |
A_SYNTHETIC := 16r1000. |
|
128 |
||
129 |
R_VOID := 16r100000. |
|
130 |
R_LONG := 16r200000. |
|
131 |
R_DOUBLE := 16r300000. |
|
132 |
||
133 |
A_BREAKPOINT := 16r0800000. |
|
134 |
A_HASHANDLER := 16r1000000. |
|
135 |
||
136 |
self flags:(self flags bitOr:Behavior flagJavaMethod). |
|
137 |
||
138 |
SignatureTypeCodes := IdentityDictionary new. |
|
139 |
SignatureTypeCodes at:$B put:#byte. |
|
140 |
SignatureTypeCodes at:$C put:#char. |
|
141 |
SignatureTypeCodes at:$D put:#double. |
|
142 |
SignatureTypeCodes at:$F put:#float. |
|
143 |
SignatureTypeCodes at:$I put:#int. |
|
144 |
SignatureTypeCodes at:$J put:#long. |
|
145 |
SignatureTypeCodes at:$S put:#'unsigned short'. |
|
146 |
SignatureTypeCodes at:$Z put:#boolean. |
|
147 |
SignatureTypeCodes at:$L put:#object. |
|
148 |
SignatureTypeCodes at:$[ put:#array. |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
149 |
SignatureTypeCodes at:$T put:#typevar. |
752 | 150 |
|
151 |
ForceByteCodeDisplay := false. |
|
152 |
||
153 |
" |
|
154 |
JavaMethod initialize. |
|
155 |
JavaMethodWithHandler initialize. |
|
156 |
ForceByteCodeDisplay := true. |
|
157 |
ForceByteCodeDisplay := false. |
|
158 |
" |
|
159 |
||
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
160 |
"Modified: / 16-10-1998 / 01:29:48 / cg" |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
161 |
"Modified: / 13-08-2011 / 01:02:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 162 |
! |
163 |
||
164 |
reinitialize |
|
165 |
||
166 |
self flags:(self flags bitOr:Behavior flagJavaMethod). |
|
167 |
||
168 |
"Created: / 14-12-2010 / 20:58:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
169 |
! ! |
|
170 |
||
171 |
!JavaMethod class methodsFor:'instance creation'! |
|
172 |
||
173 |
fromMethod:aJavaMethod |
|
174 |
"create a new javaMethod, copying values from another javaMethod" |
|
175 |
||
176 |
^ self new fromMethod:aJavaMethod |
|
177 |
||
178 |
"Created: / 16.10.1998 / 01:25:12 / cg" |
|
179 |
! |
|
180 |
||
181 |
new |
|
182 |
"create a new javaMethod. |
|
183 |
Redefined, since constants are NOT stored in a literalArray, |
|
184 |
but my classes constantTable instead." |
|
185 |
||
186 |
^ self basicNew:0. |
|
187 |
||
188 |
"Created: / 16.10.1998 / 01:13:02 / cg" |
|
189 |
! ! |
|
190 |
||
191 |
!JavaMethod class methodsFor:'Signal constants'! |
|
192 |
||
193 |
abstractMethodInvokationSignal |
|
194 |
"return the signal raised when an abstract method is invoked" |
|
195 |
||
196 |
^ AbstractMethodInvokationSignal |
|
197 |
||
198 |
"Created: / 27.1.1998 / 21:50:05 / cg" |
|
199 |
! |
|
200 |
||
201 |
unresolvedClassSignal |
|
202 |
"return the signal raised when an unresolved class is referenced" |
|
203 |
||
204 |
^ UnresolvedClassSignal |
|
205 |
||
206 |
"Created: / 27.1.1998 / 21:50:05 / cg" |
|
207 |
! ! |
|
208 |
||
209 |
!JavaMethod class methodsFor:'constants'! |
|
210 |
||
211 |
A_HASHANDLER |
|
212 |
^ A_HASHANDLER |
|
213 |
||
214 |
"Created: / 26.11.1998 / 22:23:12 / cg" |
|
215 |
! |
|
216 |
||
217 |
A_NATIVE |
|
218 |
^ A_NATIVE |
|
219 |
||
220 |
"Created: / 16.5.1998 / 01:18:24 / cg" |
|
221 |
! |
|
222 |
||
223 |
A_PUBLIC |
|
224 |
^ A_PUBLIC |
|
225 |
||
226 |
"Created: / 16.5.1998 / 00:01:10 / cg" |
|
227 |
! |
|
228 |
||
229 |
A_STATIC |
|
230 |
^ A_STATIC |
|
231 |
||
232 |
"Created: / 16.5.1998 / 00:01:17 / cg" |
|
233 |
! ! |
|
234 |
||
235 |
!JavaMethod class methodsFor:'misc'! |
|
236 |
||
237 |
forceByteCodeDisplay |
|
238 |
^ ForceByteCodeDisplay |
|
239 |
||
240 |
"Created: 7.4.1997 / 20:11:39 / cg" |
|
241 |
! |
|
242 |
||
243 |
forceByteCodeDisplay:aBoolean |
|
244 |
ForceByteCodeDisplay := aBoolean |
|
245 |
||
246 |
" |
|
247 |
self forceByteCodeDisplay:true |
|
248 |
self forceByteCodeDisplay:false |
|
249 |
" |
|
250 |
||
251 |
"Created: / 4.2.1998 / 00:22:54 / cg" |
|
252 |
! |
|
253 |
||
254 |
makeJavaMethod |
|
255 |
||
256 |
self flags:((self flags |
|
257 |
bitOr:Behavior flagJavaMethod) |
|
258 |
bitClear:Behavior flagMetaMethod) |
|
259 |
||
260 |
" |
|
261 |
JavaMethod makeJavaMethod |
|
262 |
JavaMethod makeMetaMethod |
|
263 |
" |
|
264 |
||
265 |
"Created: / 23-02-2011 / 12:56:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
266 |
! |
|
267 |
||
268 |
makeMetaMethod |
|
269 |
||
270 |
self flags:((self flags |
|
271 |
bitOr:Behavior flagMetaMethod) |
|
272 |
bitClear:Behavior flagJavaMethod) |
|
273 |
" |
|
274 |
JavaMethod makeJavaMethod |
|
275 |
JavaMethod makeMetaMethod |
|
276 |
" |
|
277 |
||
278 |
"Created: / 23-02-2011 / 12:56:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
279 |
! ! |
|
280 |
||
281 |
!JavaMethod class methodsFor:'signature parsing'! |
|
282 |
||
283 |
argSigArrayFromSignature:aSignature |
|
284 |
"given a signature, return a specArray for the arguments" |
|
285 |
||
286 |
|s| |
|
287 |
||
288 |
s := aSignature readStream. |
|
289 |
s next ~~ $( ifTrue:[self halt]. |
|
290 |
||
291 |
^ self argSigArrayFromStream:s. |
|
292 |
||
293 |
" |
|
294 |
JavaMethod argSigArrayFromSignature:'(LObject;)V' |
|
295 |
JavaMethod argSigArrayFromSignature:'(BB)S' |
|
296 |
JavaMethod argSigArrayFromSignature:'(LObject;LObject;II)V' |
|
297 |
" |
|
298 |
! |
|
299 |
||
300 |
argSigArrayFromStream:s |
|
301 |
"parse an argSpec, return an array of specs - see java doc" |
|
302 |
||
303 |
|argSpec spec| |
|
304 |
||
305 |
spec := #(). |
|
306 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
307 |
"/ s peek == Character space ifTrue:[ |
|
308 |
"/ s next |
|
309 |
"/ ] ifFalse:[ |
|
923 | 310 |
argSpec := self fieldTypeFromStream:s in:nil. |
311 |
spec := spec copyWith:argSpec. |
|
752 | 312 |
"/ ] |
313 |
]. |
|
314 |
^ spec |
|
315 |
||
316 |
"Modified: / 8.1.1998 / 19:10:20 / cg" |
|
317 |
! |
|
318 |
||
319 |
argSignatureFromArgTypeArray:arr |
|
320 |
| sig | |
|
321 |
||
322 |
sig := ''. |
|
323 |
arr do: |
|
324 |
[:el | |
|
325 |
| jCLass | |
|
326 |
||
327 |
jCLass := el. |
|
328 |
jCLass isJavaClass |
|
329 |
ifFalse:[ jCLass := JavaVM reflection classForJavaClassObject:el ]. |
|
330 |
jCLass isJavaClass |
|
331 |
ifTrue: |
|
332 |
[ sig := sig , jCLass typeName. |
|
333 |
] |
|
334 |
ifFalse:[ self halt. ] ]. |
|
335 |
^ sig |
|
336 |
||
337 |
" |
|
338 |
self argSignatureFromArgTypeArray: |
|
339 |
(Array |
|
340 |
with:(JavaVM javaClassObjectForClass:(Java at:'com.sun.java.swing.JComponent')))" |
|
341 |
||
342 |
"Modified: / 13-02-1998 / 14:57:58 / cg" |
|
343 |
"Modified: / 02-03-2011 / 22:49:24 / Marcel Hlopko <hlopik@gmail.com>" |
|
344 |
! |
|
345 |
||
346 |
argSpecFromSignature:aSignature withName:name |
|
347 |
"given a signature, return a spec" |
|
348 |
||
349 |
|s argSpec| |
|
350 |
||
351 |
s := aSignature readStream. |
|
352 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
353 |
||
354 |
argSpec := self argSpecFromStream:s in:nil. |
|
355 |
||
356 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
357 |
||
358 |
^ name , ' (' , argSpec , ')' |
|
359 |
||
360 |
" |
|
361 |
JavaMethod argSpecFromSignature:'(LObject;)V' withName:'foo' |
|
362 |
JavaMethod argSpecFromSignature:'(BB)S' withName:'foo' |
|
363 |
" |
|
364 |
||
365 |
"Modified: / 8.1.1998 / 19:05:36 / cg" |
|
366 |
! |
|
367 |
||
368 |
argSpecFromStream:s in:aPackage |
|
369 |
"parse an argSpec - see java doc" |
|
370 |
||
371 |
|argSpec spec| |
|
372 |
||
373 |
spec := ''. |
|
374 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
375 |
"/ s peek == Character space ifTrue:[ |
|
376 |
"/ s next |
|
377 |
"/ ] ifFalse:[ |
|
923 | 378 |
argSpec := self fieldTypeFromStream:s in:aPackage. |
379 |
spec size ~~ 0 ifTrue:[ |
|
380 |
spec := spec , ' ' |
|
381 |
]. |
|
382 |
spec := spec , argSpec. |
|
752 | 383 |
"/ ] |
384 |
]. |
|
385 |
^ spec |
|
386 |
||
387 |
"Created: 18.3.1997 / 11:06:44 / cg" |
|
388 |
! |
|
389 |
||
390 |
argSpecWithArgsFromStream:s in:aPackage |
|
391 |
"parse an argSpec - see java doc" |
|
392 |
||
393 |
^ self argSpecWithArgsFromStream:s in:aPackage argNames:nil |
|
394 |
||
395 |
"Modified: / 8.1.1998 / 19:21:00 / cg" |
|
396 |
! |
|
397 |
||
398 |
argSpecWithArgsFromStream:s in:aPackage argNames:argNames |
|
399 |
"parse an argSpec - see java doc" |
|
400 |
||
401 |
|argSpec spec argNr nm| |
|
402 |
||
403 |
argNr := 1. |
|
404 |
spec := ''. |
|
405 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
923 | 406 |
argSpec := self fieldTypeFromStream:s in:aPackage. |
407 |
||
408 |
(argNames notNil |
|
409 |
and:[argNames size >= argNr |
|
410 |
and:[(nm := argNames at:argNr) notNil]]) ifFalse:[ |
|
411 |
nm := 'arg' , argNr printString. |
|
412 |
]. |
|
413 |
argSpec := argSpec , ' ' , nm. |
|
414 |
||
415 |
spec size ~~ 0 ifTrue:[ |
|
416 |
spec := spec , ', ' |
|
417 |
]. |
|
418 |
spec := spec , argSpec. |
|
419 |
||
420 |
argNr := argNr + 1. |
|
752 | 421 |
]. |
422 |
^ spec |
|
423 |
||
424 |
"Created: / 8.1.1998 / 19:20:36 / cg" |
|
425 |
"Modified: / 8.1.1998 / 21:14:33 / cg" |
|
426 |
! |
|
427 |
||
428 |
fieldTypeFromStream:s in:aPackage |
|
429 |
"parse a fieldTypeSpec - see java doc" |
|
430 |
||
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
431 |
|typeChar typeSym elType size className nm out nangles | |
752 | 432 |
|
433 |
typeChar := s next. |
|
434 |
||
435 |
typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown. |
|
436 |
||
437 |
typeSym == #unknown ifTrue:[ |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
438 |
^ typeSym |
752 | 439 |
]. |
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
440 |
(typeSym == #object or: [typeSym == #typevar]) ifTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
441 |
"Take care about type variables" |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
442 |
out := String new writeStream. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
443 |
[ s peek ~~ $; and:[ s peek ~~ $< ] ] whileTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
444 |
out nextPut: s next. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
445 |
]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
446 |
className := out contents. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
447 |
"Eat possible type variables" |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
448 |
(s peek == $<) ifTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
449 |
nangles := 1. s next. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
450 |
[ nangles ~~ 0 ] whileTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
451 |
s peek == $< ifTrue:[nangles := nangles + 1]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
452 |
s peek == $> ifTrue:[nangles := nangles - 1]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
453 |
s next. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
454 |
] |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
455 |
]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
456 |
s peek ~~ $; ifTrue:[self error: 'Signature corrupted?']. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
457 |
s next. "/eat ; |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
458 |
|
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
459 |
|
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
460 |
typeSym == #typevar ifTrue:[^className]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
461 |
"/ strip off default |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
462 |
nm := className. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
463 |
aPackage notNil ifTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
464 |
(nm startsWith:aPackage) ifTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
465 |
nm := nm copyFrom:(aPackage size + 2). |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
466 |
]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
467 |
]. |
752 | 468 |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
469 |
nm := nm copyReplaceAll:$/ with:$.. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
470 |
^ nm |
752 | 471 |
]. |
472 |
||
473 |
typeSym == #array ifTrue:[ |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
474 |
s peek isDigit ifTrue:[ |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
475 |
size := Integer readFrom:s. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
476 |
elType := self fieldTypeFromStream:s in:aPackage. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
477 |
^ elType , '[' , size printString , ']' |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
478 |
]. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
479 |
elType := self fieldTypeFromStream:s in:aPackage. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
480 |
^ elType , '[]' |
752 | 481 |
]. |
482 |
||
483 |
^ typeSym |
|
484 |
||
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
485 |
"Created: / 18-03-1997 / 11:07:56 / cg" |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
486 |
"Modified: / 18-07-1998 / 22:57:06 / cg" |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
487 |
"Modified: / 13-08-2011 / 01:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 488 |
! |
489 |
||
490 |
numArgsFromSignature:aSignature |
|
491 |
"given a signature, return the number of args" |
|
492 |
||
493 |
|s| |
|
494 |
||
495 |
s := aSignature readStream. |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
496 |
(aSignature includes: $() ifFalse:[self error:'Invalid signature']. |
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
497 |
[s next ~~ $(] whileTrue. |
752 | 498 |
|
499 |
^ self numArgsFromStream:s. |
|
500 |
||
501 |
" |
|
502 |
JavaMethod numArgsFromSignature:'(LObject;)V' |
|
503 |
JavaMethod numArgsFromSignature:'(BB)S' |
|
504 |
JavaMethod numArgsFromSignature:'()V' |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
505 |
JavaMethod numArgsFromSignature:'(Ljava/util/ArrayList<*>;)V' |
752 | 506 |
" |
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
507 |
|
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
877
diff
changeset
|
508 |
"Modified (comment): / 13-08-2011 / 00:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 509 |
! |
510 |
||
511 |
numArgsFromStream:s |
|
512 |
"parse an argSpec - see java doc" |
|
513 |
||
514 |
|n t| |
|
515 |
||
516 |
n := 0. |
|
517 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
923 | 518 |
t := self fieldTypeFromStream:s in:nil. |
519 |
"/ |
|
520 |
"/ some args count as 2 |
|
521 |
"/ |
|
522 |
t == #long ifTrue:[ |
|
523 |
n := n + 2. |
|
524 |
] ifFalse:[ |
|
525 |
t == #double ifTrue:[ |
|
526 |
n := n + 2 |
|
527 |
] ifFalse:[ |
|
528 |
n := n + 1. |
|
529 |
] |
|
530 |
] |
|
752 | 531 |
]. |
532 |
^ n |
|
533 |
||
534 |
"Modified: / 8.1.1998 / 19:10:25 / cg" |
|
535 |
! |
|
536 |
||
537 |
retValSpecFromSignature:aSignature in:aPackage |
|
538 |
"given a signature, return a spec" |
|
539 |
||
540 |
|s argSpec retvalSpec| |
|
541 |
||
542 |
s := aSignature readStream. |
|
543 |
s next ~~ $( ifTrue:[self halt]. |
|
544 |
||
545 |
argSpec := self argSpecFromStream:s in:aPackage. |
|
546 |
||
547 |
s next ~~ $) ifTrue:[self halt]. |
|
548 |
||
549 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
550 |
||
551 |
^ retvalSpec |
|
552 |
||
553 |
" |
|
554 |
JavaMethod retValSpecFromSignature:'(LObject;)V' |
|
555 |
JavaMethod retValSpecFromSignature:'(BB)S' |
|
556 |
" |
|
557 |
||
558 |
"Created: 18.3.1997 / 11:11:50 / cg" |
|
559 |
! |
|
560 |
||
561 |
returnTypeFromSignature:aSignature in:aPackage |
|
562 |
"given a signature, return its type as a string" |
|
563 |
||
564 |
|s c| |
|
565 |
||
566 |
s := aSignature readStream. |
|
567 |
(c := s peek) ~~ $( ifTrue:[ |
|
923 | 568 |
c == $' ifTrue:[ |
569 |
[s peek ~= $'] whileTrue:[s next]. |
|
570 |
s next. |
|
571 |
^ (self retvalSpecFromStream:s in:aPackage) |
|
572 |
]. |
|
573 |
^ (self retvalSpecFromStream:s in:aPackage) |
|
752 | 574 |
]. |
575 |
||
576 |
s next. |
|
577 |
self argSpecFromStream:s in:aPackage. |
|
578 |
s next ~~ $) ifTrue:[self halt. ^ nil]. |
|
579 |
||
580 |
^ (self retvalSpecFromStream:s in:aPackage) |
|
581 |
||
582 |
" |
|
583 |
JavaMethod returnTypeFromSignature:'(LObject;)V' |
|
584 |
JavaMethod returnTypeFromSignature:'(BB)S' |
|
585 |
JavaMethod returnTypeFromSignature:'()J' |
|
586 |
JavaMethod returnTypeFromSignature:'''first''J' |
|
587 |
" |
|
588 |
||
589 |
"Created: / 1.8.1997 / 10:54:31 / cg" |
|
590 |
"Modified: / 8.1.1998 / 19:09:06 / cg" |
|
591 |
! |
|
592 |
||
593 |
returnsVoidFromSignature:aSignature |
|
594 |
"given a signature, return true if it returns void, false if not" |
|
595 |
||
596 |
^ (self typeFromSignature:aSignature in:nil) = 'void' |
|
597 |
||
598 |
" |
|
599 |
JavaMethod returnsVoidFromSignature:'(LObject;)V' |
|
600 |
JavaMethod returnsVoidFromSignature:'(BB)S' |
|
601 |
" |
|
602 |
||
603 |
"Modified: / 8.1.1998 / 19:13:53 / cg" |
|
604 |
! |
|
605 |
||
606 |
retvalSpecFromStream:s in:aPackage |
|
607 |
"parse a retvalSpec - see java doc" |
|
608 |
||
609 |
|spec| |
|
610 |
||
611 |
s atEnd ifTrue:[self halt. ^ #void]. |
|
612 |
s peek == $V ifTrue:[^ #void]. |
|
613 |
spec := self fieldTypeFromStream:s in:aPackage. |
|
614 |
spec knownAsSymbol ifTrue:[ |
|
923 | 615 |
^ spec asSymbol |
752 | 616 |
]. |
617 |
^ spec |
|
618 |
||
619 |
"Created: / 18.3.1997 / 11:12:19 / cg" |
|
620 |
"Modified: / 7.4.1998 / 22:28:27 / cg" |
|
621 |
! |
|
622 |
||
623 |
specComponentsWithArgsFromSignature:aSignature withName:name in:aPackage |
|
624 |
"given a signature, return a spec" |
|
625 |
||
626 |
|s argSpec retvalSpec| |
|
627 |
||
628 |
s := aSignature readStream. |
|
629 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
630 |
||
631 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage. |
|
632 |
||
633 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
634 |
||
635 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
636 |
||
637 |
^ Array with:retvalSpec with:name with:argSpec |
|
638 |
||
639 |
" |
|
640 |
JavaMethod specWithArgsFromSignature:'(LObject;)V' withName:'foo' in:nil |
|
641 |
JavaMethod specComponentsWithArgsFromSignature:'(LObject;)V' withName:'foo' in:nil |
|
642 |
" |
|
643 |
||
644 |
"Created: 18.3.1997 / 11:06:22 / cg" |
|
645 |
"Modified: 1.8.1997 / 11:03:50 / cg" |
|
646 |
! |
|
647 |
||
648 |
specFromSignature:aSignature withName:name argNames:argNames in:aPackage |
|
649 |
"given a signature, return a spec" |
|
650 |
||
651 |
|s argSpec retvalSpec| |
|
652 |
||
653 |
s := aSignature readStream. |
|
654 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
655 |
||
656 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage argNames:argNames. |
|
657 |
||
658 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
659 |
||
660 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
661 |
||
662 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
663 |
||
664 |
" |
|
665 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' argNames:#('a') in:nil |
|
666 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' argNames:#('a' 'b') in:nil |
|
667 |
" |
|
668 |
||
669 |
"Created: / 18.3.1997 / 11:06:22 / cg" |
|
670 |
"Modified: / 8.1.1998 / 21:14:43 / cg" |
|
671 |
! |
|
672 |
||
673 |
specFromSignature:aSignature withName:name in:aPackage |
|
674 |
"given a signature, return a spec" |
|
675 |
||
676 |
|s argSpec retvalSpec| |
|
677 |
||
678 |
s := aSignature readStream. |
|
679 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
680 |
||
681 |
argSpec := self argSpecFromStream:s in:aPackage. |
|
682 |
||
683 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
684 |
||
685 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
686 |
||
687 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
688 |
||
689 |
" |
|
690 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' in:nil |
|
691 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' in:nil |
|
692 |
" |
|
693 |
||
694 |
"Created: / 18.3.1997 / 11:06:22 / cg" |
|
695 |
"Modified: / 8.1.1998 / 21:06:32 / cg" |
|
696 |
! |
|
697 |
||
698 |
specTextFromSignature:aSignature in:aPackage withName:name |
|
699 |
"given a signature, return a spec as boldified text" |
|
700 |
||
701 |
|s argSpec retvalSpec| |
|
702 |
||
703 |
s := aSignature readStream. |
|
704 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
705 |
||
706 |
argSpec := self argSpecFromStream:s in:aPackage. |
|
707 |
||
708 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
709 |
||
710 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
711 |
||
712 |
"/ ^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
|
713 |
^ (name allBold) , ' (' , argSpec , ')' |
|
714 |
||
715 |
" |
|
716 |
JavaMethod specTextFromSignature:'(LObject;)V' withName:'foo' |
|
717 |
JavaMethod specTextFromSignature:'(BB)S' withName:'foo' |
|
718 |
" |
|
719 |
||
720 |
"Modified: / 8.1.1998 / 19:11:20 / cg" |
|
721 |
! |
|
722 |
||
723 |
specTextFromSignature:aSignature withName:name |
|
724 |
"given a signature, return a spec as boldified text" |
|
725 |
||
726 |
|s argSpec retvalSpec| |
|
727 |
||
728 |
s := aSignature readStream. |
|
729 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
730 |
||
731 |
argSpec := self argSpecFromStream:s in:nil. |
|
732 |
||
733 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
734 |
||
735 |
retvalSpec := self retvalSpecFromStream:s in:nil. |
|
736 |
||
737 |
^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
|
738 |
||
739 |
" |
|
740 |
JavaMethod specTextFromSignature:'(LObject;)V' withName:'foo' |
|
741 |
JavaMethod specTextFromSignature:'(BB)S' withName:'foo' |
|
742 |
" |
|
743 |
||
744 |
"Modified: / 8.1.1998 / 19:11:20 / cg" |
|
745 |
! |
|
746 |
||
747 |
specTextWithArgsFromSignature:aSignature withName:name in:aPackage |
|
748 |
"given a signature, return a spec" |
|
749 |
||
750 |
|s argSpec retvalSpec| |
|
751 |
||
752 |
s := aSignature readStream. |
|
753 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
754 |
||
755 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage. |
|
756 |
||
757 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
758 |
||
759 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
760 |
||
761 |
^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
|
762 |
||
763 |
" |
|
764 |
JavaMethod specWithArgsFromSignature:'(LObject;)V' withName:'foo' in:nil |
|
765 |
JavaMethod specWithArgsFromSignature:'(BB)S' withName:'foo' in:nil |
|
766 |
" |
|
767 |
||
768 |
"Modified: 20.3.1997 / 12:50:10 / cg" |
|
769 |
"Created: 1.8.1997 / 10:43:57 / cg" |
|
770 |
! |
|
771 |
||
772 |
specWithArgsFromSignature:aSignature withName:name in:aPackage |
|
773 |
"given a signature, return a spec" |
|
774 |
||
775 |
|s argSpec retvalSpec| |
|
776 |
||
777 |
s := aSignature readStream. |
|
778 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
779 |
||
780 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage. |
|
781 |
||
782 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
783 |
||
784 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
785 |
||
786 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
787 |
||
788 |
" |
|
789 |
JavaMethod specWithArgsFromSignature:'(LObject;)V' withName:'foo' in:nil |
|
790 |
JavaMethod specWithArgsFromSignature:'(BB)S' withName:'foo' in:nil |
|
791 |
" |
|
792 |
||
793 |
"Created: 18.3.1997 / 11:06:22 / cg" |
|
794 |
"Modified: 20.3.1997 / 12:50:10 / cg" |
|
795 |
! |
|
796 |
||
797 |
typeFromSignature:aSignature in:package |
|
798 |
"given a signature, return its type as a string" |
|
799 |
||
800 |
|s c| |
|
801 |
||
802 |
s := aSignature readStream. |
|
803 |
(c := s peek) ~~ $( ifTrue:[ |
|
923 | 804 |
c == $' ifTrue:[ |
805 |
s next. |
|
806 |
[s peek ~= $'] whileTrue:[s next]. |
|
807 |
s next. |
|
808 |
^ (self retvalSpecFromStream:s in:package) |
|
809 |
]. |
|
810 |
^ (self retvalSpecFromStream:s in:package) |
|
752 | 811 |
]. |
812 |
||
813 |
s next. |
|
814 |
self argSpecFromStream:s in:nil. |
|
815 |
s next ~~ $) ifTrue:[self halt. ^ nil]. |
|
816 |
||
817 |
^ (self retvalSpecFromStream:s in:package) |
|
818 |
||
819 |
" |
|
820 |
JavaMethod typeFromSignature:'(LObject;)Ljava/lang/Object' |
|
821 |
JavaMethod typeFromSignature:'(LObject;)Ljava/lang/Object' in:'java.lang' |
|
822 |
" |
|
823 |
||
824 |
"Created: / 1.8.1997 / 10:50:38 / cg" |
|
825 |
"Modified: / 8.1.1998 / 19:09:31 / cg" |
|
826 |
! ! |
|
827 |
||
919 | 828 |
!JavaMethod methodsFor:'* As yet uncategorized *'! |
829 |
||
830 |
sends:symbol1 or:symbol2 |
|
831 |
||
832 |
^false |
|
833 |
! ! |
|
834 |
||
752 | 835 |
!JavaMethod methodsFor:'accessing'! |
836 |
||
837 |
accessFlags |
|
838 |
"java calls this the modifiers" |
|
839 |
||
840 |
^ accessFlags |
|
841 |
||
842 |
"Created: / 9.4.1998 / 17:49:44 / cg" |
|
843 |
! |
|
844 |
||
845 |
annotations |
|
846 |
^ annotations ifNil:[JavaMethodAnnotationContainer empty]. |
|
847 |
||
848 |
"Modified: / 03-03-2011 / 23:51:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
849 |
! |
|
850 |
||
851 |
annotations:something |
|
852 |
annotations := something. |
|
853 |
! |
|
854 |
||
855 |
argSignature |
|
913 | 856 |
^ self class argSigArrayFromSignature:descriptor |
752 | 857 |
! |
858 |
||
872 | 859 |
asByteCodeMethod |
860 |
||
861 |
"JavaMethods are always bytecode methods" |
|
862 |
||
863 |
^self |
|
864 |
||
865 |
"Created: / 18-07-2011 / 20:48:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
866 |
! |
|
867 |
||
752 | 868 |
comment |
869 |
"should access the source here, and parse any method comment" |
|
870 |
||
871 |
^ nil |
|
872 |
! |
|
873 |
||
874 |
constantPool |
|
875 |
^ javaClass constantPool |
|
876 |
||
877 |
"Modified: 16.4.1996 / 12:36:27 / cg" |
|
878 |
"Created: 16.4.1996 / 15:28:50 / cg" |
|
879 |
! |
|
880 |
||
881 |
containingClass |
|
882 |
^ javaClass |
|
883 |
||
884 |
! |
|
885 |
||
886 |
decompiledBytecode |
|
887 |
|s| |
|
888 |
||
889 |
s := '' writeStream. |
|
890 |
JavaDecompiler decompile:self to:s. |
|
891 |
^ s contents |
|
892 |
||
893 |
"Created: 7.4.1997 / 20:10:37 / cg" |
|
894 |
! |
|
895 |
||
896 |
decompiledSource |
|
897 |
|s| |
|
898 |
||
899 |
s := '' writeStream. |
|
900 |
self decompileSourceTo:s. |
|
901 |
^ s contents |
|
902 |
||
903 |
"Modified: 30.7.1997 / 16:27:55 / cg" |
|
904 |
! |
|
905 |
||
906 |
descriptor |
|
907 |
||
913 | 908 |
^ JavaDescriptor fromString: descriptor |
909 |
||
910 |
"Created: / 16-04-1996 / 11:34:29 / cg" |
|
911 |
"Modified: / 14-08-2011 / 19:32:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 912 |
! |
913 |
||
914 |
ensureHasAnnotations |
|
915 |
annotations |
|
916 |
ifNil:[ annotations := JavaMethodAnnotationContainer for:self ]. |
|
917 |
^ annotations |
|
918 |
||
919 |
"Created: / 25-02-2011 / 16:02:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
920 |
"Modified: / 28-02-2011 / 16:33:00 / Marcel Hlopko <hlopik@gmail.com>" |
|
921 |
! |
|
922 |
||
923 |
exceptionHandlerTable |
|
924 |
^ nil |
|
925 |
||
926 |
"Created: / 16.10.1998 / 01:50:51 / cg" |
|
927 |
! |
|
928 |
||
929 |
exceptionTable |
|
930 |
^ nil |
|
931 |
||
932 |
"Created: / 16.10.1998 / 01:51:04 / cg" |
|
933 |
! |
|
934 |
||
935 |
firstInstructionLineNumber |
|
936 |
ForceByteCodeDisplay == true ifTrue:[ ^ 1]. |
|
937 |
lineNumberTable notNil ifTrue:[ ^ lineNumberTable at:2]. |
|
938 |
^ 0. |
|
939 |
||
940 |
"Created: / 17-12-2010 / 17:02:46 / Jan Kurs <kurs.jan@post.cz>" |
|
941 |
"Modified: / 08-01-2011 / 16:30:16 / Jan Kurs <kurs.jan@post.cz>" |
|
942 |
! |
|
943 |
||
944 |
getExceptionTable |
|
945 |
||
946 |
^ nil |
|
947 |
||
948 |
"Created: / 04-02-2011 / 23:07:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
949 |
! |
|
950 |
||
951 |
getSourcePosition |
|
952 |
^ 1 |
|
953 |
! |
|
954 |
||
955 |
hasLineNumberInformation |
|
956 |
^ lineNumberTable notNil |
|
957 |
||
958 |
"Created: 16.4.1996 / 12:34:04 / cg" |
|
959 |
"Modified: 16.4.1996 / 12:49:06 / cg" |
|
960 |
! |
|
961 |
||
962 |
javaByteCode |
|
963 |
"/ ^ javaByteCode |
|
964 |
^ byteCode |
|
965 |
||
966 |
"Created: 16.4.1996 / 14:55:44 / cg" |
|
967 |
"Modified: 1.8.1997 / 00:08:45 / cg" |
|
968 |
! |
|
969 |
||
970 |
javaClass |
|
971 |
^ javaClass |
|
972 |
||
973 |
"Modified: 16.4.1996 / 12:36:27 / cg" |
|
974 |
"Created: 16.4.1996 / 14:55:44 / cg" |
|
975 |
! |
|
976 |
||
841 | 977 |
javaExceptionTable |
978 |
^ nil |
|
979 |
||
980 |
"Created: / 04-06-2011 / 18:16:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
981 |
! |
|
982 |
||
752 | 983 |
javaNumArgs |
984 |
^ self argSignature size. |
|
985 |
||
986 |
"Created: / 14-03-2011 / 15:50:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
987 |
! |
|
988 |
||
989 |
lineNumber |
|
990 |
lineNumberTable isNil ifTrue:[^ nil]. |
|
991 |
^ lineNumberTable at:2 |
|
992 |
||
993 |
"Created: 16.4.1996 / 12:34:04 / cg" |
|
994 |
"Modified: 16.4.1996 / 12:49:06 / cg" |
|
995 |
! |
|
996 |
||
997 |
lineNumberTable |
|
998 |
"/ lineNumberTable ifNil:[ lineNumberTable := Dictionary new.]. |
|
999 |
^ lineNumberTable |
|
1000 |
||
1001 |
"Created: / 16-04-1996 / 12:34:04 / cg" |
|
1002 |
"Modified: / 13-12-2010 / 11:06:40 / Jan Kurs <kurs.jan@post.cz>" |
|
1003 |
! |
|
1004 |
||
1005 |
literalsDetect:aBlock ifNone:exceptionBlock |
|
1006 |
"execute a one arg block for each of our literals. |
|
1007 |
return the first literal for which aBlock returns true" |
|
1008 |
||
1009 |
"/ sigh - must first extract all accessed literals ... |
|
1010 |
"/ must deparse the byteCode in order to do this. |
|
1011 |
||
1012 |
|walker| |
|
1013 |
||
1014 |
walker := JavaByteCodeEnumerator new. |
|
1015 |
walker literalAction:[:pc :slotIndex :const | |
|
1016 |
const isJavaMethodRef ifTrue:[ |
|
1017 |
(aBlock value:(const name)) ifTrue:[^ const name]. |
|
1018 |
] ifFalse:[ |
|
1019 |
const isJavaClassRef ifTrue:[ |
|
1020 |
(aBlock value:(const name)) ifTrue:[^ const name]. |
|
1021 |
] |
|
1022 |
] |
|
1023 |
]. |
|
1024 |
walker decompile:self to:nil. |
|
1025 |
^ nil |
|
1026 |
||
1027 |
"Created: / 9.11.1999 / 15:21:40 / cg" |
|
1028 |
"Modified: / 24.12.1999 / 02:55:55 / cg" |
|
1029 |
! |
|
1030 |
||
1031 |
localVariableTable |
|
1032 |
^ localVariableTable |
|
1033 |
||
1034 |
" |
|
1035 |
JavaMethod allInstancesDo:[:m| m localVariableTable notNil ifTrue:[self halt]] |
|
1036 |
" |
|
1037 |
! |
|
1038 |
||
872 | 1039 |
mclass |
1040 |
^ self javaClass |
|
1041 |
! |
|
1042 |
||
1043 |
mclass: anObject |
|
1044 |
||
1045 |
javaClass := anObject |
|
1046 |
||
1047 |
"Created: / 18-10-2010 / 19:01:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1048 |
! |
|
1049 |
||
752 | 1050 |
methodArgAndVarNames |
1051 |
^ "((1 to:self numArgs) collect:[:i | 'arg' , i printString])" |
|
1052 |
self methodArgNames |
|
1053 |
, |
|
1054 |
"((1 to:self numVars) collect:[:i | 'local' , i printString])" |
|
1055 |
self methodVarNames |
|
1056 |
||
1057 |
"Modified: / 23-11-2010 / 19:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1058 |
! |
|
1059 |
||
1060 |
methodArgNames |
|
1061 |
|nA| |
|
1062 |
||
1063 |
nA := self numArgs. |
|
1064 |
localVariableTable notNil ifTrue:[ |
|
1065 |
^ (1 to:nA) collect: |
|
1066 |
[:argIndex | |
|
1067 |
|slot name| |
|
1068 |
"/ search for an entry with that index (slot), |
|
1069 |
"/ which has is valid at PC 0 |
|
1070 |
||
1071 |
self isStatic ifTrue:[ |
|
1072 |
slot := argIndex - 1 |
|
1073 |
] ifFalse:[ |
|
1074 |
slot := argIndex "/+ 1 |
|
1075 |
]. |
|
1076 |
name := localVariableTable nameForSlot:slot atPC:0. |
|
1077 |
name isNil ifTrue:[ |
|
1078 |
'arg' , argIndex printString |
|
1079 |
] ifFalse:[ |
|
1080 |
name |
|
1081 |
]. |
|
1082 |
] |
|
1083 |
]. |
|
1084 |
^ (1 to:nA) collect:[:i | 'arg' , i printString] |
|
1085 |
||
1086 |
"Modified: / 23-11-2010 / 19:47:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1087 |
! |
|
1088 |
||
1089 |
methodVarNames |
|
1090 |
|nV| |
|
1091 |
||
1092 |
nV := self numVars. |
|
1093 |
localVariableTable notNil ifTrue:[ |
|
1094 |
^ (self numArgs + 1 to: self numArgs + nV) collect: |
|
1095 |
[:argIndex | |
|
1096 |
|slot name| |
|
1097 |
"/ search for an entry with that index (slot), |
|
1098 |
"/ which has is valid at PC 0 |
|
1099 |
||
1100 |
self isStatic ifTrue:[ |
|
1101 |
slot := argIndex - 1 |
|
1102 |
] ifFalse:[ |
|
1103 |
slot := argIndex"/ + 1 |
|
1104 |
]. |
|
1105 |
name := localVariableTable nameForSlot:slot atPC:0. |
|
1106 |
name isNil ifTrue:[ |
|
1107 |
'local' , argIndex printString |
|
1108 |
] ifFalse:[ |
|
1109 |
name |
|
1110 |
]. |
|
1111 |
] |
|
1112 |
]. |
|
1113 |
^ (1 to:nV) collect:[:i | 'local' , i printString] |
|
1114 |
||
1115 |
"Created: / 23-11-2010 / 19:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1116 |
! |
|
1117 |
||
1118 |
name |
|
913 | 1119 |
^ (selector copyWithoutLast:descriptor size) asSymbol |
752 | 1120 |
|
1121 |
"Created: 16.4.1996 / 11:34:22 / cg" |
|
1122 |
! |
|
1123 |
||
872 | 1124 |
nameSpaceName |
1125 |
||
1126 |
^'' |
|
1127 |
||
1128 |
"Created: / 18-10-2010 / 19:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1129 |
! |
|
1130 |
||
752 | 1131 |
numLocals |
1132 |
^super numVars. |
|
1133 |
"/ numLocals isNil ifTrue:[^ 0]. |
|
1134 |
"/ ^ numLocals |
|
1135 |
||
1136 |
"Modified: / 3.1.1998 / 21:15:38 / cg" |
|
1137 |
! |
|
1138 |
||
1139 |
numVars |
|
1140 |
|n| |
|
1141 |
||
1142 |
"/ a Java-stackframe includes the args in the locals |
|
1143 |
n := self numLocals - self numArgs. |
|
1144 |
^ n |
|
1145 |
||
1146 |
"Modified: / 13.1.1998 / 17:34:37 / cg" |
|
1147 |
! |
|
1148 |
||
923 | 1149 |
originalMethodIfWrapped |
1150 |
"return the method the receiver is wrapping - none here" |
|
1151 |
||
1152 |
^ self |
|
1153 |
||
1154 |
"Created: / 22-10-2010 / 11:46:07 / cg" |
|
1155 |
! |
|
1156 |
||
752 | 1157 |
previousVersion |
1158 |
^ nil |
|
1159 |
||
1160 |
"Created: 30.7.1997 / 15:56:18 / cg" |
|
1161 |
! |
|
1162 |
||
872 | 1163 |
previousVersionCode |
1164 |
||
1165 |
^nil |
|
1166 |
||
1167 |
"Created: / 18-10-2010 / 20:15:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1168 |
! |
|
1169 |
||
752 | 1170 |
retValSignature |
913 | 1171 |
^ self class retValSpecFromSignature:descriptor in:nil |
752 | 1172 |
|
1173 |
"Modified: / 8.1.1998 / 19:06:40 / cg" |
|
1174 |
! |
|
1175 |
||
1176 |
returnType |
|
1177 |
"/ ^ returnType |
|
913 | 1178 |
^ self class typeFromSignature:descriptor in:nil. |
752 | 1179 |
|
1180 |
"Modified: / 16.10.1998 / 00:17:43 / cg" |
|
1181 |
! |
|
1182 |
||
1183 |
returnTypeClass |
|
1184 |
|cls returnType| |
|
1185 |
||
1186 |
(returnType := self returnType) isNil ifTrue:[ |
|
923 | 1187 |
self halt. |
752 | 1188 |
]. |
1189 |
cls := Java at:returnType. |
|
1190 |
cls notNil ifTrue:[^ cls]. |
|
1191 |
||
1192 |
returnType == #void ifTrue:[ |
|
923 | 1193 |
^ nil |
752 | 1194 |
]. |
1195 |
returnType == #double ifTrue:[ |
|
923 | 1196 |
'warning: no returnTypeClass for double' printCR. |
752 | 1197 |
"/ self halt:'no returnTypeClass for double'. |
923 | 1198 |
^ nil |
752 | 1199 |
]. |
1200 |
returnType == #float ifTrue:[ |
|
923 | 1201 |
'warning: no returnTypeClass for float' printCR. |
752 | 1202 |
"/ self halt:'no returnTypeClass for float'. |
923 | 1203 |
^ nil |
752 | 1204 |
]. |
1205 |
returnType == #long ifTrue:[ |
|
923 | 1206 |
'warning: no returnTypeClass for long' printCR. |
752 | 1207 |
"/ self halt:'no returnTypeClass for long'. |
923 | 1208 |
^ nil |
752 | 1209 |
]. |
1210 |
returnType == #int ifTrue:[ |
|
923 | 1211 |
'warning: no returnTypeClass for int' printCR. |
752 | 1212 |
"/ self halt:'no returnTypeClass for int'. |
923 | 1213 |
^ nil |
752 | 1214 |
]. |
1215 |
returnType == #boolean ifTrue:[ |
|
923 | 1216 |
'warning: no returnTypeClass for boolean' printCR. |
752 | 1217 |
"/ self halt:'no returnTypeClass for boolean'. |
923 | 1218 |
^ nil |
752 | 1219 |
]. |
1220 |
self halt. |
|
1221 |
^ nil |
|
1222 |
||
1223 |
"Created: / 13.2.1998 / 15:08:26 / cg" |
|
1224 |
"Modified: / 16.10.1998 / 00:16:07 / cg" |
|
1225 |
! |
|
1226 |
||
1227 |
returnsDouble |
|
1228 |
^ self returnType == #double |
|
1229 |
||
1230 |
"Modified: / 16.10.1998 / 00:18:24 / cg" |
|
1231 |
! |
|
1232 |
||
1233 |
returnsLong |
|
1234 |
^ self returnType == #long |
|
1235 |
||
1236 |
"Modified: / 16.10.1998 / 00:18:41 / cg" |
|
1237 |
! |
|
1238 |
||
1239 |
returnsVoid |
|
1240 |
^ self returnType == #void |
|
1241 |
||
1242 |
"Modified: / 16-10-1998 / 00:18:53 / cg" |
|
1243 |
"Modified: / 22-03-2011 / 12:27:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1244 |
! |
|
1245 |
||
1246 |
selector |
|
1247 |
"/ could theoretically be extracted from my classes |
|
1248 |
"/ methodDictionary via: |
|
1249 |
"/ ^ javaClass methodDictionary keyAtValue:self ifAbsent:nil. |
|
1250 |
||
1251 |
^ selector |
|
1252 |
||
1253 |
"Created: / 7.1.1998 / 14:05:11 / cg" |
|
1254 |
"Modified: / 16.10.1998 / 13:41:06 / cg" |
|
1255 |
! |
|
1256 |
||
1257 |
signature |
|
913 | 1258 |
^ signature ? descriptor |
752 | 1259 |
! |
1260 |
||
1261 |
source |
|
1262 |
| classSource | |
|
1263 |
"/ self isNative ifTrue:[ |
|
1264 |
"/ ^ 'native method' |
|
1265 |
"/ ]. |
|
1266 |
ForceByteCodeDisplay == true ifTrue:[ |
|
1267 |
^ self decompiledBytecode |
|
1268 |
]. |
|
1269 |
lineNumberTable notNil ifTrue:[ |
|
1270 |
classSource := javaClass source. |
|
1271 |
classSource notNil ifTrue:[ ^ classSource]. |
|
1272 |
]. |
|
1273 |
^ self decompiledSource |
|
1274 |
||
1275 |
"Modified: / 04-01-1998 / 13:48:35 / cg" |
|
1276 |
"Modified: / 13-12-2010 / 11:06:51 / Jan Kurs <kurs.jan@post.cz>" |
|
1277 |
! |
|
1278 |
||
1279 |
sourceFilename |
|
1280 |
^ javaClass sourceFile |
|
1281 |
! |
|
1282 |
||
1283 |
sourceLineNumber |
|
1284 |
" |
|
1285 |
sourceLineNumber ifNil: [ |
|
1286 |
sourceLineNumber := (JavaSourceCodeCache new) |
|
1287 |
findLineForMethod: self |
|
1288 |
inClass:javaClass. |
|
1289 |
]. |
|
1290 |
" |
|
1291 |
sourceLineNumber := 0. |
|
1292 |
||
1293 |
sourceLineNumber == 0 ifTrue: |
|
1294 |
[ |
|
1295 |
"There is something wrong with parsing" |
|
1296 |
"/ self halt. |
|
1297 |
self breakPoint: #libjava. |
|
1298 |
sourceLineNumber := self firstInstructionLineNumber -2. |
|
1299 |
]. |
|
1300 |
||
1301 |
^ sourceLineNumber. |
|
1302 |
||
1303 |
"Created: / 30-07-1997 / 15:40:45 / cg" |
|
1304 |
"Modified: / 13-12-2010 / 23:46:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
1305 |
"Modified: / 08-01-2011 / 16:20:40 / Jan Kurs <kurs.jan@post.cz>" |
|
1306 |
"Modified: / 05-02-2011 / 22:29:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
872 | 1307 |
! |
1308 |
||
1309 |
wrapper |
|
1310 |
||
1311 |
^nil |
|
1312 |
||
1313 |
"Created: / 18-10-2010 / 19:11:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 1314 |
! ! |
1315 |
||
1316 |
!JavaMethod methodsFor:'compiler interface'! |
|
1317 |
||
1318 |
programmingLanguage |
|
1319 |
||
1320 |
^JavaLanguage instance |
|
1321 |
"Created: / 26-10-2010 / 23:42:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1322 |
! ! |
|
1323 |
||
1324 |
!JavaMethod methodsFor:'debugging'! |
|
1325 |
||
1326 |
breakPoint |
|
1327 |
Debugger enter:thisContext sender withMessage:'breakpoint' |
|
1328 |
||
1329 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1330 |
! |
|
1331 |
||
1332 |
clearBreakPoint |
|
1333 |
self hasCode ifTrue:[ |
|
923 | 1334 |
MessageTracer unwrapMethod:self |
752 | 1335 |
]. |
1336 |
accessFlags := (accessFlags bitClear:A_BREAKPOINT). |
|
1337 |
||
1338 |
"Modified: / 13.11.1998 / 23:31:00 / cg" |
|
1339 |
! |
|
1340 |
||
1341 |
isCounting |
|
1342 |
^ false. |
|
1343 |
||
1344 |
"Created: / 12.1.1998 / 20:02:23 / cg" |
|
1345 |
! |
|
1346 |
||
1347 |
isCountingMemoryUsage |
|
1348 |
^ false. |
|
1349 |
||
1350 |
"Created: / 12.1.1998 / 20:03:22 / cg" |
|
1351 |
! |
|
1352 |
||
1353 |
setBreakPoint |
|
1354 |
self hasCode ifTrue:[ |
|
923 | 1355 |
MessageTracer trapMethod:self |
752 | 1356 |
]. |
1357 |
accessFlags := (accessFlags bitOr:A_BREAKPOINT). |
|
1358 |
||
1359 |
"Modified: / 13.11.1998 / 23:30:45 / cg" |
|
1360 |
! |
|
1361 |
||
1362 |
setTraceFullPoint |
|
1363 |
"not yet implemented" |
|
1364 |
||
1365 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1366 |
"Created: / 12.1.1998 / 20:04:45 / cg" |
|
1367 |
! |
|
1368 |
||
1369 |
setTracePoint |
|
1370 |
"not yet implemented" |
|
1371 |
||
1372 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1373 |
"Created: / 12.1.1998 / 20:04:02 / cg" |
|
1374 |
! |
|
1375 |
||
1376 |
setTraceSenderPoint |
|
1377 |
"not yet implemented" |
|
1378 |
||
1379 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1380 |
"Created: / 12.1.1998 / 20:04:35 / cg" |
|
1381 |
! |
|
1382 |
||
1383 |
startCounting |
|
1384 |
"not yet implemented" |
|
1385 |
||
1386 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1387 |
"Created: / 12.1.1998 / 20:05:01 / cg" |
|
1388 |
! |
|
1389 |
||
1390 |
startCountingMemoryUsage |
|
1391 |
"not yet implemented" |
|
1392 |
||
1393 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1394 |
"Created: / 12.1.1998 / 20:05:04 / cg" |
|
1395 |
! |
|
1396 |
||
1397 |
startTiming |
|
1398 |
"not yet implemented" |
|
1399 |
||
1400 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1401 |
"Created: / 12.1.1998 / 20:04:57 / cg" |
|
1402 |
! ! |
|
1403 |
||
1404 |
!JavaMethod methodsFor:'decompiling'! |
|
1405 |
||
1406 |
decompileSourceTo:aStream |
|
1407 |
|argNames| |
|
1408 |
||
1409 |
byteCode isNil ifTrue:[ |
|
1410 |
self isPublic ifTrue:[ |
|
1411 |
aStream nextPutAll:'public '. |
|
1412 |
]. |
|
1413 |
self isProtected ifTrue:[ |
|
1414 |
aStream nextPutAll:'protected '. |
|
1415 |
]. |
|
1416 |
self isPrivate ifTrue:[ |
|
1417 |
aStream nextPutAll:'private '. |
|
1418 |
]. |
|
1419 |
self isStatic ifTrue:[ |
|
1420 |
aStream nextPutAll:'static '. |
|
1421 |
]. |
|
1422 |
||
1423 |
self isNative ifTrue:[ |
|
1424 |
aStream nextPutAll:'native '. |
|
1425 |
]. |
|
1426 |
self isAbstract ifTrue:[ |
|
1427 |
aStream nextPutAll:'abstract '. |
|
1428 |
]. |
|
1429 |
argNames := #('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6' 'arg7' 'arg8' 'arg9'). |
|
1430 |
aStream nextPutAll:(self signatureNameWithArgNames:argNames). |
|
1431 |
aStream nextPutAll:';'; cr. |
|
1432 |
^ self |
|
1433 |
]. |
|
1434 |
||
1435 |
" |
|
1436 |
JavaDeparser isNil ifTrue:[ |
|
1437 |
aStream nextPutAll:'// Sorry - no decompiler'. |
|
1438 |
^ self |
|
1439 |
]. |
|
1440 |
" |
|
1441 |
||
1442 |
||
1443 |
"/ self isNative ifFalse:[ |
|
1444 |
"/ self isAbstract ifFalse:[ |
|
1445 |
aStream nextPutAll:'// source not available...'; cr. |
|
1446 |
SignalSet anySignal handle:[:ex | |
|
1447 |
ex signal == Object haltSignal ifTrue:[ex reject]. |
|
1448 |
ex signal == MessageTracer breakpointSignal ifTrue:[ex reject]. |
|
1449 |
ex signal == Signal noHandlerSignal ifTrue:[ex reject]. |
|
1450 |
||
1451 |
aStream nextPutAll:'error while decompiling:'. |
|
1452 |
aStream cr; cr; spaces:4. |
|
1453 |
aStream nextPutAll:ex errorString. |
|
1454 |
aStream cr. |
|
1455 |
aStream nextPutAll:ex suspendedContext printString. |
|
1456 |
aStream cr. |
|
1457 |
aStream nextPutAll:ex suspendedContext sender printString. |
|
1458 |
aStream cr. |
|
1459 |
aStream nextPutAll:ex suspendedContext sender sender printString. |
|
1460 |
aStream cr. |
|
1461 |
aStream nextPutAll:ex suspendedContext sender sender sender printString. |
|
1462 |
aStream cr. |
|
1463 |
aStream nextPutAll:ex suspendedContext sender sender sender sender printString. |
|
1464 |
aStream cr. |
|
1465 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender printString. |
|
1466 |
aStream cr. |
|
1467 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender printString. |
|
1468 |
aStream cr. |
|
1469 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender sender printString. |
|
1470 |
aStream cr. |
|
1471 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender sender sender printString. |
|
1472 |
aStream cr. |
|
1473 |
||
1474 |
" |
|
1475 |
JavaByteCodeDisassembler isNil ifTrue:[ |
|
1476 |
aStream nextPutAll:'// Sorry - no decompiler' |
|
1477 |
] ifFalse:[ |
|
1478 |
JavaByteCodeDisassembler diassemble:self to:aStream. |
|
1479 |
]. |
|
1480 |
" |
|
1481 |
ex return |
|
1482 |
] do:[ |
|
1483 |
"aStream nextPutAll:(JavaDeparser decompile:self)." |
|
1484 |
JavaByteCodeDisassembler diassemble:self to:aStream. |
|
1485 |
]. |
|
1486 |
"/ ]. |
|
1487 |
"/ ]. |
|
1488 |
||
1489 |
"Created: / 30-07-1997 / 16:28:09 / cg" |
|
1490 |
"Modified: / 21-12-1999 / 14:31:54 / cg" |
|
1491 |
"Modified: / 22-03-2011 / 21:34:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1492 |
! |
|
1493 |
||
1494 |
decompiler |
|
1495 |
^ JavaDecompiler |
|
1496 |
||
1497 |
"Created: 30.7.1997 / 16:36:48 / cg" |
|
1498 |
! |
|
1499 |
||
1500 |
isMethod |
|
1501 |
"return true, if the receiver is some kind of method; |
|
1502 |
true returned here - the method is redefined from Object." |
|
1503 |
||
1504 |
^ true |
|
1505 |
||
1506 |
"Created: / 13.11.1998 / 23:57:40 / cg" |
|
1507 |
! |
|
1508 |
||
1509 |
originalMethod |
|
1510 |
^ self |
|
1511 |
||
1512 |
"Created: / 13.1.1998 / 15:03:05 / cg" |
|
1513 |
! ! |
|
1514 |
||
1515 |
!JavaMethod methodsFor:'error handling'! |
|
1516 |
||
872 | 1517 |
errorInvalidClassRefAt: index |
1518 |
||
1519 |
"Sent by the VM when an invalid entry in contant pool |
|
1520 |
is encountered - for instance when the VM expects |
|
1521 |
a classref but the entry is not a classref" |
|
1522 |
||
1523 |
" |
|
1524 |
javaClass constantPool at: index. |
|
1525 |
" |
|
1526 |
||
1527 |
JavaInvalidRefError new |
|
1528 |
javaClass: javaClass; |
|
1529 |
index: index; |
|
1530 |
raiseRequest |
|
1531 |
||
1532 |
"Created: / 18-07-2011 / 23:33:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1533 |
! |
|
1534 |
||
1535 |
errorInvalidFieldRefAt: index |
|
1536 |
||
1537 |
"Sent by the VM when an invalid entry in contant pool |
|
1538 |
is encountered - for instance when the VM expects |
|
1539 |
a classref but the entry is not a classref" |
|
1540 |
||
1541 |
" |
|
1542 |
javaClass constantPool at: index. |
|
1543 |
" |
|
1544 |
||
1545 |
JavaInvalidRefError new |
|
1546 |
javaClass: javaClass; |
|
1547 |
index: index; |
|
1548 |
raiseRequest |
|
1549 |
||
1550 |
"Created: / 18-07-2011 / 23:33:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1551 |
! |
|
1552 |
||
1553 |
errorInvalidMethodRefAt: index |
|
1554 |
||
1555 |
"Sent by the VM when an invalid entry in contant pool |
|
1556 |
is encountered - for instance when the VM expects |
|
1557 |
a classref but the entry is not a classref" |
|
1558 |
||
1559 |
" |
|
1560 |
javaClass constantPool at: index. |
|
1561 |
" |
|
1562 |
||
1563 |
JavaInvalidRefError new |
|
1564 |
javaClass: javaClass; |
|
1565 |
index: index; |
|
1566 |
raiseRequest |
|
1567 |
||
1568 |
"Created: / 18-07-2011 / 19:59:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1569 |
! |
|
1570 |
||
752 | 1571 |
invalidByteCode |
1572 |
self isAbstract ifTrue:[ |
|
913 | 1573 |
^ AbstractMethodInvokationSignal raise. |
752 | 1574 |
]. |
913 | 1575 |
((self class numArgsFromSignature:descriptor) > self class maxNumberOfArguments) ifTrue:[ |
1576 |
^ self error:'method cannot be executed - too many args' |
|
752 | 1577 |
]. |
1578 |
^ super invalidByteCode |
|
1579 |
||
913 | 1580 |
"Created: / 27-01-1998 / 21:48:01 / cg" |
1581 |
"Modified: / 14-08-2011 / 19:29:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 1582 |
! |
1583 |
||
1584 |
invalidMethodRef |
|
1585 |
self halt. |
|
1586 |
^ nil. |
|
1587 |
||
1588 |
"Modified: / 27.1.1998 / 21:50:19 / cg" |
|
1589 |
"Created: / 16.10.1998 / 11:27:21 / cg" |
|
1590 |
! |
|
1591 |
||
1592 |
nullClassPointer |
|
1593 |
JavaVM throwClassNotFoundException |
|
985 | 1594 |
! |
1595 |
||
1596 |
wrongNumberOfArguments:numArgsGiven |
|
1597 |
"{ Pragma: +optSpace }" |
|
1598 |
||
1599 |
"this error is triggered by the VM, if a method is called with a wrong number |
|
1600 |
of arguments. |
|
1601 |
This only applies to #valueWithReceiverXXX and #perform:withArguments: - sends. |
|
1602 |
With a normal send, this error cannot happen." |
|
1603 |
||
1604 |
^ JavaVM |
|
1605 |
throwIllegalArgumentException:(' - %1 got %2 arg(s) where %3 expected' |
|
1606 |
bindWith:self class name |
|
1607 |
with:numArgsGiven |
|
1608 |
with:self numArgs) |
|
1609 |
||
1610 |
" |
|
1611 |
2 perform:#+ |
|
1612 |
" |
|
1613 |
||
1614 |
"Modified: / 01-08-1997 / 00:23:10 / cg" |
|
1615 |
"Created: / 07-09-2011 / 14:17:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 1616 |
! ! |
1617 |
||
913 | 1618 |
!JavaMethod methodsFor:'initialization'! |
1619 |
||
1620 |
setAccessFlags:flags |
|
1621 |
accessFlags := flags. |
|
1622 |
||
1623 |
"Created: 16.4.1996 / 11:34:14 / cg" |
|
1624 |
! |
|
1625 |
||
1626 |
setCode:codeBytes maxStack:max_stack maxLocals:max_locals u1:unknown1 u2:unknown2 |
|
1627 |
"/ javaByteCode := codeBytes. |
|
1628 |
byteCode := codeBytes. |
|
1629 |
"/ numStack := max_stack. |
|
1630 |
"/ numLocals := max_locals. |
|
1631 |
super numberOfVars:max_locals. |
|
1632 |
super stackSize:max_stack. |
|
1633 |
||
1634 |
"/ self displayString printNL. |
|
1635 |
"/ ' nStack: ' print. numStack print. |
|
1636 |
"/ ' nLocal: ' print. numLocals print. |
|
1637 |
"/ ' u1: ' print. unknown1 print. |
|
1638 |
"/ ' u2: ' print. unknown2 printNL. |
|
1639 |
||
1640 |
"Modified: 1.8.1997 / 00:08:32 / cg" |
|
1641 |
! |
|
1642 |
||
1643 |
setDescriptor:aString |
|
1644 |
||
1645 |
descriptor := aString asSymbol. |
|
1646 |
||
1647 |
"Created: / 16-04-1996 / 11:34:29 / cg" |
|
1648 |
"Modified: / 16-10-1998 / 00:17:12 / cg" |
|
1649 |
"Modified: / 13-08-2011 / 01:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1650 |
"Created: / 14-08-2011 / 19:41:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1651 |
! |
|
1652 |
||
1653 |
setJavaClass:aJavaClass |
|
1654 |
javaClass := aJavaClass |
|
1655 |
||
1656 |
"Modified: 16.4.1996 / 12:36:27 / cg" |
|
1657 |
"Created: 16.4.1996 / 15:28:15 / cg" |
|
1658 |
! |
|
1659 |
||
1660 |
setLineNumberTable:anArrayOfPCtoLineAssociations |
|
1661 |
"since this uses up lots of memory, compress it" |
|
1662 |
||
1663 |
|allBytes allWords idx| |
|
1664 |
||
1665 |
allBytes := allWords := true. |
|
1666 |
||
1667 |
anArrayOfPCtoLineAssociations do:[:assoc | |
|
923 | 1668 |
assoc key > 255 ifTrue:[ |
1669 |
allBytes := false. |
|
1670 |
assoc key > 16rFFFF ifTrue:[ |
|
1671 |
allWords := false. |
|
1672 |
]. |
|
1673 |
]. |
|
1674 |
assoc value > 255 ifTrue:[ |
|
1675 |
allBytes := false. |
|
1676 |
assoc value > 16rFFFF ifTrue:[ |
|
1677 |
allWords := false |
|
1678 |
]. |
|
1679 |
]. |
|
913 | 1680 |
]. |
1681 |
allBytes ifTrue:[ |
|
923 | 1682 |
lineNumberTable := ByteArray new:(anArrayOfPCtoLineAssociations size * 2). |
913 | 1683 |
] ifFalse:[ |
923 | 1684 |
allWords ifTrue:[ |
1685 |
lineNumberTable := WordArray new:(anArrayOfPCtoLineAssociations size * 2). |
|
1686 |
] ifFalse:[ |
|
1687 |
lineNumberTable := Array new:(anArrayOfPCtoLineAssociations size * 2). |
|
1688 |
] |
|
913 | 1689 |
]. |
1690 |
||
1691 |
idx := 1. |
|
1692 |
anArrayOfPCtoLineAssociations do:[:assoc | |
|
923 | 1693 |
lineNumberTable at:idx put:assoc key. |
1694 |
lineNumberTable at:idx+1 put:assoc value. |
|
1695 |
idx := idx + 2. |
|
913 | 1696 |
]. |
1697 |
||
1698 |
"Created: 16.4.1996 / 12:34:04 / cg" |
|
1699 |
"Modified: 16.4.1996 / 12:49:06 / cg" |
|
1700 |
! |
|
1701 |
||
1702 |
setLocalVariableTable:anArray |
|
1703 |
localVariableTable := anArray. |
|
1704 |
! |
|
1705 |
||
1706 |
setName:nameString descriptor:aString |
|
1707 |
||
1708 |
||
1709 |
|numArgs tooManyArgs returnType| |
|
1710 |
||
1711 |
selector := (nameString , aString) asSymbol. |
|
1712 |
self setDescriptor:aString. |
|
1713 |
||
1714 |
numArgs := self class numArgsFromSignature:aString. |
|
1715 |
(tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[ |
|
1716 |
numArgs := 0. |
|
1717 |
]. |
|
1718 |
self numberOfArgs:numArgs. |
|
1719 |
returnType := self class typeFromSignature:aString in:nil. |
|
1720 |
||
1721 |
"/ for the convenience of the VM, also mirror the return type in |
|
1722 |
"/ the flags ... |
|
1723 |
||
1724 |
returnType == #void ifTrue:[ |
|
1725 |
accessFlags := accessFlags bitOr:R_VOID |
|
1726 |
] ifFalse:[ |
|
1727 |
returnType == #long ifTrue:[ |
|
1728 |
accessFlags := accessFlags bitOr:R_LONG |
|
1729 |
] ifFalse:[ |
|
1730 |
returnType == #double ifTrue:[ |
|
1731 |
accessFlags := accessFlags bitOr:R_DOUBLE |
|
1732 |
] |
|
1733 |
] |
|
1734 |
]. |
|
1735 |
tooManyArgs ifTrue:[ |
|
1736 |
^ ArgumentError |
|
1737 |
raiseRequestWith:self |
|
1738 |
errorString:'too many args in method' |
|
1739 |
]. |
|
1740 |
||
1741 |
"Created: / 14-08-2011 / 19:41:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1742 |
! |
|
1743 |
||
1744 |
setSignature:aString |
|
1745 |
||
1746 |
signature := aString asSymbol. |
|
1747 |
||
1748 |
"Created: / 16-04-1996 / 11:34:29 / cg" |
|
1749 |
"Modified: / 16-10-1998 / 00:17:12 / cg" |
|
1750 |
"Modified (format): / 14-08-2011 / 19:41:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1751 |
! ! |
|
1752 |
||
752 | 1753 |
!JavaMethod methodsFor:'inspecting'! |
1754 |
||
1755 |
inspectorExtraAttributes |
|
1756 |
"extra (pseudo instvar) entries to be shown in an inspector." |
|
1757 |
||
1758 |
^ Dictionary new |
|
1759 |
declareAllNewFrom:(super inspectorExtraAttributes ? #()); |
|
1760 |
"/add:'-code' -> [ String streamContents:[:s | JavaDecompiler decompile: self to: s] ]; |
|
1761 |
add:'-code' -> [ String streamContents:[:s | JavaByteCodeDisassembler diassemble: self to: s] ]; |
|
1762 |
"/add:'-source' -> [ self source ]; |
|
1763 |
yourself |
|
1764 |
||
1765 |
"Modified: / 22-03-2011 / 21:13:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1766 |
! ! |
|
1767 |
||
1768 |
!JavaMethod methodsFor:'interpretation'! |
|
1769 |
||
1770 |
interpretWithReceiver: receiver |
|
1771 |
||
1772 |
^self |
|
1773 |
interpretWithReceiver: receiver |
|
1774 |
arguments: #() |
|
1775 |
||
1776 |
"Created: / 24-02-2011 / 22:05:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1777 |
! |
|
1778 |
||
1779 |
interpretWithReceiver: receiver arg: a1 |
|
1780 |
||
1781 |
^self |
|
1782 |
interpretWithReceiver: receiver |
|
1783 |
arguments: (Array with: a1) |
|
1784 |
||
1785 |
"Created: / 24-02-2011 / 22:05:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1786 |
! |
|
1787 |
||
1788 |
interpretWithReceiver: receiver arg: a1 arg: a2 |
|
1789 |
||
1790 |
^self |
|
1791 |
interpretWithReceiver: receiver |
|
1792 |
arguments: (Array with: a1 with: a2) |
|
1793 |
||
1794 |
"Created: / 24-02-2011 / 22:05:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1795 |
! |
|
1796 |
||
1797 |
interpretWithReceiver: receiver arg: a1 arg: a2 arg: a3 |
|
1798 |
||
1799 |
^self |
|
1800 |
interpretWithReceiver: receiver |
|
1801 |
arguments: (Array with: a1 with: a2 with: a3) |
|
1802 |
||
1803 |
"Created: / 24-02-2011 / 22:06:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1804 |
! |
|
1805 |
||
1806 |
interpretWithReceiver: receiver arguments:args |
|
1807 |
||
1808 |
^ JavaByteCodeInterpreter |
|
1809 |
interpret:self |
|
1810 |
receiver:receiver |
|
1811 |
arguments:args |
|
1812 |
||
1813 |
"Modified: / 24-02-2011 / 23:00:42 / Marcel Hlopko <hlopik@gmail.com>" |
|
1814 |
"Created: / 24-02-2011 / 22:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1815 |
! ! |
|
1816 |
||
1817 |
!JavaMethod methodsFor:'methodref interchangability'! |
|
1818 |
||
1819 |
homeMethod |
|
1820 |
^ self |
|
1821 |
! |
|
1822 |
||
1823 |
method |
|
1824 |
^ self |
|
1825 |
! |
|
1826 |
||
1827 |
setPackage:newPackage |
|
1828 |
newPackage ~= javaClass package ifTrue:[ |
|
1829 |
self halt:'java method cannot be in a package different from its class'. |
|
1830 |
] |
|
1831 |
! ! |
|
1832 |
||
1833 |
!JavaMethod methodsFor:'misc'! |
|
1834 |
||
1835 |
fromMethod:aJavaMethod |
|
1836 |
"copy values from another javaMethod" |
|
1837 |
||
1838 |
flags := aJavaMethod flags. |
|
1839 |
byteCode := aJavaMethod byteCode. |
|
1840 |
accessFlags := aJavaMethod accessFlags. |
|
1841 |
selector := aJavaMethod selector. |
|
1842 |
javaClass := aJavaMethod javaClass. |
|
913 | 1843 |
descriptor := aJavaMethod instVarNamed:#descriptor. |
1844 |
signature := aJavaMethod instVarNamed:#signature. |
|
752 | 1845 |
lineNumberTable := aJavaMethod lineNumberTable. |
1846 |
localVariableTable := aJavaMethod localVariableTable. |
|
1847 |
annotations := aJavaMethod annotations. |
|
1848 |
||
1849 |
"Modified: / 16-10-1998 / 01:27:19 / cg" |
|
913 | 1850 |
"Modified: / 14-08-2011 / 19:30:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 1851 |
! |
1852 |
||
1853 |
updateClassRefsFrom:oldClass to:newClass |
|
1854 |
javaClass == oldClass ifTrue:[ |
|
923 | 1855 |
"/ invalidate |
1856 |
byteCode := nil. |
|
752 | 1857 |
] |
1858 |
||
1859 |
"Created: / 6.1.1998 / 18:19:48 / cg" |
|
1860 |
! ! |
|
1861 |
||
1862 |
!JavaMethod methodsFor:'printing & storing'! |
|
1863 |
||
1864 |
displayString |
|
1865 |
javaClass isNil ifTrue:[ |
|
1866 |
^ self class name , '(???)' |
|
1867 |
]. |
|
1868 |
^ self class name , '(' , javaClass displayString , '::' , self signatureName , ')' |
|
1869 |
||
1870 |
"Modified: / 25.9.1999 / 23:04:01 / cg" |
|
1871 |
! |
|
1872 |
||
1873 |
printStringForBrowserWithSelector:dummySelector inClass:dummyClass |
|
1874 |
"/ self isStatic ifTrue:[ |
|
1875 |
"/ ^ 'static ' , self signatureName |
|
1876 |
"/ ]. |
|
1877 |
"/ self isBreakpointed ifTrue:[ |
|
1878 |
"/ ^ (LabelAndIcon '!! ' , self signatureName |
|
1879 |
"/ ]. |
|
1880 |
||
1881 |
self name = #'<init>' ifTrue:[ |
|
913 | 1882 |
^ self class specTextFromSignature:descriptor in:javaClass package withName:(javaClass lastName). |
752 | 1883 |
]. |
913 | 1884 |
^ self class specTextFromSignature:descriptor in:javaClass package withName:(self name) |
752 | 1885 |
! |
1886 |
||
1887 |
shortDisplayString |
|
1888 |
^ javaClass name , '::' , self signatureNameWithoutReturnType |
|
1889 |
! |
|
1890 |
||
1891 |
signatureName |
|
1892 |
"return a string to be used when browsing" |
|
1893 |
||
913 | 1894 |
^ self class specFromSignature:descriptor withName:(self name) in:nil |
752 | 1895 |
|
1896 |
"Modified: / 8.1.1998 / 19:15:33 / cg" |
|
1897 |
! |
|
1898 |
||
1899 |
signatureNameFor:name withArgsIn:aPackage |
|
1900 |
"return a string to be used when decompiling" |
|
1901 |
||
913 | 1902 |
^ self class specWithArgsFromSignature:descriptor withName:name in:aPackage |
752 | 1903 |
|
1904 |
"Created: 25.3.1997 / 18:49:45 / cg" |
|
1905 |
! |
|
1906 |
||
1907 |
signatureNameIn:aPackage |
|
1908 |
"return a string to be used when browsing" |
|
1909 |
||
913 | 1910 |
^ self class specFromSignature:descriptor withName:(self name) in:aPackage |
752 | 1911 |
|
1912 |
"Created: 18.3.1997 / 11:11:01 / cg" |
|
1913 |
! |
|
1914 |
||
1915 |
signatureNameText |
|
1916 |
"return a text to be used when browsing" |
|
1917 |
||
913 | 1918 |
^ self class specTextFromSignature:descriptor withName:(self name) |
752 | 1919 |
|
1920 |
"Created: 30.7.1997 / 14:40:29 / cg" |
|
1921 |
! |
|
1922 |
||
1923 |
signatureNameTextFor:name withArgsIn:aPackage |
|
1924 |
"return a text to be used when decompiling" |
|
1925 |
||
913 | 1926 |
^ self class specTextWithArgsFromSignature:descriptor withName:name in:aPackage |
752 | 1927 |
|
1928 |
"Created: 25.3.1997 / 18:49:45 / cg" |
|
1929 |
"Modified: 1.8.1997 / 10:44:28 / cg" |
|
1930 |
! |
|
1931 |
||
1932 |
signatureNameWithArgNames:argNames |
|
1933 |
"return a string to be used when browsing" |
|
1934 |
||
1935 |
|myName| |
|
1936 |
||
1937 |
myName := self name. |
|
1938 |
myName = '<init>' ifTrue:[ |
|
923 | 1939 |
myName := javaClass name |
752 | 1940 |
]. |
913 | 1941 |
^ self class specFromSignature:descriptor withName:myName argNames:argNames in:nil |
752 | 1942 |
|
1943 |
"Created: / 8.1.1998 / 21:04:03 / cg" |
|
1944 |
"Modified: / 8.1.1998 / 21:22:38 / cg" |
|
1945 |
! |
|
1946 |
||
1947 |
signatureNameWithArgNames:argNames in:package |
|
1948 |
"return a string to be used when browsing" |
|
1949 |
||
1950 |
|myName| |
|
1951 |
||
1952 |
myName := self name. |
|
1953 |
myName = '<init>' ifTrue:[ |
|
923 | 1954 |
myName := javaClass name |
752 | 1955 |
]. |
913 | 1956 |
^ self class specFromSignature:descriptor withName:myName argNames:argNames in:package |
752 | 1957 |
|
1958 |
"Modified: / 8.1.1998 / 21:05:52 / cg" |
|
1959 |
"Created: / 8.1.1998 / 21:23:03 / cg" |
|
1960 |
! |
|
1961 |
||
1962 |
signatureNameWithArgsIn:aPackage |
|
1963 |
"return a string to be used when browsing" |
|
1964 |
||
913 | 1965 |
^ self class specWithArgsFromSignature:descriptor withName:(self name) in:aPackage |
1966 |
||
1967 |
"Created: / 20-03-1997 / 12:44:17 / cg" |
|
1968 |
"Modified: / 14-08-2011 / 19:29:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
752 | 1969 |
! |
1970 |
||
1971 |
signatureNameWithModifiers |
|
1972 |
"return a string to be used when deassembling" |
|
1973 |
||
1974 |
| result | |
|
1975 |
||
1976 |
result := self signatureName. |
|
1977 |
self isFinal ifTrue: [ result := 'final ' , result ]. |
|
1978 |
self isStatic ifTrue: [ result := 'static ' , result ]. |
|
1979 |
self isSynchronized ifTrue: [ result := 'synchronized ' , result ]. |
|
1980 |
self isPrivate |
|
1981 |
ifTrue: [ result := 'private ' , result ] |
|
1982 |
ifFalse: |
|
1983 |
[ self isProtected |
|
1984 |
ifTrue: [ result := 'protected ' , result ] |
|
1985 |
ifFalse: [ self isPublic ifTrue: [ result := 'public ' , result ] ] ]. |
|
1986 |
self isAbstract ifTrue: [ result := 'abstract ' , result ]. |
|
1987 |
^ result. |
|
1988 |
||
1989 |
"Modified: / 08-01-1998 / 19:15:33 / cg" |
|
1990 |
"Created: / 22-03-2011 / 16:25:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1991 |
! |
|
1992 |
||
1993 |
signatureNameWithoutReturnType |
|
1994 |
"return a string to be used when browsing" |
|
1995 |
||
913 | 1996 |
^ self class argSpecFromSignature:descriptor withName:(self name) |
752 | 1997 |
|
1998 |
! ! |
|
1999 |
||
2000 |
!JavaMethod methodsFor:'queries'! |
|
2001 |
||
2002 |
handlerFor:anException at:pc |
|
2003 |
"return an exceptionHandlers pc, for an exception of the given type, |
|
2004 |
occurring at pc. Returns nil, if there is none." |
|
2005 |
||
2006 |
|handlerTable| |
|
2007 |
||
2008 |
(handlerTable := self exceptionHandlerTable) isNil ifTrue:[^ nil]. |
|
2009 |
||
2010 |
handlerTable do:[:entry | |
|
2011 |
|hpc| |
|
2012 |
||
2013 |
hpc := entry handlerPCFor:anException at:pc in:self. |
|
2014 |
hpc notNil ifTrue:[^ hpc]. |
|
2015 |
]. |
|
2016 |
||
2017 |
^ nil |
|
2018 |
||
2019 |
"Created: / 16.10.1998 / 01:18:40 / cg" |
|
2020 |
"Modified: / 25.9.1999 / 23:07:01 / cg" |
|
2021 |
! |
|
2022 |
||
872 | 2023 |
hasPrimitiveCode |
2024 |
||
2025 |
^false |
|
2026 |
||
2027 |
"Created: / 18-07-2011 / 20:45:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2028 |
! |
|
2029 |
||
752 | 2030 |
hasResource |
2031 |
^ false |
|
2032 |
! |
|
2033 |
||
2034 |
isAbstract |
|
2035 |
^ (accessFlags bitAnd:A_ABSTRACT) ~~ 0 |
|
2036 |
! |
|
2037 |
||
2038 |
isBreakpointed |
|
2039 |
^ (accessFlags bitAnd:A_BREAKPOINT) ~~ 0 |
|
2040 |
||
2041 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
2042 |
! |
|
2043 |
||
2044 |
isFinal |
|
2045 |
^ (accessFlags bitAnd:A_FINAL) ~~ 0 |
|
2046 |
! |
|
2047 |
||
2048 |
isIgnored |
|
2049 |
"not really a java attribute; |
|
2050 |
added to allow browsing" |
|
2051 |
||
2052 |
^ false. |
|
2053 |
||
2054 |
"Created: 30.7.1997 / 15:34:33 / cg" |
|
2055 |
! |
|
2056 |
||
2057 |
isJavaClassRef |
|
2058 |
^ false |
|
2059 |
||
2060 |
"Created: / 9.11.1999 / 17:16:20 / cg" |
|
2061 |
! |
|
2062 |
||
2063 |
isJavaMethod |
|
2064 |
^ true |
|
2065 |
||
2066 |
"Created: / 10.11.1998 / 18:24:51 / cg" |
|
2067 |
! |
|
2068 |
||
2069 |
isNative |
|
2070 |
^ (accessFlags bitAnd:A_NATIVE) ~~ 0 |
|
2071 |
! |
|
2072 |
||
2073 |
isPrivate |
|
2074 |
^ (accessFlags bitAnd:A_PRIVATE) ~~ 0 |
|
2075 |
! |
|
2076 |
||
2077 |
isProtected |
|
2078 |
^ (accessFlags bitAnd:A_PROTECTED) ~~ 0 |
|
2079 |
! |
|
2080 |
||
2081 |
isPublic |
|
2082 |
^ (accessFlags bitAnd:A_PUBLIC) ~~ 0 |
|
2083 |
! |
|
2084 |
||
2085 |
isStatic |
|
2086 |
^ (accessFlags bitAnd:A_STATIC) ~~ 0 |
|
2087 |
! |
|
2088 |
||
2089 |
isSynchronized |
|
2090 |
^ (accessFlags bitAnd:A_SYNCHRONIZED) ~~ 0 |
|
2091 |
! |
|
2092 |
||
2093 |
isTraced |
|
2094 |
^ false |
|
2095 |
||
2096 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
2097 |
"Created: / 11.1.1998 / 13:38:11 / cg" |
|
2098 |
! |
|
2099 |
||
2100 |
isUnloaded |
|
2101 |
^ false |
|
2102 |
! |
|
2103 |
||
2104 |
isUnresolved |
|
2105 |
"return true, if the receiver is unresolved;" |
|
2106 |
||
2107 |
||
2108 |
^ false |
|
2109 |
||
2110 |
"Created: / 06-03-2011 / 22:57:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2111 |
! |
|
2112 |
||
2113 |
isWrapped |
|
2114 |
^ self isBreakpointed |
|
2115 |
||
2116 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
2117 |
"Created: / 11.1.1998 / 13:38:04 / cg" |
|
2118 |
! |
|
2119 |
||
2120 |
lineNumberForPC:pc |
|
2121 |
|last num text classSource| |
|
2122 |
||
2123 |
num := nil. |
|
2124 |
||
2125 |
ForceByteCodeDisplay == true ifFalse:[ |
|
2126 |
||
923 | 2127 |
lineNumberTable notNil ifTrue:[ |
2128 |
classSource := javaClass source. |
|
2129 |
classSource notNil ifTrue:[ |
|
2130 |
lineNumberTable pairWiseDo:[:lPc :lNr | |
|
2131 |
lPc >= pc ifTrue:[ |
|
2132 |
lPc == pc ifTrue:[^ lNr]. |
|
2133 |
last isNil ifTrue:[^ lNr]. |
|
2134 |
^ last. |
|
2135 |
]. |
|
2136 |
last := lNr. |
|
2137 |
]. |
|
2138 |
last notNil ifTrue:[ |
|
2139 |
^ last |
|
2140 |
]. |
|
2141 |
^ lineNumberTable at:2 |
|
2142 |
]. |
|
2143 |
]. |
|
752 | 2144 |
]. |
2145 |
||
2146 |
"/ decompile and look which line the pc falls into |
|
2147 |
||
2148 |
ForceByteCodeDisplay == true ifTrue:[ |
|
923 | 2149 |
text := self decompiledBytecode asCollectionOfLines. |
752 | 2150 |
] ifFalse:[ |
923 | 2151 |
text := self decompiledSource asCollectionOfLines. |
752 | 2152 |
]. |
2153 |
||
2154 |
text keysAndValuesDo:[:lineNr :line | |
|
923 | 2155 |
|nr| |
2156 |
||
2157 |
(line startsWith:' ') ifFalse:[ |
|
2158 |
nr := Integer readFrom:line onError:0. |
|
2159 |
nr >= pc ifTrue:[ |
|
2160 |
^ lineNr |
|
2161 |
] |
|
2162 |
] |
|
752 | 2163 |
]. |
2164 |
^ num |
|
2165 |
||
2166 |
"Modified: / 14.1.1998 / 13:30:54 / cg" |
|
2167 |
! |
|
2168 |
||
2169 |
messagesSent |
|
2170 |
"return a collection of messages sent by this method" |
|
2171 |
||
2172 |
|walker selectors| |
|
2173 |
||
2174 |
"/ sigh - must extract all accessed literals ... |
|
2175 |
"/ must deparse the byteCode in order to do this. |
|
2176 |
||
2177 |
selectors := IdentitySet new. |
|
2178 |
walker := JavaByteCodeEnumerator new. |
|
2179 |
walker |
|
2180 |
literalAction: |
|
2181 |
[:pc :slotIndex :const | |
|
2182 |
|mSel| |
|
2183 |
||
2184 |
(const isNumber |
|
2185 |
or:[const isString |
|
2186 |
or:[const isNil]]) ifFalse:[ |
|
2187 |
const isJavaMethod ifTrue:[ |
|
2188 |
mSel := const selector. |
|
2189 |
] ifFalse:[ |
|
2190 |
const isJavaMethodRef ifTrue:[ |
|
2191 |
mSel := const selector "/ signature. |
|
2192 |
] |
|
2193 |
]. |
|
2194 |
]. |
|
2195 |
mSel notNil ifTrue:[ |
|
2196 |
"/ Transcript showCR:mSel. |
|
2197 |
selectors add:mSel |
|
2198 |
]. |
|
2199 |
]. |
|
2200 |
walker decompile:self to:nil. |
|
2201 |
^ selectors |
|
2202 |
! |
|
2203 |
||
2204 |
package |
|
2205 |
"in java, class extensions are not possible; |
|
2206 |
all methods MUST be in their classes package" |
|
2207 |
||
2208 |
^ javaClass package |
|
2209 |
! |
|
2210 |
||
2211 |
quickLineNumberForPC:pc |
|
2212 |
|last| |
|
2213 |
||
2214 |
lineNumberTable notNil ifTrue:[ |
|
923 | 2215 |
lineNumberTable pairWiseDo:[:lPc :lNr | |
2216 |
lPc >= pc ifTrue:[ |
|
2217 |
lPc == pc ifTrue:[^ lNr]. |
|
2218 |
last isNil ifTrue:[^ lNr]. |
|
2219 |
^ last. |
|
2220 |
]. |
|
2221 |
last := lNr. |
|
2222 |
]. |
|
2223 |
last notNil ifTrue:[ |
|
2224 |
^ last |
|
2225 |
]. |
|
2226 |
^ lineNumberTable at:2 |
|
752 | 2227 |
]. |
2228 |
^ nil |
|
2229 |
||
2230 |
"Modified: / 14.1.1998 / 13:30:54 / cg" |
|
2231 |
"Created: / 10.11.1998 / 14:18:22 / cg" |
|
2232 |
! |
|
2233 |
||
2234 |
referencesGlobal:aGlobalName |
|
2235 |
"return true, if this method refers to a global named aGlobalName" |
|
2236 |
||
2237 |
|walker any| |
|
2238 |
||
2239 |
"/ quick check, if constantPool includes a methodRef for this |
|
2240 |
"/ selector. |
|
2241 |
||
2242 |
any := false. |
|
2243 |
self javaClass constantPool do:[:const | |
|
2244 |
(const isNumber |
|
2245 |
or:[const isString |
|
2246 |
or:[const isNil]]) ifFalse:[ |
|
2247 |
const isJavaClass ifTrue:[ |
|
2248 |
any := any or:[const fullName = aGlobalName]. |
|
2249 |
] ifFalse:[ |
|
2250 |
const isJavaClassRef ifTrue:[ |
|
2251 |
any := any or:[const fullName = aGlobalName]. |
|
2252 |
] |
|
2253 |
]. |
|
2254 |
]. |
|
2255 |
]. |
|
2256 |
any ifFalse:[^ false]. |
|
2257 |
||
2258 |
"/ sigh - must extract all accessed literals ... |
|
2259 |
"/ must deparse the byteCode in order to do this. |
|
2260 |
||
2261 |
walker := JavaByteCodeEnumerator new. |
|
2262 |
walker |
|
2263 |
literalAction: |
|
2264 |
[:pc :slotIndex :const | |
|
2265 |
|mSel| |
|
2266 |
||
2267 |
(const isNumber |
|
2268 |
or:[const isString |
|
2269 |
or:[const isNil]]) ifFalse:[ |
|
2270 |
const isJavaClass ifTrue:[ |
|
2271 |
mSel := const fullName. |
|
2272 |
] ifFalse:[ |
|
2273 |
const isJavaClassRef ifTrue:[ |
|
2274 |
mSel := const fullName. |
|
2275 |
] |
|
2276 |
]. |
|
2277 |
]. |
|
2278 |
mSel notNil ifTrue:[ |
|
2279 |
"/ Transcript showCR:mSel. |
|
2280 |
mSel = aGlobalName ifTrue:[ |
|
2281 |
^ true |
|
2282 |
] |
|
2283 |
]. |
|
2284 |
]. |
|
2285 |
walker decompile:self to:nil. |
|
2286 |
||
2287 |
"Created: / 9.11.1999 / 17:15:46 / cg" |
|
2288 |
"Modified: / 9.11.1999 / 17:18:02 / cg" |
|
2289 |
! |
|
2290 |
||
2291 |
sends:aSelectorSymbol |
|
2292 |
"return true, if this method contains a message-send |
|
2293 |
with aSelectorSymbol as selector." |
|
2294 |
||
2295 |
|walker any| |
|
2296 |
||
2297 |
"/ quick check, if constantPool includes a methodRef for this |
|
2298 |
"/ selector. |
|
2299 |
||
2300 |
any := false. |
|
2301 |
self javaClass constantPool do:[:const | |
|
2302 |
(const isNumber |
|
2303 |
or:[const isString |
|
2304 |
or:[const isNil]]) ifFalse:[ |
|
2305 |
const isJavaMethod ifTrue:[ |
|
2306 |
any := any or:[const selector = aSelectorSymbol]. |
|
2307 |
] ifFalse:[ |
|
2308 |
const isJavaMethodRef ifTrue:[ |
|
2309 |
any := any or:[const signature = aSelectorSymbol]. |
|
2310 |
] |
|
2311 |
]. |
|
2312 |
]. |
|
2313 |
]. |
|
2314 |
any ifFalse:[^ false]. |
|
2315 |
||
2316 |
"/ sigh - must extract all accessed literals ... |
|
2317 |
"/ must deparse the byteCode in order to do this. |
|
2318 |
||
2319 |
walker := JavaByteCodeEnumerator new. |
|
2320 |
walker |
|
2321 |
literalAction: |
|
2322 |
[:pc :slotIndex :const | |
|
2323 |
|mSel| |
|
2324 |
||
2325 |
(const isNumber |
|
2326 |
or:[const isString |
|
2327 |
or:[const isNil]]) ifFalse:[ |
|
2328 |
const isJavaMethod ifTrue:[ |
|
2329 |
mSel := const selector. |
|
2330 |
] ifFalse:[ |
|
2331 |
const isJavaMethodRef ifTrue:[ |
|
2332 |
mSel := const signature. |
|
2333 |
] |
|
2334 |
]. |
|
2335 |
]. |
|
2336 |
mSel notNil ifTrue:[ |
|
2337 |
"/ Transcript showCR:mSel. |
|
2338 |
mSel = aSelectorSymbol ifTrue:[ |
|
2339 |
^ true |
|
2340 |
] |
|
2341 |
]. |
|
2342 |
]. |
|
2343 |
walker decompile:self to:nil. |
|
2344 |
||
2345 |
"Created: / 9.11.1999 / 15:38:14 / cg" |
|
2346 |
"Modified: / 9.11.1999 / 17:06:03 / cg" |
|
2347 |
! |
|
2348 |
||
872 | 2349 |
shouldBeSkippedInDebuggersWalkBack |
2350 |
||
2351 |
^false |
|
2352 |
||
2353 |
"Created: / 30-11-2010 / 15:35:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2354 |
! |
|
2355 |
||
752 | 2356 |
who |
2357 |
"return the class and selector of where I am defined in." |
|
2358 |
||
2359 |
|sel| |
|
2360 |
||
2361 |
javaClass isNil ifTrue:[^ nil]. |
|
2362 |
sel := selector. |
|
2363 |
"/ sel := javaClass methodDictionary keyAtValue:self ifAbsent:nil. |
|
2364 |
sel isNil ifTrue:[^ nil]. |
|
2365 |
^ Method::MethodWhoInfo class:javaClass selector:sel. |
|
2366 |
||
2367 |
"Modified: / 16.10.1998 / 13:42:10 / cg" |
|
2368 |
! ! |
|
2369 |
||
2370 |
!JavaMethod methodsFor:'signature parsing'! |
|
2371 |
||
2372 |
XXXspecWithArgsFromSignature:aSignature withName:name in:aPackage |
|
2373 |
"given a signature, return a spec with args" |
|
2374 |
||
2375 |
|s argSpec retvalSpec| |
|
2376 |
||
2377 |
s := aSignature readStream. |
|
2378 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
2379 |
||
2380 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage. |
|
2381 |
||
2382 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
2383 |
||
2384 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
2385 |
||
2386 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
2387 |
||
2388 |
" |
|
2389 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' |
|
2390 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' |
|
2391 |
" |
|
2392 |
||
2393 |
"Created: / 8.1.1998 / 19:17:58 / cg" |
|
2394 |
! ! |
|
2395 |
||
872 | 2396 |
!JavaMethod methodsFor:'testing'! |
2397 |
||
2398 |
isSynthetic |
|
2399 |
^false |
|
2400 |
||
2401 |
"Created: / 18-10-2010 / 19:09:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2402 |
! ! |
|
2403 |
||
752 | 2404 |
!JavaMethod class methodsFor:'documentation'! |
2405 |
||
2406 |
version |
|
948 | 2407 |
^ '$Header: /cvs/stx/stx/libjava/JavaMethod.st,v 1.108 2011/08/19 13:49:39 cg Exp $' |
752 | 2408 |
! |
2409 |
||
2410 |
version_CVS |
|
923 | 2411 |
^ '§Header: /cvs/stx/stx/libjava/JavaMethod.st,v 1.108 2011/08/19 13:49:39 cg Exp §' |
752 | 2412 |
! |
2413 |
||
2414 |
version_SVN |
|
1022 | 2415 |
^ '$Id$' |
752 | 2416 |
! ! |
2417 |
||
948 | 2418 |
JavaMethod initialize! |