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