author | Claus Gittinger <cg@exept.de> |
Fri, 19 Aug 2011 14:34:39 +0200 | |
changeset 2156 | a8c5720d1d05 |
parent 2151 | c0b6570c6f9b |
child 2158 | cf16fc148fb8 |
permissions | -rw-r--r-- |
454 | 1 |
" |
2151 | 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: |
|
454 | 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. |
|
2151 | 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. |
|
2086 | 41 |
" |
678 | 42 |
"{ Package: 'stx:libjava' }" |
43 |
||
427 | 44 |
CompiledCode variableSubclass:#JavaMethod |
2151 | 45 |
instanceVariableNames:'accessFlags selector javaClass descriptor signature lookupObject |
46 |
lineNumberTable localVariableTable sourceLineNumber annotations' |
|
2086 | 47 |
classVariableNames:'AbstractMethodInvokationSignal SignatureTypeCodes |
48 |
ForceByteCodeDisplay UnresolvedClassSignal A_PUBLIC A_PRIVATE |
|
49 |
A_PROTECTED A_STATIC A_FINAL A_SYNCHRONIZED A_ABSTRACT A_NATIVE |
|
2145 | 50 |
A_BREAKPOINT R_VOID R_LONG R_DOUBLE A_HASHANDLER A_BRIDGE |
51 |
A_VARARGS A_STRICT A_SYNTHETIC' |
|
2086 | 52 |
poolDictionaries:'' |
2107 | 53 |
category:'Languages-Java-Classes' |
2 | 54 |
! |
55 |
||
454 | 56 |
!JavaMethod class methodsFor:'documentation'! |
57 |
||
58 |
copyright |
|
59 |
" |
|
2151 | 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: |
|
454 | 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. |
|
2151 | 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 |
||
2086 | 100 |
" |
454 | 101 |
! ! |
2 | 102 |
|
129 | 103 |
!JavaMethod class methodsFor:'initialization'! |
8 | 104 |
|
105 |
initialize |
|
277 | 106 |
AbstractMethodInvokationSignal isNil ifTrue:[ |
2114
cbdc4c02a8e2
ExecutionErrorSignal -> ExecutionError
Claus Gittinger <cg@exept.de>
parents:
2110
diff
changeset
|
107 |
AbstractMethodInvokationSignal := ExecutionError newSignalMayProceed:true. |
594 | 108 |
AbstractMethodInvokationSignal nameClass:self message:#abstractMethodInvokationSignal. |
109 |
AbstractMethodInvokationSignal notifierString:'attempt to execute abstract method'. |
|
110 |
||
2114
cbdc4c02a8e2
ExecutionErrorSignal -> ExecutionError
Claus Gittinger <cg@exept.de>
parents:
2110
diff
changeset
|
111 |
UnresolvedClassSignal := ExecutionError newSignalMayProceed:true. |
594 | 112 |
UnresolvedClassSignal nameClass:self message:#unresolvedClassSignal. |
113 |
UnresolvedClassSignal notifierString:'unresolved class'. |
|
277 | 114 |
]. |
115 |
||
252 | 116 |
A_PUBLIC := 16r0001. |
117 |
A_PRIVATE := 16r0002. |
|
118 |
A_PROTECTED := 16r0004. |
|
119 |
A_STATIC := 16r0008. |
|
120 |
A_FINAL := 16r0010. |
|
121 |
A_SYNCHRONIZED := 16r0020. |
|
2145 | 122 |
A_BRIDGE := 16r0040. |
123 |
A_VARARGS := 16r0080. |
|
252 | 124 |
A_NATIVE := 16r0100. |
125 |
A_ABSTRACT := 16r0400. |
|
2145 | 126 |
A_STRICT := 16r0800. |
127 |
A_SYNTHETIC := 16r1000. |
|
252 | 128 |
|
129 |
R_VOID := 16r100000. |
|
130 |
R_LONG := 16r200000. |
|
131 |
R_DOUBLE := 16r300000. |
|
132 |
||
255 | 133 |
A_BREAKPOINT := 16r0800000. |
378 | 134 |
A_HASHANDLER := 16r1000000. |
255 | 135 |
|
173 | 136 |
self flags:(self flags bitOr:Behavior flagJavaMethod). |
137 |
||
8 | 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. |
|
2151 | 149 |
SignatureTypeCodes at:$T put:#typevar. |
8 | 150 |
|
207 | 151 |
ForceByteCodeDisplay := false. |
152 |
||
8 | 153 |
" |
378 | 154 |
JavaMethod initialize. |
155 |
JavaMethodWithHandler initialize. |
|
209 | 156 |
ForceByteCodeDisplay := true. |
255 | 157 |
ForceByteCodeDisplay := false. |
8 | 158 |
" |
173 | 159 |
|
2151 | 160 |
"Modified: / 16-10-1998 / 01:29:48 / cg" |
161 |
"Modified: / 13-08-2011 / 01:02:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
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>" |
|
378 | 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" |
|
277 | 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" |
|
594 | 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" |
|
8 | 207 |
! ! |
208 |
||
357 | 209 |
!JavaMethod class methodsFor:'constants'! |
210 |
||
467 | 211 |
A_HASHANDLER |
212 |
^ A_HASHANDLER |
|
213 |
||
214 |
"Created: / 26.11.1998 / 22:23:12 / cg" |
|
215 |
! |
|
216 |
||
357 | 217 |
A_NATIVE |
2091 | 218 |
^ A_NATIVE |
357 | 219 |
|
220 |
"Created: / 16.5.1998 / 01:18:24 / cg" |
|
221 |
! |
|
222 |
||
223 |
A_PUBLIC |
|
2091 | 224 |
^ A_PUBLIC |
357 | 225 |
|
226 |
"Created: / 16.5.1998 / 00:01:10 / cg" |
|
227 |
! |
|
228 |
||
229 |
A_STATIC |
|
2091 | 230 |
^ A_STATIC |
357 | 231 |
|
232 |
"Created: / 16.5.1998 / 00:01:17 / cg" |
|
233 |
! ! |
|
234 |
||
169 | 235 |
!JavaMethod class methodsFor:'misc'! |
236 |
||
237 |
forceByteCodeDisplay |
|
238 |
^ ForceByteCodeDisplay |
|
239 |
||
240 |
"Created: 7.4.1997 / 20:11:39 / cg" |
|
309 | 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" |
|
2151 | 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>" |
|
169 | 279 |
! ! |
280 |
||
129 | 281 |
!JavaMethod class methodsFor:'signature parsing'! |
5 | 282 |
|
29 | 283 |
argSigArrayFromSignature:aSignature |
284 |
"given a signature, return a specArray for the arguments" |
|
285 |
||
238 | 286 |
|s| |
29 | 287 |
|
288 |
s := aSignature readStream. |
|
237 | 289 |
s next ~~ $( ifTrue:[self halt]. |
29 | 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:[ |
|
2086 | 310 |
argSpec := self fieldTypeFromStream:s in:nil. |
311 |
spec := spec copyWith:argSpec. |
|
29 | 312 |
"/ ] |
313 |
]. |
|
314 |
^ spec |
|
315 |
||
255 | 316 |
"Modified: / 8.1.1998 / 19:10:20 / cg" |
29 | 317 |
! |
318 |
||
2151 | 319 |
argSignatureFromArgTypeArray:arr |
320 |
| sig | |
|
321 | 321 |
|
322 |
sig := ''. |
|
2151 | 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. ] ]. |
|
322 | 335 |
^ sig |
321 | 336 |
|
337 |
" |
|
338 |
self argSignatureFromArgTypeArray: |
|
2151 | 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>" |
|
321 | 344 |
! |
345 |
||
113 | 346 |
argSpecFromSignature:aSignature withName:name |
347 |
"given a signature, return a spec" |
|
348 |
||
238 | 349 |
|s argSpec| |
113 | 350 |
|
351 |
s := aSignature readStream. |
|
352 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
353 |
||
255 | 354 |
argSpec := self argSpecFromStream:s in:nil. |
113 | 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 |
||
255 | 365 |
"Modified: / 8.1.1998 / 19:05:36 / cg" |
5 | 366 |
! |
367 |
||
142 | 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:[ |
|
2086 | 378 |
argSpec := self fieldTypeFromStream:s in:aPackage. |
379 |
spec size ~~ 0 ifTrue:[ |
|
380 |
spec := spec , ' ' |
|
381 |
]. |
|
382 |
spec := spec , argSpec. |
|
142 | 383 |
"/ ] |
384 |
]. |
|
385 |
^ spec |
|
386 |
||
387 |
"Created: 18.3.1997 / 11:06:44 / cg" |
|
388 |
! |
|
389 |
||
154 | 390 |
argSpecWithArgsFromStream:s in:aPackage |
391 |
"parse an argSpec - see java doc" |
|
392 |
||
255 | 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| |
|
154 | 402 |
|
403 |
argNr := 1. |
|
404 |
spec := ''. |
|
405 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
2086 | 406 |
argSpec := self fieldTypeFromStream:s in:aPackage. |
750 | 407 |
|
2086 | 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. |
|
750 | 414 |
|
2086 | 415 |
spec size ~~ 0 ifTrue:[ |
416 |
spec := spec , ', ' |
|
417 |
]. |
|
418 |
spec := spec , argSpec. |
|
750 | 419 |
|
2086 | 420 |
argNr := argNr + 1. |
154 | 421 |
]. |
422 |
^ spec |
|
423 |
||
255 | 424 |
"Created: / 8.1.1998 / 19:20:36 / cg" |
425 |
"Modified: / 8.1.1998 / 21:14:33 / cg" |
|
8 | 426 |
! |
427 |
||
142 | 428 |
fieldTypeFromStream:s in:aPackage |
429 |
"parse a fieldTypeSpec - see java doc" |
|
430 |
||
2151 | 431 |
|typeChar typeSym elType size className nm out nangles | |
142 | 432 |
|
433 |
typeChar := s next. |
|
434 |
||
435 |
typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown. |
|
436 |
||
437 |
typeSym == #unknown ifTrue:[ |
|
2151 | 438 |
^ typeSym |
142 | 439 |
]. |
2151 | 440 |
(typeSym == #object or: [typeSym == #typevar]) ifTrue:[ |
441 |
"Take care about type variables" |
|
442 |
out := String new writeStream. |
|
443 |
[ s peek ~~ $; and:[ s peek ~~ $< ] ] whileTrue:[ |
|
444 |
out nextPut: s next. |
|
445 |
]. |
|
446 |
className := out contents. |
|
447 |
"Eat possible type variables" |
|
448 |
(s peek == $<) ifTrue:[ |
|
449 |
nangles := 1. s next. |
|
450 |
[ nangles ~~ 0 ] whileTrue:[ |
|
451 |
s peek == $< ifTrue:[nangles := nangles + 1]. |
|
452 |
s peek == $> ifTrue:[nangles := nangles - 1]. |
|
453 |
s next. |
|
454 |
] |
|
455 |
]. |
|
456 |
s peek ~~ $; ifTrue:[self error: 'Signature corrupted?']. |
|
457 |
s next. "/eat ; |
|
458 |
||
459 |
||
460 |
typeSym == #typevar ifTrue:[^className]. |
|
461 |
"/ strip off default |
|
462 |
nm := className. |
|
463 |
aPackage notNil ifTrue:[ |
|
464 |
(nm startsWith:aPackage) ifTrue:[ |
|
465 |
nm := nm copyFrom:(aPackage size + 2). |
|
466 |
]. |
|
467 |
]. |
|
142 | 468 |
|
2151 | 469 |
nm := nm copyReplaceAll:$/ with:$.. |
470 |
^ nm |
|
142 | 471 |
]. |
189 | 472 |
|
142 | 473 |
typeSym == #array ifTrue:[ |
2151 | 474 |
s peek isDigit ifTrue:[ |
475 |
size := Integer readFrom:s. |
|
476 |
elType := self fieldTypeFromStream:s in:aPackage. |
|
477 |
^ elType , '[' , size printString , ']' |
|
478 |
]. |
|
479 |
elType := self fieldTypeFromStream:s in:aPackage. |
|
480 |
^ elType , '[]' |
|
142 | 481 |
]. |
189 | 482 |
|
142 | 483 |
^ typeSym |
484 |
||
2151 | 485 |
"Created: / 18-03-1997 / 11:07:56 / cg" |
486 |
"Modified: / 18-07-1998 / 22:57:06 / cg" |
|
487 |
"Modified: / 13-08-2011 / 01:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 | 488 |
! |
489 |
||
27 | 490 |
numArgsFromSignature:aSignature |
491 |
"given a signature, return the number of args" |
|
492 |
||
238 | 493 |
|s| |
27 | 494 |
|
495 |
s := aSignature readStream. |
|
2151 | 496 |
(aSignature includes: $() ifFalse:[self error:'Invalid signature']. |
497 |
[s next ~~ $(] whileTrue. |
|
27 | 498 |
|
499 |
^ self numArgsFromStream:s. |
|
500 |
||
501 |
" |
|
502 |
JavaMethod numArgsFromSignature:'(LObject;)V' |
|
503 |
JavaMethod numArgsFromSignature:'(BB)S' |
|
504 |
JavaMethod numArgsFromSignature:'()V' |
|
2151 | 505 |
JavaMethod numArgsFromSignature:'(Ljava/util/ArrayList<*>;)V' |
27 | 506 |
" |
2151 | 507 |
|
508 |
"Modified (comment): / 13-08-2011 / 00:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
27 | 509 |
! |
510 |
||
511 |
numArgsFromStream:s |
|
512 |
"parse an argSpec - see java doc" |
|
513 |
||
238 | 514 |
|n t| |
27 | 515 |
|
516 |
n := 0. |
|
517 |
[s atEnd or:[s peek == $)]] whileFalse:[ |
|
2086 | 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 |
] |
|
27 | 531 |
]. |
532 |
^ n |
|
533 |
||
255 | 534 |
"Modified: / 8.1.1998 / 19:10:25 / cg" |
29 | 535 |
! |
536 |
||
142 | 537 |
retValSpecFromSignature:aSignature in:aPackage |
538 |
"given a signature, return a spec" |
|
539 |
||
540 |
|s argSpec retvalSpec| |
|
541 |
||
542 |
s := aSignature readStream. |
|
237 | 543 |
s next ~~ $( ifTrue:[self halt]. |
142 | 544 |
|
545 |
argSpec := self argSpecFromStream:s in:aPackage. |
|
546 |
||
237 | 547 |
s next ~~ $) ifTrue:[self halt]. |
142 | 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 |
||
189 | 561 |
returnTypeFromSignature:aSignature in:aPackage |
562 |
"given a signature, return its type as a string" |
|
563 |
||
238 | 564 |
|s c| |
189 | 565 |
|
566 |
s := aSignature readStream. |
|
567 |
(c := s peek) ~~ $( ifTrue:[ |
|
2086 | 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) |
|
189 | 574 |
]. |
575 |
||
576 |
s next. |
|
255 | 577 |
self argSpecFromStream:s in:aPackage. |
189 | 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 |
||
255 | 589 |
"Created: / 1.8.1997 / 10:54:31 / cg" |
590 |
"Modified: / 8.1.1998 / 19:09:06 / cg" |
|
72 | 591 |
! |
592 |
||
593 |
returnsVoidFromSignature:aSignature |
|
594 |
"given a signature, return true if it returns void, false if not" |
|
595 |
||
255 | 596 |
^ (self typeFromSignature:aSignature in:nil) = 'void' |
27 | 597 |
|
598 |
" |
|
599 |
JavaMethod returnsVoidFromSignature:'(LObject;)V' |
|
600 |
JavaMethod returnsVoidFromSignature:'(BB)S' |
|
601 |
" |
|
602 |
||
255 | 603 |
"Modified: / 8.1.1998 / 19:13:53 / cg" |
10 | 604 |
! |
605 |
||
142 | 606 |
retvalSpecFromStream:s in:aPackage |
607 |
"parse a retvalSpec - see java doc" |
|
608 |
||
332 | 609 |
|spec| |
610 |
||
142 | 611 |
s atEnd ifTrue:[self halt. ^ #void]. |
612 |
s peek == $V ifTrue:[^ #void]. |
|
332 | 613 |
spec := self fieldTypeFromStream:s in:aPackage. |
614 |
spec knownAsSymbol ifTrue:[ |
|
2086 | 615 |
^ spec asSymbol |
332 | 616 |
]. |
617 |
^ spec |
|
142 | 618 |
|
332 | 619 |
"Created: / 18.3.1997 / 11:12:19 / cg" |
620 |
"Modified: / 7.4.1998 / 22:28:27 / cg" |
|
142 | 621 |
! |
622 |
||
189 | 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 |
||
255 | 648 |
specFromSignature:aSignature withName:name argNames:argNames in:aPackage |
10 | 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 |
||
255 | 656 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage argNames:argNames. |
10 | 657 |
|
658 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
659 |
||
255 | 660 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
10 | 661 |
|
662 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
663 |
||
664 |
" |
|
255 | 665 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' argNames:#('a') in:nil |
666 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' argNames:#('a' 'b') in:nil |
|
10 | 667 |
" |
255 | 668 |
|
669 |
"Created: / 18.3.1997 / 11:06:22 / cg" |
|
670 |
"Modified: / 8.1.1998 / 21:14:43 / cg" |
|
83 | 671 |
! |
672 |
||
142 | 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 |
" |
|
255 | 690 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' in:nil |
691 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' in:nil |
|
142 | 692 |
" |
693 |
||
255 | 694 |
"Created: / 18.3.1997 / 11:06:22 / cg" |
695 |
"Modified: / 8.1.1998 / 21:06:32 / cg" |
|
142 | 696 |
! |
697 |
||
678 | 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 |
||
2110
6188ec8713ea
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
2107
diff
changeset
|
712 |
"/ ^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
6188ec8713ea
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
2107
diff
changeset
|
713 |
^ (name allBold) , ' (' , argSpec , ')' |
678 | 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 |
||
175 | 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 |
||
255 | 731 |
argSpec := self argSpecFromStream:s in:nil. |
175 | 732 |
|
733 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
734 |
||
255 | 735 |
retvalSpec := self retvalSpecFromStream:s in:nil. |
175 | 736 |
|
2110
6188ec8713ea
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
2107
diff
changeset
|
737 |
^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
175 | 738 |
|
739 |
" |
|
740 |
JavaMethod specTextFromSignature:'(LObject;)V' withName:'foo' |
|
741 |
JavaMethod specTextFromSignature:'(BB)S' withName:'foo' |
|
742 |
" |
|
743 |
||
255 | 744 |
"Modified: / 8.1.1998 / 19:11:20 / cg" |
175 | 745 |
! |
746 |
||
189 | 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 |
||
2110
6188ec8713ea
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
2107
diff
changeset
|
761 |
^ retvalSpec , ' ' , (name allBold) , ' (' , argSpec , ')' |
189 | 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 |
||
154 | 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 |
||
189 | 797 |
typeFromSignature:aSignature in:package |
798 |
"given a signature, return its type as a string" |
|
799 |
||
238 | 800 |
|s c| |
189 | 801 |
|
802 |
s := aSignature readStream. |
|
803 |
(c := s peek) ~~ $( ifTrue:[ |
|
2086 | 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) |
|
189 | 811 |
]. |
812 |
||
813 |
s next. |
|
255 | 814 |
self argSpecFromStream:s in:nil. |
189 | 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 |
||
255 | 824 |
"Created: / 1.8.1997 / 10:50:38 / cg" |
825 |
"Modified: / 8.1.1998 / 19:09:31 / cg" |
|
10 | 826 |
! ! |
827 |
||
2151 | 828 |
!JavaMethod methodsFor:'* As yet uncategorized *'! |
829 |
||
830 |
sends:symbol1 or:symbol2 |
|
831 |
||
832 |
^false |
|
833 |
! ! |
|
834 |
||
10 | 835 |
!JavaMethod methodsFor:'accessing'! |
836 |
||
334 | 837 |
accessFlags |
838 |
"java calls this the modifiers" |
|
839 |
||
840 |
^ accessFlags |
|
841 |
||
842 |
"Created: / 9.4.1998 / 17:49:44 / cg" |
|
843 |
! |
|
844 |
||
2151 | 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 |
||
29 | 855 |
argSignature |
2151 | 856 |
^ self class argSigArrayFromSignature:descriptor |
857 |
! |
|
858 |
||
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>" |
|
29 | 866 |
! |
867 |
||
678 | 868 |
comment |
869 |
"should access the source here, and parse any method comment" |
|
870 |
||
871 |
^ nil |
|
872 |
! |
|
873 |
||
10 | 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 |
||
129 | 881 |
containingClass |
882 |
^ javaClass |
|
883 |
||
884 |
! |
|
885 |
||
169 | 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 |
||
75 | 896 |
decompiledSource |
897 |
|s| |
|
898 |
||
899 |
s := '' writeStream. |
|
175 | 900 |
self decompileSourceTo:s. |
75 | 901 |
^ s contents |
175 | 902 |
|
903 |
"Modified: 30.7.1997 / 16:27:55 / cg" |
|
75 | 904 |
! |
905 |
||
2151 | 906 |
descriptor |
907 |
||
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>" |
|
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 |
||
135 | 923 |
exceptionHandlerTable |
378 | 924 |
^ nil |
135 | 925 |
|
378 | 926 |
"Created: / 16.10.1998 / 01:50:51 / cg" |
135 | 927 |
! |
928 |
||
83 | 929 |
exceptionTable |
378 | 930 |
^ nil |
83 | 931 |
|
378 | 932 |
"Created: / 16.10.1998 / 01:51:04 / cg" |
83 | 933 |
! |
934 |
||
2151 | 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 |
||
2090 | 951 |
getSourcePosition |
952 |
^ 1 |
|
953 |
! |
|
954 |
||
90 | 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 |
||
10 | 962 |
javaByteCode |
184 | 963 |
"/ ^ javaByteCode |
964 |
^ byteCode |
|
10 | 965 |
|
966 |
"Created: 16.4.1996 / 14:55:44 / cg" |
|
184 | 967 |
"Modified: 1.8.1997 / 00:08:45 / cg" |
8 | 968 |
! |
969 |
||
27 | 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 |
||
2151 | 977 |
javaExceptionTable |
978 |
^ nil |
|
979 |
||
980 |
"Created: / 04-06-2011 / 18:16:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
981 |
! |
|
982 |
||
983 |
javaNumArgs |
|
984 |
^ self argSignature size. |
|
985 |
||
986 |
"Created: / 14-03-2011 / 15:50:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
987 |
! |
|
988 |
||
90 | 989 |
lineNumber |
252 | 990 |
lineNumberTable isNil ifTrue:[^ nil]. |
90 | 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 |
||
50 | 997 |
lineNumberTable |
2151 | 998 |
"/ lineNumberTable ifNil:[ lineNumberTable := Dictionary new.]. |
50 | 999 |
^ lineNumberTable |
1000 |
||
2151 | 1001 |
"Created: / 16-04-1996 / 12:34:04 / cg" |
1002 |
"Modified: / 13-12-2010 / 11:06:40 / Jan Kurs <kurs.jan@post.cz>" |
|
50 | 1003 |
! |
1004 |
||
618 | 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. |
|
651 | 1015 |
walker literalAction:[:pc :slotIndex :const | |
1016 |
const isJavaMethodRef ifTrue:[ |
|
654 | 1017 |
(aBlock value:(const name)) ifTrue:[^ const name]. |
651 | 1018 |
] ifFalse:[ |
1019 |
const isJavaClassRef ifTrue:[ |
|
654 | 1020 |
(aBlock value:(const name)) ifTrue:[^ const name]. |
651 | 1021 |
] |
1022 |
] |
|
1023 |
]. |
|
618 | 1024 |
walker decompile:self to:nil. |
654 | 1025 |
^ nil |
618 | 1026 |
|
1027 |
"Created: / 9.11.1999 / 15:21:40 / cg" |
|
654 | 1028 |
"Modified: / 24.12.1999 / 02:55:55 / cg" |
618 | 1029 |
! |
1030 |
||
85 | 1031 |
localVariableTable |
1032 |
^ localVariableTable |
|
1033 |
||
1034 |
" |
|
1035 |
JavaMethod allInstancesDo:[:m| m localVariableTable notNil ifTrue:[self halt]] |
|
1036 |
" |
|
1037 |
! |
|
1038 |
||
2151 | 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 |
||
2086 | 1050 |
methodArgAndVarNames |
2151 | 1051 |
^ "((1 to:self numArgs) collect:[:i | 'arg' , i printString])" |
1052 |
self methodArgNames |
|
2086 | 1053 |
, |
2151 | 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>" |
|
31 | 1058 |
! |
1059 |
||
1060 |
methodArgNames |
|
252 | 1061 |
|nA| |
1062 |
||
1063 |
nA := self numArgs. |
|
102 | 1064 |
localVariableTable notNil ifTrue:[ |
2151 | 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 |
] |
|
102 | 1083 |
]. |
252 | 1084 |
^ (1 to:nA) collect:[:i | 'arg' , i printString] |
2151 | 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>" |
|
31 | 1116 |
! |
1117 |
||
29 | 1118 |
name |
2151 | 1119 |
^ (selector copyWithoutLast:descriptor size) asSymbol |
29 | 1120 |
|
1121 |
"Created: 16.4.1996 / 11:34:22 / cg" |
|
1122 |
! |
|
1123 |
||
2151 | 1124 |
nameSpaceName |
1125 |
||
1126 |
^'' |
|
1127 |
||
1128 |
"Created: / 18-10-2010 / 19:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1129 |
! |
|
1130 |
||
252 | 1131 |
numLocals |
1132 |
^super numVars. |
|
1133 |
"/ numLocals isNil ifTrue:[^ 0]. |
|
1134 |
"/ ^ numLocals |
|
27 | 1135 |
|
252 | 1136 |
"Modified: / 3.1.1998 / 21:15:38 / cg" |
118 | 1137 |
! |
1138 |
||
261 | 1139 |
numVars |
1140 |
|n| |
|
118 | 1141 |
|
261 | 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" |
|
27 | 1147 |
! |
1148 |
||
175 | 1149 |
previousVersion |
1150 |
^ nil |
|
1151 |
||
1152 |
"Created: 30.7.1997 / 15:56:18 / cg" |
|
1153 |
! |
|
1154 |
||
2151 | 1155 |
previousVersionCode |
1156 |
||
1157 |
^nil |
|
1158 |
||
1159 |
"Created: / 18-10-2010 / 20:15:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1160 |
! |
|
1161 |
||
29 | 1162 |
retValSignature |
2151 | 1163 |
^ self class retValSpecFromSignature:descriptor in:nil |
29 | 1164 |
|
255 | 1165 |
"Modified: / 8.1.1998 / 19:06:40 / cg" |
29 | 1166 |
! |
1167 |
||
123 | 1168 |
returnType |
378 | 1169 |
"/ ^ returnType |
2151 | 1170 |
^ self class typeFromSignature:descriptor in:nil. |
378 | 1171 |
|
1172 |
"Modified: / 16.10.1998 / 00:17:43 / cg" |
|
123 | 1173 |
! |
1174 |
||
322 | 1175 |
returnTypeClass |
378 | 1176 |
|cls returnType| |
322 | 1177 |
|
378 | 1178 |
(returnType := self returnType) isNil ifTrue:[ |
2086 | 1179 |
self halt. |
322 | 1180 |
]. |
1181 |
cls := Java at:returnType. |
|
1182 |
cls notNil ifTrue:[^ cls]. |
|
1183 |
||
1184 |
returnType == #void ifTrue:[ |
|
2086 | 1185 |
^ nil |
322 | 1186 |
]. |
1187 |
returnType == #double ifTrue:[ |
|
2086 | 1188 |
'warning: no returnTypeClass for double' printCR. |
334 | 1189 |
"/ self halt:'no returnTypeClass for double'. |
2086 | 1190 |
^ nil |
322 | 1191 |
]. |
1192 |
returnType == #float ifTrue:[ |
|
2086 | 1193 |
'warning: no returnTypeClass for float' printCR. |
334 | 1194 |
"/ self halt:'no returnTypeClass for float'. |
2086 | 1195 |
^ nil |
322 | 1196 |
]. |
1197 |
returnType == #long ifTrue:[ |
|
2086 | 1198 |
'warning: no returnTypeClass for long' printCR. |
334 | 1199 |
"/ self halt:'no returnTypeClass for long'. |
2086 | 1200 |
^ nil |
334 | 1201 |
]. |
1202 |
returnType == #int ifTrue:[ |
|
2086 | 1203 |
'warning: no returnTypeClass for int' printCR. |
334 | 1204 |
"/ self halt:'no returnTypeClass for int'. |
2086 | 1205 |
^ nil |
334 | 1206 |
]. |
1207 |
returnType == #boolean ifTrue:[ |
|
2086 | 1208 |
'warning: no returnTypeClass for boolean' printCR. |
334 | 1209 |
"/ self halt:'no returnTypeClass for boolean'. |
2086 | 1210 |
^ nil |
322 | 1211 |
]. |
1212 |
self halt. |
|
1213 |
^ nil |
|
1214 |
||
1215 |
"Created: / 13.2.1998 / 15:08:26 / cg" |
|
378 | 1216 |
"Modified: / 16.10.1998 / 00:16:07 / cg" |
322 | 1217 |
! |
1218 |
||
116 | 1219 |
returnsDouble |
378 | 1220 |
^ self returnType == #double |
1221 |
||
1222 |
"Modified: / 16.10.1998 / 00:18:24 / cg" |
|
116 | 1223 |
! |
1224 |
||
72 | 1225 |
returnsLong |
378 | 1226 |
^ self returnType == #long |
1227 |
||
1228 |
"Modified: / 16.10.1998 / 00:18:41 / cg" |
|
72 | 1229 |
! |
1230 |
||
27 | 1231 |
returnsVoid |
378 | 1232 |
^ self returnType == #void |
1233 |
||
2151 | 1234 |
"Modified: / 16-10-1998 / 00:18:53 / cg" |
1235 |
"Modified: / 22-03-2011 / 12:27:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
27 | 1236 |
! |
1237 |
||
255 | 1238 |
selector |
378 | 1239 |
"/ could theoretically be extracted from my classes |
1240 |
"/ methodDictionary via: |
|
1241 |
"/ ^ javaClass methodDictionary keyAtValue:self ifAbsent:nil. |
|
1242 |
||
255 | 1243 |
^ selector |
1244 |
||
1245 |
"Created: / 7.1.1998 / 14:05:11 / cg" |
|
378 | 1246 |
"Modified: / 16.10.1998 / 13:41:06 / cg" |
255 | 1247 |
! |
1248 |
||
27 | 1249 |
signature |
2151 | 1250 |
|
1251 |
^ signature ? descriptor |
|
1252 |
||
1253 |
"Modified (format): / 14-08-2011 / 19:37:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
31 | 1254 |
! |
1255 |
||
1256 |
source |
|
2151 | 1257 |
| classSource | |
1258 |
"/ self isNative ifTrue:[ |
|
1259 |
"/ ^ 'native method' |
|
1260 |
"/ ]. |
|
169 | 1261 |
ForceByteCodeDisplay == true ifTrue:[ |
2151 | 1262 |
^ self decompiledBytecode |
169 | 1263 |
]. |
75 | 1264 |
lineNumberTable notNil ifTrue:[ |
2151 | 1265 |
classSource := javaClass source. |
1266 |
classSource notNil ifTrue:[ ^ classSource]. |
|
75 | 1267 |
]. |
1268 |
^ self decompiledSource |
|
169 | 1269 |
|
2151 | 1270 |
"Modified: / 04-01-1998 / 13:48:35 / cg" |
1271 |
"Modified: / 13-12-2010 / 11:06:51 / Jan Kurs <kurs.jan@post.cz>" |
|
31 | 1272 |
! |
1273 |
||
1274 |
sourceFilename |
|
1275 |
^ javaClass sourceFile |
|
175 | 1276 |
! |
1277 |
||
1278 |
sourceLineNumber |
|
2151 | 1279 |
" |
1280 |
sourceLineNumber ifNil: [ |
|
1281 |
sourceLineNumber := (JavaSourceCodeCache new) |
|
1282 |
findLineForMethod: self |
|
1283 |
inClass:javaClass. |
|
1284 |
]. |
|
1285 |
" |
|
1286 |
sourceLineNumber := 0. |
|
1287 |
||
1288 |
sourceLineNumber == 0 ifTrue: |
|
1289 |
[ |
|
1290 |
"There is something wrong with parsing" |
|
1291 |
"/ self halt. |
|
1292 |
self breakPoint: #libjava. |
|
1293 |
sourceLineNumber := self firstInstructionLineNumber -2. |
|
175 | 1294 |
]. |
1295 |
||
2151 | 1296 |
^ sourceLineNumber. |
1297 |
||
1298 |
"Created: / 30-07-1997 / 15:40:45 / cg" |
|
1299 |
"Modified: / 13-12-2010 / 23:46:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
1300 |
"Modified: / 08-01-2011 / 16:20:40 / Jan Kurs <kurs.jan@post.cz>" |
|
1301 |
"Modified: / 05-02-2011 / 22:29:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1302 |
! |
|
1303 |
||
1304 |
wrapper |
|
1305 |
||
1306 |
^nil |
|
1307 |
||
1308 |
"Created: / 18-10-2010 / 19:11:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1309 |
! ! |
|
1310 |
||
1311 |
!JavaMethod methodsFor:'compiler interface'! |
|
1312 |
||
1313 |
programmingLanguage |
|
1314 |
||
1315 |
^JavaLanguage instance |
|
1316 |
||
1317 |
"Created: / 26-10-2010 / 23:42:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
8 | 1318 |
! ! |
1319 |
||
255 | 1320 |
!JavaMethod methodsFor:'debugging'! |
1321 |
||
1322 |
breakPoint |
|
1323 |
Debugger enter:thisContext sender withMessage:'breakpoint' |
|
1324 |
||
1325 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1326 |
! |
|
1327 |
||
1328 |
clearBreakPoint |
|
449 | 1329 |
self hasCode ifTrue:[ |
2086 | 1330 |
MessageTracer unwrapMethod:self |
449 | 1331 |
]. |
1332 |
accessFlags := (accessFlags bitClear:A_BREAKPOINT). |
|
1333 |
||
1334 |
"Modified: / 13.11.1998 / 23:31:00 / cg" |
|
255 | 1335 |
! |
1336 |
||
257 | 1337 |
isCounting |
1338 |
^ false. |
|
1339 |
||
1340 |
"Created: / 12.1.1998 / 20:02:23 / cg" |
|
1341 |
! |
|
1342 |
||
1343 |
isCountingMemoryUsage |
|
1344 |
^ false. |
|
1345 |
||
1346 |
"Created: / 12.1.1998 / 20:03:22 / cg" |
|
1347 |
! |
|
1348 |
||
255 | 1349 |
setBreakPoint |
449 | 1350 |
self hasCode ifTrue:[ |
2086 | 1351 |
MessageTracer trapMethod:self |
449 | 1352 |
]. |
1353 |
accessFlags := (accessFlags bitOr:A_BREAKPOINT). |
|
1354 |
||
1355 |
"Modified: / 13.11.1998 / 23:30:45 / cg" |
|
257 | 1356 |
! |
1357 |
||
1358 |
setTraceFullPoint |
|
1359 |
"not yet implemented" |
|
1360 |
||
1361 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1362 |
"Created: / 12.1.1998 / 20:04:45 / cg" |
|
1363 |
! |
|
1364 |
||
1365 |
setTracePoint |
|
1366 |
"not yet implemented" |
|
1367 |
||
1368 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1369 |
"Created: / 12.1.1998 / 20:04:02 / cg" |
|
1370 |
! |
|
1371 |
||
1372 |
setTraceSenderPoint |
|
1373 |
"not yet implemented" |
|
1374 |
||
1375 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1376 |
"Created: / 12.1.1998 / 20:04:35 / cg" |
|
1377 |
! |
|
1378 |
||
1379 |
startCounting |
|
1380 |
"not yet implemented" |
|
1381 |
||
1382 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1383 |
"Created: / 12.1.1998 / 20:05:01 / cg" |
|
1384 |
! |
|
1385 |
||
1386 |
startCountingMemoryUsage |
|
1387 |
"not yet implemented" |
|
1388 |
||
1389 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1390 |
"Created: / 12.1.1998 / 20:05:04 / cg" |
|
1391 |
! |
|
1392 |
||
1393 |
startTiming |
|
1394 |
"not yet implemented" |
|
1395 |
||
1396 |
"Modified: / 9.1.1998 / 23:01:17 / cg" |
|
1397 |
"Created: / 12.1.1998 / 20:04:57 / cg" |
|
255 | 1398 |
! ! |
1399 |
||
18 | 1400 |
!JavaMethod methodsFor:'decompiling'! |
1401 |
||
175 | 1402 |
decompileSourceTo:aStream |
637 | 1403 |
|argNames| |
1404 |
||
1405 |
byteCode isNil ifTrue:[ |
|
1406 |
self isPublic ifTrue:[ |
|
1407 |
aStream nextPutAll:'public '. |
|
1408 |
]. |
|
1409 |
self isProtected ifTrue:[ |
|
1410 |
aStream nextPutAll:'protected '. |
|
1411 |
]. |
|
1412 |
self isPrivate ifTrue:[ |
|
1413 |
aStream nextPutAll:'private '. |
|
1414 |
]. |
|
1415 |
self isStatic ifTrue:[ |
|
1416 |
aStream nextPutAll:'static '. |
|
1417 |
]. |
|
1418 |
||
1419 |
self isNative ifTrue:[ |
|
1420 |
aStream nextPutAll:'native '. |
|
1421 |
]. |
|
1422 |
self isAbstract ifTrue:[ |
|
1423 |
aStream nextPutAll:'abstract '. |
|
1424 |
]. |
|
1425 |
argNames := #('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6' 'arg7' 'arg8' 'arg9'). |
|
1426 |
aStream nextPutAll:(self signatureNameWithArgNames:argNames). |
|
1427 |
aStream nextPutAll:';'; cr. |
|
1428 |
^ self |
|
1429 |
]. |
|
1430 |
||
2151 | 1431 |
" |
637 | 1432 |
JavaDeparser isNil ifTrue:[ |
1433 |
aStream nextPutAll:'// Sorry - no decompiler'. |
|
1434 |
^ self |
|
1435 |
]. |
|
2151 | 1436 |
" |
637 | 1437 |
|
1438 |
||
252 | 1439 |
"/ self isNative ifFalse:[ |
1440 |
"/ self isAbstract ifFalse:[ |
|
2151 | 1441 |
aStream nextPutAll:'// source not available...'; cr. |
637 | 1442 |
SignalSet anySignal handle:[:ex | |
1443 |
ex signal == Object haltSignal ifTrue:[ex reject]. |
|
1444 |
ex signal == MessageTracer breakpointSignal ifTrue:[ex reject]. |
|
1445 |
ex signal == Signal noHandlerSignal ifTrue:[ex reject]. |
|
506 | 1446 |
|
637 | 1447 |
aStream nextPutAll:'error while decompiling:'. |
1448 |
aStream cr; cr; spaces:4. |
|
1449 |
aStream nextPutAll:ex errorString. |
|
1450 |
aStream cr. |
|
1451 |
aStream nextPutAll:ex suspendedContext printString. |
|
1452 |
aStream cr. |
|
1453 |
aStream nextPutAll:ex suspendedContext sender printString. |
|
1454 |
aStream cr. |
|
1455 |
aStream nextPutAll:ex suspendedContext sender sender printString. |
|
1456 |
aStream cr. |
|
1457 |
aStream nextPutAll:ex suspendedContext sender sender sender printString. |
|
1458 |
aStream cr. |
|
1459 |
aStream nextPutAll:ex suspendedContext sender sender sender sender printString. |
|
1460 |
aStream cr. |
|
1461 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender printString. |
|
1462 |
aStream cr. |
|
2095 | 1463 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender printString. |
1464 |
aStream cr. |
|
1465 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender sender printString. |
|
1466 |
aStream cr. |
|
1467 |
aStream nextPutAll:ex suspendedContext sender sender sender sender sender sender sender sender printString. |
|
1468 |
aStream cr. |
|
506 | 1469 |
|
2151 | 1470 |
" |
1471 |
JavaByteCodeDisassembler isNil ifTrue:[ |
|
637 | 1472 |
aStream nextPutAll:'// Sorry - no decompiler' |
1473 |
] ifFalse:[ |
|
2151 | 1474 |
JavaByteCodeDisassembler diassemble:self to:aStream. |
637 | 1475 |
]. |
2151 | 1476 |
" |
637 | 1477 |
ex return |
1478 |
] do:[ |
|
2151 | 1479 |
"aStream nextPutAll:(JavaDeparser decompile:self)." |
1480 |
JavaByteCodeDisassembler diassemble:self to:aStream. |
|
637 | 1481 |
]. |
252 | 1482 |
"/ ]. |
1483 |
"/ ]. |
|
18 | 1484 |
|
2151 | 1485 |
"Created: / 30-07-1997 / 16:28:09 / cg" |
1486 |
"Modified: / 21-12-1999 / 14:31:54 / cg" |
|
1487 |
"Modified: / 22-03-2011 / 21:34:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 | 1488 |
! |
1489 |
||
1490 |
decompiler |
|
1491 |
^ JavaDecompiler |
|
1492 |
||
1493 |
"Created: 30.7.1997 / 16:36:48 / cg" |
|
261 | 1494 |
! |
1495 |
||
449 | 1496 |
isMethod |
1497 |
"return true, if the receiver is some kind of method; |
|
1498 |
true returned here - the method is redefined from Object." |
|
1499 |
||
1500 |
^ true |
|
1501 |
||
1502 |
"Created: / 13.11.1998 / 23:57:40 / cg" |
|
1503 |
! |
|
1504 |
||
261 | 1505 |
originalMethod |
1506 |
^ self |
|
1507 |
||
1508 |
"Created: / 13.1.1998 / 15:03:05 / cg" |
|
18 | 1509 |
! ! |
1510 |
||
277 | 1511 |
!JavaMethod methodsFor:'error handling'! |
1512 |
||
2151 | 1513 |
errorInvalidClassRefAt: index |
1514 |
||
1515 |
"Sent by the VM when an invalid entry in contant pool |
|
1516 |
is encountered - for instance when the VM expects |
|
1517 |
a classref but the entry is not a classref" |
|
1518 |
||
1519 |
" |
|
1520 |
javaClass constantPool at: index. |
|
1521 |
" |
|
1522 |
||
1523 |
JavaInvalidRefError new |
|
1524 |
javaClass: javaClass; |
|
1525 |
index: index; |
|
1526 |
raiseRequest |
|
1527 |
||
1528 |
"Created: / 18-07-2011 / 23:33:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1529 |
! |
|
1530 |
||
1531 |
errorInvalidFieldRefAt: index |
|
1532 |
||
1533 |
"Sent by the VM when an invalid entry in contant pool |
|
1534 |
is encountered - for instance when the VM expects |
|
1535 |
a classref but the entry is not a classref" |
|
1536 |
||
1537 |
" |
|
1538 |
javaClass constantPool at: index. |
|
1539 |
" |
|
1540 |
||
1541 |
JavaInvalidRefError new |
|
1542 |
javaClass: javaClass; |
|
1543 |
index: index; |
|
1544 |
raiseRequest |
|
1545 |
||
1546 |
"Created: / 18-07-2011 / 23:33:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1547 |
! |
|
1548 |
||
1549 |
errorInvalidMethodRefAt: index |
|
1550 |
||
1551 |
"Sent by the VM when an invalid entry in contant pool |
|
1552 |
is encountered - for instance when the VM expects |
|
1553 |
a classref but the entry is not a classref" |
|
1554 |
||
1555 |
" |
|
1556 |
javaClass constantPool at: index. |
|
1557 |
" |
|
1558 |
||
1559 |
JavaInvalidRefError new |
|
1560 |
javaClass: javaClass; |
|
1561 |
index: index; |
|
1562 |
raiseRequest |
|
1563 |
||
1564 |
"Created: / 18-07-2011 / 19:59:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1565 |
! |
|
1566 |
||
277 | 1567 |
invalidByteCode |
1568 |
self isAbstract ifTrue:[ |
|
2151 | 1569 |
^ AbstractMethodInvokationSignal raise. |
277 | 1570 |
]. |
2151 | 1571 |
((self class numArgsFromSignature:descriptor) > self class maxNumberOfArguments) ifTrue:[ |
1572 |
^ self error:'method cannot be executed - too many args' |
|
309 | 1573 |
]. |
277 | 1574 |
^ super invalidByteCode |
1575 |
||
2151 | 1576 |
"Created: / 27-01-1998 / 21:48:01 / cg" |
1577 |
"Modified: / 14-08-2011 / 19:29:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
378 | 1578 |
! |
1579 |
||
1580 |
invalidMethodRef |
|
1581 |
self halt. |
|
1582 |
^ nil. |
|
1583 |
||
1584 |
"Modified: / 27.1.1998 / 21:50:19 / cg" |
|
1585 |
"Created: / 16.10.1998 / 11:27:21 / cg" |
|
594 | 1586 |
! |
1587 |
||
1588 |
nullClassPointer |
|
1589 |
JavaVM throwClassNotFoundException |
|
277 | 1590 |
! ! |
1591 |
||
2151 | 1592 |
!JavaMethod methodsFor:'initialization'! |
1593 |
||
1594 |
setAccessFlags:flags |
|
1595 |
accessFlags := flags. |
|
1596 |
||
1597 |
"Created: 16.4.1996 / 11:34:14 / cg" |
|
1598 |
! |
|
1599 |
||
1600 |
setCode:codeBytes maxStack:max_stack maxLocals:max_locals u1:unknown1 u2:unknown2 |
|
1601 |
"/ javaByteCode := codeBytes. |
|
1602 |
byteCode := codeBytes. |
|
1603 |
"/ numStack := max_stack. |
|
1604 |
"/ numLocals := max_locals. |
|
1605 |
super numberOfVars:max_locals. |
|
1606 |
super stackSize:max_stack. |
|
1607 |
||
1608 |
"/ self displayString printNL. |
|
1609 |
"/ ' nStack: ' print. numStack print. |
|
1610 |
"/ ' nLocal: ' print. numLocals print. |
|
1611 |
"/ ' u1: ' print. unknown1 print. |
|
1612 |
"/ ' u2: ' print. unknown2 printNL. |
|
1613 |
||
1614 |
"Modified: 1.8.1997 / 00:08:32 / cg" |
|
1615 |
! |
|
1616 |
||
1617 |
setDescriptor:aString |
|
1618 |
||
1619 |
descriptor := aString asSymbol. |
|
1620 |
||
1621 |
"Created: / 16-04-1996 / 11:34:29 / cg" |
|
1622 |
"Modified: / 16-10-1998 / 00:17:12 / cg" |
|
1623 |
"Modified: / 13-08-2011 / 01:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1624 |
"Created: / 14-08-2011 / 19:41:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1625 |
! |
|
1626 |
||
1627 |
setJavaClass:aJavaClass |
|
1628 |
javaClass := aJavaClass |
|
1629 |
||
1630 |
"Modified: 16.4.1996 / 12:36:27 / cg" |
|
1631 |
"Created: 16.4.1996 / 15:28:15 / cg" |
|
1632 |
! |
|
1633 |
||
1634 |
setLineNumberTable:anArrayOfPCtoLineAssociations |
|
1635 |
"since this uses up lots of memory, compress it" |
|
1636 |
||
1637 |
|allBytes allWords idx| |
|
1638 |
||
1639 |
allBytes := allWords := true. |
|
1640 |
||
1641 |
anArrayOfPCtoLineAssociations do:[:assoc | |
|
1642 |
assoc key > 255 ifTrue:[ |
|
1643 |
allBytes := false. |
|
1644 |
assoc key > 16rFFFF ifTrue:[ |
|
1645 |
allWords := false. |
|
1646 |
]. |
|
1647 |
]. |
|
1648 |
assoc value > 255 ifTrue:[ |
|
1649 |
allBytes := false. |
|
1650 |
assoc value > 16rFFFF ifTrue:[ |
|
1651 |
allWords := false |
|
1652 |
]. |
|
1653 |
]. |
|
1654 |
]. |
|
1655 |
allBytes ifTrue:[ |
|
1656 |
lineNumberTable := ByteArray new:(anArrayOfPCtoLineAssociations size * 2). |
|
1657 |
] ifFalse:[ |
|
1658 |
allWords ifTrue:[ |
|
1659 |
lineNumberTable := WordArray new:(anArrayOfPCtoLineAssociations size * 2). |
|
1660 |
] ifFalse:[ |
|
1661 |
lineNumberTable := Array new:(anArrayOfPCtoLineAssociations size * 2). |
|
1662 |
] |
|
1663 |
]. |
|
1664 |
||
1665 |
idx := 1. |
|
1666 |
anArrayOfPCtoLineAssociations do:[:assoc | |
|
1667 |
lineNumberTable at:idx put:assoc key. |
|
1668 |
lineNumberTable at:idx+1 put:assoc value. |
|
1669 |
idx := idx + 2. |
|
1670 |
]. |
|
1671 |
||
1672 |
"Created: 16.4.1996 / 12:34:04 / cg" |
|
1673 |
"Modified: 16.4.1996 / 12:49:06 / cg" |
|
1674 |
! |
|
1675 |
||
1676 |
setLocalVariableTable:anArray |
|
1677 |
localVariableTable := anArray. |
|
1678 |
! |
|
1679 |
||
1680 |
setName:nameString descriptor:aString |
|
1681 |
||
1682 |
||
1683 |
|numArgs tooManyArgs returnType| |
|
1684 |
||
1685 |
selector := (nameString , aString) asSymbol. |
|
1686 |
self setDescriptor:aString. |
|
1687 |
||
1688 |
numArgs := self class numArgsFromSignature:aString. |
|
1689 |
(tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[ |
|
1690 |
numArgs := 0. |
|
1691 |
]. |
|
1692 |
self numberOfArgs:numArgs. |
|
1693 |
returnType := self class typeFromSignature:aString in:nil. |
|
1694 |
||
1695 |
"/ for the convenience of the VM, also mirror the return type in |
|
1696 |
"/ the flags ... |
|
1697 |
||
1698 |
returnType == #void ifTrue:[ |
|
1699 |
accessFlags := accessFlags bitOr:R_VOID |
|
1700 |
] ifFalse:[ |
|
1701 |
returnType == #long ifTrue:[ |
|
1702 |
accessFlags := accessFlags bitOr:R_LONG |
|
1703 |
] ifFalse:[ |
|
1704 |
returnType == #double ifTrue:[ |
|
1705 |
accessFlags := accessFlags bitOr:R_DOUBLE |
|
1706 |
] |
|
1707 |
] |
|
1708 |
]. |
|
1709 |
tooManyArgs ifTrue:[ |
|
1710 |
^ ArgumentError |
|
1711 |
raiseRequestWith:self |
|
1712 |
errorString:'too many args in method' |
|
1713 |
]. |
|
1714 |
||
1715 |
"Created: / 14-08-2011 / 19:41:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1716 |
! |
|
1717 |
||
1718 |
setSignature:aString |
|
1719 |
||
1720 |
signature := aString asSymbol. |
|
1721 |
||
1722 |
"Created: / 16-04-1996 / 11:34:29 / cg" |
|
1723 |
"Modified: / 16-10-1998 / 00:17:12 / cg" |
|
1724 |
"Modified (format): / 14-08-2011 / 19:41:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1725 |
! ! |
|
1726 |
||
1727 |
!JavaMethod methodsFor:'inspecting'! |
|
1728 |
||
1729 |
inspectorExtraAttributes |
|
1730 |
"extra (pseudo instvar) entries to be shown in an inspector." |
|
1731 |
||
1732 |
^ Dictionary new |
|
1733 |
declareAllNewFrom:(super inspectorExtraAttributes ? #()); |
|
1734 |
"/add:'-code' -> [ String streamContents:[:s | JavaDecompiler decompile: self to: s] ]; |
|
1735 |
add:'-code' -> [ String streamContents:[:s | JavaByteCodeDisassembler diassemble: self to: s] ]; |
|
1736 |
"/add:'-source' -> [ self source ]; |
|
1737 |
yourself |
|
1738 |
||
1739 |
"Modified: / 22-03-2011 / 21:13:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1740 |
! ! |
|
1741 |
||
1742 |
!JavaMethod methodsFor:'interpretation'! |
|
1743 |
||
1744 |
interpretWithReceiver: receiver |
|
1745 |
||
1746 |
^self |
|
1747 |
interpretWithReceiver: receiver |
|
1748 |
arguments: #() |
|
1749 |
||
1750 |
"Created: / 24-02-2011 / 22:05:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1751 |
! |
|
1752 |
||
1753 |
interpretWithReceiver: receiver arg: a1 |
|
1754 |
||
1755 |
^self |
|
1756 |
interpretWithReceiver: receiver |
|
1757 |
arguments: (Array with: a1) |
|
1758 |
||
1759 |
"Created: / 24-02-2011 / 22:05:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1760 |
! |
|
1761 |
||
1762 |
interpretWithReceiver: receiver arg: a1 arg: a2 |
|
1763 |
||
1764 |
^self |
|
1765 |
interpretWithReceiver: receiver |
|
1766 |
arguments: (Array with: a1 with: a2) |
|
1767 |
||
1768 |
"Created: / 24-02-2011 / 22:05:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1769 |
! |
|
1770 |
||
1771 |
interpretWithReceiver: receiver arg: a1 arg: a2 arg: a3 |
|
1772 |
||
1773 |
^self |
|
1774 |
interpretWithReceiver: receiver |
|
1775 |
arguments: (Array with: a1 with: a2 with: a3) |
|
1776 |
||
1777 |
"Created: / 24-02-2011 / 22:06:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1778 |
! |
|
1779 |
||
1780 |
interpretWithReceiver: receiver arguments:args |
|
1781 |
||
1782 |
^ JavaByteCodeInterpreter |
|
1783 |
interpret:self |
|
1784 |
receiver:receiver |
|
1785 |
arguments:args |
|
1786 |
||
1787 |
"Modified: / 24-02-2011 / 23:00:42 / Marcel Hlopko <hlopik@gmail.com>" |
|
1788 |
"Created: / 24-02-2011 / 22:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1789 |
! ! |
|
1790 |
||
118 | 1791 |
!JavaMethod methodsFor:'methodref interchangability'! |
1792 |
||
673 | 1793 |
homeMethod |
1794 |
^ self |
|
1795 |
! |
|
1796 |
||
118 | 1797 |
method |
1798 |
^ self |
|
692 | 1799 |
! |
1800 |
||
1801 |
setPackage:newPackage |
|
1802 |
newPackage ~= javaClass package ifTrue:[ |
|
1803 |
self halt:'java method cannot be in a package different from its class'. |
|
1804 |
] |
|
118 | 1805 |
! ! |
1806 |
||
148 | 1807 |
!JavaMethod methodsFor:'misc'! |
1808 |
||
378 | 1809 |
fromMethod:aJavaMethod |
1810 |
"copy values from another javaMethod" |
|
149 | 1811 |
|
378 | 1812 |
flags := aJavaMethod flags. |
1813 |
byteCode := aJavaMethod byteCode. |
|
1814 |
accessFlags := aJavaMethod accessFlags. |
|
1815 |
selector := aJavaMethod selector. |
|
1816 |
javaClass := aJavaMethod javaClass. |
|
2151 | 1817 |
descriptor := aJavaMethod instVarNamed:#descriptor. |
1818 |
signature := aJavaMethod instVarNamed:#signature. |
|
378 | 1819 |
lineNumberTable := aJavaMethod lineNumberTable. |
1820 |
localVariableTable := aJavaMethod localVariableTable. |
|
2151 | 1821 |
annotations := aJavaMethod annotations. |
1822 |
||
1823 |
"Modified: / 16-10-1998 / 01:27:19 / cg" |
|
1824 |
"Modified: / 14-08-2011 / 19:30:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 | 1825 |
! |
252 | 1826 |
|
255 | 1827 |
updateClassRefsFrom:oldClass to:newClass |
1828 |
javaClass == oldClass ifTrue:[ |
|
2086 | 1829 |
"/ invalidate |
1830 |
byteCode := nil. |
|
255 | 1831 |
] |
252 | 1832 |
|
255 | 1833 |
"Created: / 6.1.1998 / 18:19:48 / cg" |
252 | 1834 |
! ! |
1835 |
||
8 | 1836 |
!JavaMethod methodsFor:'printing & storing'! |
1837 |
||
29 | 1838 |
displayString |
168 | 1839 |
javaClass isNil ifTrue:[ |
611 | 1840 |
^ self class name , '(???)' |
168 | 1841 |
]. |
611 | 1842 |
^ self class name , '(' , javaClass displayString , '::' , self signatureName , ')' |
423 | 1843 |
|
611 | 1844 |
"Modified: / 25.9.1999 / 23:04:01 / cg" |
29 | 1845 |
! |
1846 |
||
670 | 1847 |
printStringForBrowserWithSelector:dummySelector inClass:dummyClass |
43 | 1848 |
"/ self isStatic ifTrue:[ |
1849 |
"/ ^ 'static ' , self signatureName |
|
1850 |
"/ ]. |
|
168 | 1851 |
"/ self isBreakpointed ifTrue:[ |
1852 |
"/ ^ (LabelAndIcon '!! ' , self signatureName |
|
1853 |
"/ ]. |
|
175 | 1854 |
|
252 | 1855 |
self name = #'<init>' ifTrue:[ |
2151 | 1856 |
^ self class specTextFromSignature:descriptor in:javaClass package withName:(javaClass lastName). |
166 | 1857 |
]. |
2151 | 1858 |
^ self class specTextFromSignature:descriptor in:javaClass package withName:(self name) |
10 | 1859 |
! |
1860 |
||
118 | 1861 |
shortDisplayString |
1862 |
^ javaClass name , '::' , self signatureNameWithoutReturnType |
|
1863 |
! |
|
1864 |
||
10 | 1865 |
signatureName |
1866 |
"return a string to be used when browsing" |
|
1867 |
||
2151 | 1868 |
^ self class specFromSignature:descriptor withName:(self name) in:nil |
255 | 1869 |
|
1870 |
"Modified: / 8.1.1998 / 19:15:33 / cg" |
|
113 | 1871 |
! |
1872 |
||
164 | 1873 |
signatureNameFor:name withArgsIn:aPackage |
1874 |
"return a string to be used when decompiling" |
|
1875 |
||
2151 | 1876 |
^ self class specWithArgsFromSignature:descriptor withName:name in:aPackage |
164 | 1877 |
|
1878 |
"Created: 25.3.1997 / 18:49:45 / cg" |
|
1879 |
! |
|
1880 |
||
142 | 1881 |
signatureNameIn:aPackage |
1882 |
"return a string to be used when browsing" |
|
1883 |
||
2151 | 1884 |
^ self class specFromSignature:descriptor withName:(self name) in:aPackage |
142 | 1885 |
|
1886 |
"Created: 18.3.1997 / 11:11:01 / cg" |
|
1887 |
! |
|
1888 |
||
175 | 1889 |
signatureNameText |
1890 |
"return a text to be used when browsing" |
|
1891 |
||
2151 | 1892 |
^ self class specTextFromSignature:descriptor withName:(self name) |
175 | 1893 |
|
1894 |
"Created: 30.7.1997 / 14:40:29 / cg" |
|
1895 |
! |
|
1896 |
||
189 | 1897 |
signatureNameTextFor:name withArgsIn:aPackage |
1898 |
"return a text to be used when decompiling" |
|
1899 |
||
2151 | 1900 |
^ self class specTextWithArgsFromSignature:descriptor withName:name in:aPackage |
189 | 1901 |
|
1902 |
"Created: 25.3.1997 / 18:49:45 / cg" |
|
1903 |
"Modified: 1.8.1997 / 10:44:28 / cg" |
|
1904 |
! |
|
1905 |
||
255 | 1906 |
signatureNameWithArgNames:argNames |
1907 |
"return a string to be used when browsing" |
|
1908 |
||
1909 |
|myName| |
|
1910 |
||
1911 |
myName := self name. |
|
1912 |
myName = '<init>' ifTrue:[ |
|
2086 | 1913 |
myName := javaClass name |
255 | 1914 |
]. |
2151 | 1915 |
^ self class specFromSignature:descriptor withName:myName argNames:argNames in:nil |
255 | 1916 |
|
1917 |
"Created: / 8.1.1998 / 21:04:03 / cg" |
|
1918 |
"Modified: / 8.1.1998 / 21:22:38 / cg" |
|
1919 |
! |
|
1920 |
||
1921 |
signatureNameWithArgNames:argNames in:package |
|
1922 |
"return a string to be used when browsing" |
|
1923 |
||
1924 |
|myName| |
|
1925 |
||
1926 |
myName := self name. |
|
1927 |
myName = '<init>' ifTrue:[ |
|
2086 | 1928 |
myName := javaClass name |
255 | 1929 |
]. |
2151 | 1930 |
^ self class specFromSignature:descriptor withName:myName argNames:argNames in:package |
255 | 1931 |
|
1932 |
"Modified: / 8.1.1998 / 21:05:52 / cg" |
|
1933 |
"Created: / 8.1.1998 / 21:23:03 / cg" |
|
1934 |
! |
|
1935 |
||
154 | 1936 |
signatureNameWithArgsIn:aPackage |
1937 |
"return a string to be used when browsing" |
|
1938 |
||
2151 | 1939 |
^ self class specWithArgsFromSignature:descriptor withName:(self name) in:aPackage |
1940 |
||
1941 |
"Created: / 20-03-1997 / 12:44:17 / cg" |
|
1942 |
"Modified: / 14-08-2011 / 19:29:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1943 |
! |
|
1944 |
||
1945 |
signatureNameWithModifiers |
|
1946 |
"return a string to be used when deassembling" |
|
1947 |
||
1948 |
| result | |
|
1949 |
||
1950 |
result := self signatureName. |
|
1951 |
self isFinal ifTrue: [ result := 'final ' , result ]. |
|
1952 |
self isStatic ifTrue: [ result := 'static ' , result ]. |
|
1953 |
self isSynchronized ifTrue: [ result := 'synchronized ' , result ]. |
|
1954 |
self isPrivate |
|
1955 |
ifTrue: [ result := 'private ' , result ] |
|
1956 |
ifFalse: |
|
1957 |
[ self isProtected |
|
1958 |
ifTrue: [ result := 'protected ' , result ] |
|
1959 |
ifFalse: [ self isPublic ifTrue: [ result := 'public ' , result ] ] ]. |
|
1960 |
self isAbstract ifTrue: [ result := 'abstract ' , result ]. |
|
1961 |
^ result. |
|
1962 |
||
1963 |
"Modified: / 08-01-1998 / 19:15:33 / cg" |
|
1964 |
"Created: / 22-03-2011 / 16:25:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
154 | 1965 |
! |
1966 |
||
113 | 1967 |
signatureNameWithoutReturnType |
1968 |
"return a string to be used when browsing" |
|
1969 |
||
2151 | 1970 |
^ self class argSpecFromSignature:descriptor withName:(self name) |
113 | 1971 |
|
8 | 1972 |
! ! |
1973 |
||
1974 |
!JavaMethod methodsFor:'queries'! |
|
1975 |
||
111 | 1976 |
handlerFor:anException at:pc |
611 | 1977 |
"return an exceptionHandlers pc, for an exception of the given type, |
1978 |
occurring at pc. Returns nil, if there is none." |
|
1979 |
||
1980 |
|handlerTable| |
|
1981 |
||
1982 |
(handlerTable := self exceptionHandlerTable) isNil ifTrue:[^ nil]. |
|
1983 |
||
1984 |
handlerTable do:[:entry | |
|
1985 |
|hpc| |
|
1986 |
||
1987 |
hpc := entry handlerPCFor:anException at:pc in:self. |
|
1988 |
hpc notNil ifTrue:[^ hpc]. |
|
1989 |
]. |
|
1990 |
||
378 | 1991 |
^ nil |
48 | 1992 |
|
611 | 1993 |
"Created: / 16.10.1998 / 01:18:40 / cg" |
1994 |
"Modified: / 25.9.1999 / 23:07:01 / cg" |
|
31 | 1995 |
! |
1996 |
||
2151 | 1997 |
hasPrimitiveCode |
1998 |
||
1999 |
^false |
|
2000 |
||
2001 |
"Created: / 18-07-2011 / 20:45:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2002 |
! |
|
2003 |
||
127 | 2004 |
hasResource |
2005 |
^ false |
|
2006 |
! |
|
2007 |
||
19 | 2008 |
isAbstract |
252 | 2009 |
^ (accessFlags bitAnd:A_ABSTRACT) ~~ 0 |
19 | 2010 |
! |
2011 |
||
80 | 2012 |
isBreakpointed |
256 | 2013 |
^ (accessFlags bitAnd:A_BREAKPOINT) ~~ 0 |
2014 |
||
2015 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
80 | 2016 |
! |
2017 |
||
19 | 2018 |
isFinal |
252 | 2019 |
^ (accessFlags bitAnd:A_FINAL) ~~ 0 |
19 | 2020 |
! |
2021 |
||
175 | 2022 |
isIgnored |
2023 |
"not really a java attribute; |
|
2024 |
added to allow browsing" |
|
2025 |
||
2026 |
^ false. |
|
2027 |
||
2028 |
"Created: 30.7.1997 / 15:34:33 / cg" |
|
2029 |
! |
|
2030 |
||
625 | 2031 |
isJavaClassRef |
2032 |
^ false |
|
2033 |
||
2034 |
"Created: / 9.11.1999 / 17:16:20 / cg" |
|
2035 |
! |
|
2036 |
||
431 | 2037 |
isJavaMethod |
2038 |
^ true |
|
2039 |
||
2040 |
"Created: / 10.11.1998 / 18:24:51 / cg" |
|
2041 |
! |
|
2042 |
||
19 | 2043 |
isNative |
252 | 2044 |
^ (accessFlags bitAnd:A_NATIVE) ~~ 0 |
19 | 2045 |
! |
2046 |
||
2047 |
isPrivate |
|
252 | 2048 |
^ (accessFlags bitAnd:A_PRIVATE) ~~ 0 |
19 | 2049 |
! |
2050 |
||
2051 |
isProtected |
|
252 | 2052 |
^ (accessFlags bitAnd:A_PROTECTED) ~~ 0 |
19 | 2053 |
! |
2054 |
||
2055 |
isPublic |
|
252 | 2056 |
^ (accessFlags bitAnd:A_PUBLIC) ~~ 0 |
19 | 2057 |
! |
2058 |
||
2059 |
isStatic |
|
252 | 2060 |
^ (accessFlags bitAnd:A_STATIC) ~~ 0 |
19 | 2061 |
! |
2062 |
||
2063 |
isSynchronized |
|
252 | 2064 |
^ (accessFlags bitAnd:A_SYNCHRONIZED) ~~ 0 |
18 | 2065 |
! |
2066 |
||
256 | 2067 |
isTraced |
2068 |
^ false |
|
2069 |
||
2070 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
2071 |
"Created: / 11.1.1998 / 13:38:11 / cg" |
|
2072 |
! |
|
2073 |
||
8 | 2074 |
isUnloaded |
2075 |
^ false |
|
18 | 2076 |
! |
2077 |
||
2151 | 2078 |
isUnresolved |
2079 |
"return true, if the receiver is unresolved;" |
|
2080 |
||
2081 |
||
2082 |
^ false |
|
2083 |
||
2084 |
"Created: / 06-03-2011 / 22:57:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2085 |
! |
|
2086 |
||
256 | 2087 |
isWrapped |
2088 |
^ self isBreakpointed |
|
2089 |
||
2090 |
"Modified: / 11.1.1998 / 13:28:43 / cg" |
|
2091 |
"Created: / 11.1.1998 / 13:38:04 / cg" |
|
2092 |
! |
|
2093 |
||
31 | 2094 |
lineNumberForPC:pc |
75 | 2095 |
|last num text classSource| |
31 | 2096 |
|
2097 |
num := nil. |
|
2098 |
||
207 | 2099 |
ForceByteCodeDisplay == true ifFalse:[ |
169 | 2100 |
|
2086 | 2101 |
lineNumberTable notNil ifTrue:[ |
2102 |
classSource := javaClass source. |
|
2103 |
classSource notNil ifTrue:[ |
|
2104 |
lineNumberTable pairWiseDo:[:lPc :lNr | |
|
2105 |
lPc >= pc ifTrue:[ |
|
2106 |
lPc == pc ifTrue:[^ lNr]. |
|
2107 |
last isNil ifTrue:[^ lNr]. |
|
2108 |
^ last. |
|
2109 |
]. |
|
2110 |
last := lNr. |
|
2111 |
]. |
|
2112 |
last notNil ifTrue:[ |
|
2113 |
^ last |
|
2114 |
]. |
|
2115 |
^ lineNumberTable at:2 |
|
2116 |
]. |
|
2117 |
]. |
|
46 | 2118 |
]. |
31 | 2119 |
|
46 | 2120 |
"/ decompile and look which line the pc falls into |
209 | 2121 |
|
2122 |
ForceByteCodeDisplay == true ifTrue:[ |
|
2086 | 2123 |
text := self decompiledBytecode asCollectionOfLines. |
209 | 2124 |
] ifFalse:[ |
2086 | 2125 |
text := self decompiledSource asCollectionOfLines. |
209 | 2126 |
]. |
31 | 2127 |
|
46 | 2128 |
text keysAndValuesDo:[:lineNr :line | |
2086 | 2129 |
|nr| |
750 | 2130 |
|
2086 | 2131 |
(line startsWith:' ') ifFalse:[ |
2132 |
nr := Integer readFrom:line onError:0. |
|
2133 |
nr >= pc ifTrue:[ |
|
2134 |
^ lineNr |
|
2135 |
] |
|
2136 |
] |
|
31 | 2137 |
]. |
2138 |
^ num |
|
141 | 2139 |
|
261 | 2140 |
"Modified: / 14.1.1998 / 13:30:54 / cg" |
31 | 2141 |
! |
2142 |
||
2087 | 2143 |
messagesSent |
2144 |
"return a collection of messages sent by this method" |
|
2145 |
||
2091 | 2146 |
|walker selectors| |
2087 | 2147 |
|
2148 |
"/ sigh - must extract all accessed literals ... |
|
2149 |
"/ must deparse the byteCode in order to do this. |
|
2150 |
||
2151 |
selectors := IdentitySet new. |
|
2152 |
walker := JavaByteCodeEnumerator new. |
|
2153 |
walker |
|
2154 |
literalAction: |
|
2155 |
[:pc :slotIndex :const | |
|
2156 |
|mSel| |
|
2157 |
||
2158 |
(const isNumber |
|
2159 |
or:[const isString |
|
2160 |
or:[const isNil]]) ifFalse:[ |
|
2161 |
const isJavaMethod ifTrue:[ |
|
2162 |
mSel := const selector. |
|
2163 |
] ifFalse:[ |
|
2164 |
const isJavaMethodRef ifTrue:[ |
|
2165 |
mSel := const selector "/ signature. |
|
2166 |
] |
|
2167 |
]. |
|
2168 |
]. |
|
2169 |
mSel notNil ifTrue:[ |
|
2170 |
"/ Transcript showCR:mSel. |
|
2171 |
selectors add:mSel |
|
2172 |
]. |
|
2173 |
]. |
|
2174 |
walker decompile:self to:nil. |
|
2175 |
^ selectors |
|
2176 |
! |
|
2177 |
||
156 | 2178 |
package |
685 | 2179 |
"in java, class extensions are not possible; |
2180 |
all methods MUST be in their classes package" |
|
156 | 2181 |
|
685 | 2182 |
^ javaClass package |
156 | 2183 |
! |
2184 |
||
428 | 2185 |
quickLineNumberForPC:pc |
2186 |
|last| |
|
2187 |
||
2188 |
lineNumberTable notNil ifTrue:[ |
|
2086 | 2189 |
lineNumberTable pairWiseDo:[:lPc :lNr | |
2190 |
lPc >= pc ifTrue:[ |
|
2191 |
lPc == pc ifTrue:[^ lNr]. |
|
2192 |
last isNil ifTrue:[^ lNr]. |
|
2193 |
^ last. |
|
2194 |
]. |
|
2195 |
last := lNr. |
|
2196 |
]. |
|
2197 |
last notNil ifTrue:[ |
|
2198 |
^ last |
|
2199 |
]. |
|
2200 |
^ lineNumberTable at:2 |
|
428 | 2201 |
]. |
2202 |
^ nil |
|
2203 |
||
2204 |
"Modified: / 14.1.1998 / 13:30:54 / cg" |
|
2205 |
"Created: / 10.11.1998 / 14:18:22 / cg" |
|
2206 |
! |
|
2207 |
||
625 | 2208 |
referencesGlobal:aGlobalName |
2209 |
"return true, if this method refers to a global named aGlobalName" |
|
2210 |
||
2211 |
|walker any| |
|
2212 |
||
2213 |
"/ quick check, if constantPool includes a methodRef for this |
|
2214 |
"/ selector. |
|
2215 |
||
2216 |
any := false. |
|
2217 |
self javaClass constantPool do:[:const | |
|
2218 |
(const isNumber |
|
2219 |
or:[const isString |
|
2220 |
or:[const isNil]]) ifFalse:[ |
|
2221 |
const isJavaClass ifTrue:[ |
|
2222 |
any := any or:[const fullName = aGlobalName]. |
|
2223 |
] ifFalse:[ |
|
2224 |
const isJavaClassRef ifTrue:[ |
|
2225 |
any := any or:[const fullName = aGlobalName]. |
|
2226 |
] |
|
2227 |
]. |
|
2228 |
]. |
|
2229 |
]. |
|
2230 |
any ifFalse:[^ false]. |
|
2231 |
||
2232 |
"/ sigh - must extract all accessed literals ... |
|
2233 |
"/ must deparse the byteCode in order to do this. |
|
2234 |
||
2235 |
walker := JavaByteCodeEnumerator new. |
|
2236 |
walker |
|
2237 |
literalAction: |
|
2238 |
[:pc :slotIndex :const | |
|
2239 |
|mSel| |
|
2240 |
||
2241 |
(const isNumber |
|
2242 |
or:[const isString |
|
2243 |
or:[const isNil]]) ifFalse:[ |
|
2244 |
const isJavaClass ifTrue:[ |
|
2245 |
mSel := const fullName. |
|
2246 |
] ifFalse:[ |
|
2247 |
const isJavaClassRef ifTrue:[ |
|
2248 |
mSel := const fullName. |
|
2249 |
] |
|
2250 |
]. |
|
2251 |
]. |
|
2252 |
mSel notNil ifTrue:[ |
|
2253 |
"/ Transcript showCR:mSel. |
|
2254 |
mSel = aGlobalName ifTrue:[ |
|
2255 |
^ true |
|
2256 |
] |
|
2257 |
]. |
|
2258 |
]. |
|
2259 |
walker decompile:self to:nil. |
|
2260 |
||
2261 |
"Created: / 9.11.1999 / 17:15:46 / cg" |
|
2262 |
"Modified: / 9.11.1999 / 17:18:02 / cg" |
|
2263 |
! |
|
2264 |
||
618 | 2265 |
sends:aSelectorSymbol |
2266 |
"return true, if this method contains a message-send |
|
2267 |
with aSelectorSymbol as selector." |
|
2268 |
||
2269 |
|walker any| |
|
2270 |
||
2271 |
"/ quick check, if constantPool includes a methodRef for this |
|
2272 |
"/ selector. |
|
2273 |
||
2274 |
any := false. |
|
2275 |
self javaClass constantPool do:[:const | |
|
2276 |
(const isNumber |
|
2277 |
or:[const isString |
|
2278 |
or:[const isNil]]) ifFalse:[ |
|
2279 |
const isJavaMethod ifTrue:[ |
|
2280 |
any := any or:[const selector = aSelectorSymbol]. |
|
2281 |
] ifFalse:[ |
|
2282 |
const isJavaMethodRef ifTrue:[ |
|
2283 |
any := any or:[const signature = aSelectorSymbol]. |
|
2284 |
] |
|
2285 |
]. |
|
2286 |
]. |
|
2287 |
]. |
|
2288 |
any ifFalse:[^ false]. |
|
2289 |
||
625 | 2290 |
"/ sigh - must extract all accessed literals ... |
2291 |
"/ must deparse the byteCode in order to do this. |
|
2292 |
||
618 | 2293 |
walker := JavaByteCodeEnumerator new. |
2294 |
walker |
|
2295 |
literalAction: |
|
2296 |
[:pc :slotIndex :const | |
|
2297 |
|mSel| |
|
2298 |
||
2299 |
(const isNumber |
|
2300 |
or:[const isString |
|
2301 |
or:[const isNil]]) ifFalse:[ |
|
2302 |
const isJavaMethod ifTrue:[ |
|
2303 |
mSel := const selector. |
|
2304 |
] ifFalse:[ |
|
2305 |
const isJavaMethodRef ifTrue:[ |
|
2306 |
mSel := const signature. |
|
2307 |
] |
|
2308 |
]. |
|
2309 |
]. |
|
2310 |
mSel notNil ifTrue:[ |
|
2311 |
"/ Transcript showCR:mSel. |
|
2312 |
mSel = aSelectorSymbol ifTrue:[ |
|
2313 |
^ true |
|
2314 |
] |
|
2315 |
]. |
|
2316 |
]. |
|
2317 |
walker decompile:self to:nil. |
|
2318 |
||
2319 |
"Created: / 9.11.1999 / 15:38:14 / cg" |
|
625 | 2320 |
"Modified: / 9.11.1999 / 17:06:03 / cg" |
618 | 2321 |
! |
2322 |
||
2151 | 2323 |
shouldBeSkippedInDebuggersWalkBack |
2324 |
||
2325 |
^false |
|
2326 |
||
2327 |
"Created: / 30-11-2010 / 15:35:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2328 |
! |
|
2329 |
||
18 | 2330 |
who |
2331 |
"return the class and selector of where I am defined in." |
|
2332 |
||
64 | 2333 |
|sel| |
18 | 2334 |
|
252 | 2335 |
javaClass isNil ifTrue:[^ nil]. |
378 | 2336 |
sel := selector. |
2337 |
"/ sel := javaClass methodDictionary keyAtValue:self ifAbsent:nil. |
|
64 | 2338 |
sel isNil ifTrue:[^ nil]. |
129 | 2339 |
^ Method::MethodWhoInfo class:javaClass selector:sel. |
378 | 2340 |
|
2341 |
"Modified: / 16.10.1998 / 13:42:10 / cg" |
|
5 | 2342 |
! ! |
2343 |
||
154 | 2344 |
!JavaMethod methodsFor:'signature parsing'! |
2345 |
||
255 | 2346 |
XXXspecWithArgsFromSignature:aSignature withName:name in:aPackage |
154 | 2347 |
"given a signature, return a spec with args" |
2348 |
||
2349 |
|s argSpec retvalSpec| |
|
2350 |
||
2351 |
s := aSignature readStream. |
|
2352 |
s next ~~ $( ifTrue:[self halt. ^ name]. |
|
2353 |
||
2354 |
argSpec := self argSpecWithArgsFromStream:s in:aPackage. |
|
2355 |
||
2356 |
s next ~~ $) ifTrue:[self halt. ^ name]. |
|
2357 |
||
2358 |
retvalSpec := self retvalSpecFromStream:s in:aPackage. |
|
2359 |
||
2360 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')' |
|
2361 |
||
2362 |
" |
|
2363 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo' |
|
2364 |
JavaMethod specFromSignature:'(BB)S' withName:'foo' |
|
2365 |
" |
|
2366 |
||
255 | 2367 |
"Created: / 8.1.1998 / 19:17:58 / cg" |
154 | 2368 |
! ! |
2369 |
||
2151 | 2370 |
!JavaMethod methodsFor:'testing'! |
2371 |
||
2372 |
isSynthetic |
|
2373 |
^false |
|
2374 |
||
2375 |
"Created: / 18-10-2010 / 19:09:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2376 |
! ! |
|
2377 |
||
129 | 2378 |
!JavaMethod class methodsFor:'documentation'! |
2 | 2379 |
|
2380 |
version |
|
2151 | 2381 |
^ '$Header: /cvs/stx/stx/libjava/JavaMethod.st,v 1.107 2011-08-18 18:42:48 vrany Exp $' |
2145 | 2382 |
! |
2383 |
||
2384 |
version_CVS |
|
2151 | 2385 |
^ '§Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaMethod.st,v 1.106 2009/10/09 14:04:17 cg Exp §' |
2386 |
! |
|
2387 |
||
2388 |
version_SVN |
|
2389 |
^ '$Id: JavaMethod.st,v 1.107 2011-08-18 18:42:48 vrany Exp $' |
|
2 | 2390 |
! ! |
2107 | 2391 |
|
2086 | 2392 |
JavaMethod initialize! |