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