261
|
1 |
'From Smalltalk/X, Version:3.3.1 on 15-jan-1998 at 7:53:24 pm' !
|
252
|
2 |
|
172
|
3 |
Class subclass:#JavaClass
|
261
|
4 |
instanceVariableNames:'constantPool interfaces accessFlags classLoader fullName
|
|
5 |
sourceFile binaryFilePath fields initValues staticFields'
|
252
|
6 |
classVariableNames:'InitialValuePerType A_OBSOLETE A_INTERFACE A_PUBLIC A_FINAL
|
|
7 |
A_ABSTRACT A_INITIALIZED'
|
1
|
8 |
poolDictionaries:''
|
|
9 |
category:'Java-Classes'
|
|
10 |
!
|
|
11 |
|
133
|
12 |
!JavaClass class methodsFor:'documentation'!
|
|
13 |
|
255
|
14 |
documentation
|
|
15 |
"
|
|
16 |
fields upTo-and-including accessFlags are known & used by the VM
|
|
17 |
only add fields after those and keep their order intact.
|
|
18 |
"
|
|
19 |
!
|
|
20 |
|
133
|
21 |
examples
|
|
22 |
"
|
|
23 |
(Java at:'java.util.Stack') new inspect
|
|
24 |
(Java at:'java.util.Vector') new inspect
|
|
25 |
"
|
|
26 |
! !
|
1
|
27 |
|
130
|
28 |
!JavaClass class methodsFor:'initialization'!
|
52
|
29 |
|
|
30 |
initialize
|
252
|
31 |
"/ those are defined in Java and read from the classFile
|
|
32 |
A_PUBLIC := 16r000001.
|
|
33 |
A_FINAL := 16r000010.
|
|
34 |
A_INTERFACE := 16r000200.
|
|
35 |
A_ABSTRACT := 16r000400.
|
|
36 |
A_OBSOLETE := 16r008000.
|
|
37 |
|
|
38 |
"/ those are local to the ST/X implementation
|
|
39 |
A_INITIALIZED := 16r100000.
|
|
40 |
|
52
|
41 |
InitialValuePerType := IdentityDictionary new.
|
|
42 |
InitialValuePerType at:$B put:0.
|
|
43 |
InitialValuePerType at:$C put:0.
|
|
44 |
InitialValuePerType at:$D put:0.0.
|
252
|
45 |
InitialValuePerType at:$F put:(0.0 asShortFloat).
|
52
|
46 |
InitialValuePerType at:$I put:0.
|
|
47 |
InitialValuePerType at:$J put:0.
|
|
48 |
InitialValuePerType at:$S put:0.
|
|
49 |
InitialValuePerType at:$Z put:0.
|
|
50 |
InitialValuePerType at:$L put:nil.
|
|
51 |
InitialValuePerType at:$[ put:nil.
|
|
52 |
|
|
53 |
"
|
|
54 |
JavaClass initialize
|
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
130
|
58 |
!JavaClass class methodsFor:'instance creation'!
|
1
|
59 |
|
7
|
60 |
fullName:aString
|
90
|
61 |
self shouldNotImplement.
|
|
62 |
^ self new flags:0; setFullName:aString
|
7
|
63 |
|
|
64 |
!
|
|
65 |
|
38
|
66 |
fullName:aString numStatic:nStatic
|
181
|
67 |
|meta cls fullName parts s ns|
|
38
|
68 |
|
130
|
69 |
"/ check for a JAVA nameSpace to exist
|
|
70 |
JAVA isNil ifTrue:[
|
255
|
71 |
Namespace name:'JAVA'
|
130
|
72 |
].
|
|
73 |
|
38
|
74 |
"create the metaclass first"
|
|
75 |
|
40
|
76 |
meta := Metaclass new.
|
|
77 |
meta setSuperclass:(self).
|
130
|
78 |
meta instSize:(JavaClass instSize + nStatic).
|
172
|
79 |
"/ meta setName:(aString , 'class') asSymbol.
|
|
80 |
"/ meta setClassVariableString:''.
|
252
|
81 |
meta flags:(meta flags bitOr:Behavior flagJavaClass).
|
|
82 |
"/ meta setSuperclass:JavaObject class.
|
38
|
83 |
|
|
84 |
"then let the new meta create the class"
|
|
85 |
cls := meta new.
|
|
86 |
cls setSuperclass:JavaObject.
|
|
87 |
cls instSize:0.
|
130
|
88 |
cls setName:('JAVA::' , aString).
|
38
|
89 |
cls flags:0.
|
40
|
90 |
"/ cls setClassVariableString:''.
|
38
|
91 |
cls setInstanceVariableString:''.
|
|
92 |
cls category:#java.
|
40
|
93 |
|
|
94 |
cls setFullName:aString.
|
130
|
95 |
|
181
|
96 |
"/ break up the package and create nameSpaces
|
|
97 |
"/ for each package component.
|
|
98 |
"/ This allows java.foo.bar to be visible in ST/X
|
|
99 |
"/ under the name JAVA::java::foo::bar
|
|
100 |
|
|
101 |
ns := JAVA.
|
|
102 |
|
|
103 |
parts := aString asCollectionOfSubstringsSeparatedBy:$/.
|
|
104 |
parts size > 1 ifTrue:[
|
255
|
105 |
s := '' writeStream.
|
|
106 |
s nextPutAll:'JAVA'.
|
|
107 |
parts from:1 to:(parts size - 1) do:[:aPart |
|
|
108 |
s nextPutAll:'::'.
|
|
109 |
s nextPutAll:aPart
|
|
110 |
].
|
|
111 |
Metaclass confirmationQuerySignal answer:false do:[
|
|
112 |
Class updateChangeFileQuerySignal answer:false do:[
|
|
113 |
ns := Namespace fullName:(s contents).
|
|
114 |
]
|
|
115 |
]
|
181
|
116 |
].
|
197
|
117 |
ns isNamespace ifTrue:[
|
255
|
118 |
ns at:parts last asSymbol put:cls.
|
197
|
119 |
].
|
181
|
120 |
|
|
121 |
"/ for ST/X browsing
|
130
|
122 |
Smalltalk at:('JAVA::' , aString) asSymbol put:cls.
|
|
123 |
|
38
|
124 |
^ cls
|
|
125 |
|
252
|
126 |
"Created: / 15.4.1996 / 15:52:55 / cg"
|
|
127 |
"Modified: / 3.1.1998 / 22:32:25 / cg"
|
38
|
128 |
!
|
|
129 |
|
1
|
130 |
name:aString
|
7
|
131 |
self shouldNotImplement
|
1
|
132 |
|
|
133 |
"Created: 15.4.1996 / 15:52:55 / cg"
|
|
134 |
! !
|
|
135 |
|
229
|
136 |
!JavaClass class methodsFor:'method lookup'!
|
|
137 |
|
236
|
138 |
lookupMethod:selector numArgs:nargs in:aClass static:staticMethod
|
229
|
139 |
"lookup a method"
|
|
140 |
|
|
141 |
|method cls sel|
|
|
142 |
|
|
143 |
sel := selector.
|
|
144 |
(sel includes:$:) ifTrue:[
|
252
|
145 |
sel := sel copyTo:(sel indexOf:$:)-1
|
229
|
146 |
].
|
|
147 |
|
|
148 |
sel := sel asSymbolIfInterned.
|
|
149 |
sel notNil ifTrue:[
|
252
|
150 |
cls := aClass.
|
229
|
151 |
|
252
|
152 |
[cls notNil
|
|
153 |
and:[cls ~~ JavaObject
|
|
154 |
and:[cls ~~ JavaClass]]] whileTrue:[
|
|
155 |
cls methodDictionary keysAndValuesDo:[:jSel :aMethod |
|
|
156 |
((jSel == sel)
|
|
157 |
or:[aMethod name = sel
|
|
158 |
or:[aMethod signatureNameWithoutReturnType = sel]])
|
|
159 |
ifTrue:[
|
|
160 |
aMethod numArgs == nargs ifTrue:[
|
|
161 |
staticMethod ifTrue:[
|
|
162 |
aMethod isStatic ifTrue:[
|
|
163 |
^ aMethod
|
|
164 |
]
|
|
165 |
] ifFalse:[
|
|
166 |
aMethod isStatic ifFalse:[
|
|
167 |
^ aMethod
|
|
168 |
]
|
|
169 |
]
|
|
170 |
]
|
|
171 |
]
|
|
172 |
].
|
229
|
173 |
|
252
|
174 |
cls := cls superclass.
|
|
175 |
].
|
229
|
176 |
].
|
|
177 |
self halt.
|
|
178 |
^ nil
|
|
179 |
|
|
180 |
"Created: 17.8.1997 / 18:25:47 / cg"
|
|
181 |
"Modified: 17.8.1997 / 18:31:57 / cg"
|
|
182 |
! !
|
|
183 |
|
130
|
184 |
!JavaClass class methodsFor:'signature parsing'!
|
52
|
185 |
|
|
186 |
initialValueFromSignature:aSignature
|
|
187 |
"given a signature, return an initializer value"
|
|
188 |
|
|
189 |
|s|
|
|
190 |
|
|
191 |
s := aSignature readStream.
|
|
192 |
^ self initialValueFromStream:s.
|
|
193 |
|
|
194 |
"
|
|
195 |
JavaClass initialValueFromSignature:'LObject;'
|
|
196 |
JavaClass initialValueFromSignature:'B'
|
|
197 |
JavaClass initialValueFromSignature:'I'
|
|
198 |
"
|
|
199 |
|
|
200 |
|
|
201 |
!
|
|
202 |
|
|
203 |
initialValueFromStream:s
|
|
204 |
"parse a fieldTypeSpec - see java doc"
|
|
205 |
|
|
206 |
|typeChar|
|
|
207 |
|
|
208 |
typeChar := s next.
|
|
209 |
^ InitialValuePerType at:typeChar ifAbsent:nil.
|
|
210 |
! !
|
|
211 |
|
130
|
212 |
!JavaClass class methodsFor:'special'!
|
40
|
213 |
|
|
214 |
setInstanceVariableStringFromFields:f in:aClass
|
|
215 |
|varNames|
|
|
216 |
|
|
217 |
varNames := ''.
|
|
218 |
f do:[:aField |
|
172
|
219 |
varNames := varNames , aField name , ' '
|
40
|
220 |
].
|
|
221 |
aClass setInstanceVariableString:varNames.
|
|
222 |
|
|
223 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
224 |
! !
|
|
225 |
|
5
|
226 |
!JavaClass methodsFor:'accessing'!
|
|
227 |
|
74
|
228 |
binaryFile
|
|
229 |
^ binaryFilePath
|
|
230 |
!
|
|
231 |
|
7
|
232 |
category
|
|
233 |
"java classes do not really hav a category;
|
|
234 |
simulate one by separating its name into individual components,
|
|
235 |
prepending 'java'"
|
|
236 |
|
|
237 |
|nameComponents|
|
|
238 |
|
|
239 |
nameComponents := fullName asCollectionOfSubstringsSeparatedBy:$/.
|
160
|
240 |
nameComponents size <= 1 ifTrue:[
|
252
|
241 |
^ 'java' "/ fullName
|
160
|
242 |
].
|
252
|
243 |
^ ((nameComponents asStringWith:$/ from:1 to:(nameComponents size - 1)))
|
|
244 |
replaceAll:$/ with:$.
|
160
|
245 |
|
175
|
246 |
"Modified: 30.7.1997 / 15:35:22 / cg"
|
7
|
247 |
!
|
|
248 |
|
255
|
249 |
classLoader
|
|
250 |
^ classLoader
|
|
251 |
!
|
|
252 |
|
|
253 |
classLoader:aJavaClassLoaderOrNil
|
|
254 |
classLoader := aJavaClassLoaderOrNil
|
|
255 |
!
|
|
256 |
|
185
|
257 |
compiledMethodAt:name signature:sig
|
|
258 |
"lookup the classes methodDictionary"
|
|
259 |
|
|
260 |
methodDictionary keysAndValuesDo:[:mFullSelector :aMethod |
|
252
|
261 |
aMethod name == name ifTrue:[
|
|
262 |
aMethod signature == sig ifTrue:[
|
|
263 |
^ aMethod
|
|
264 |
]
|
|
265 |
]
|
185
|
266 |
].
|
|
267 |
^ nil
|
|
268 |
|
|
269 |
"Created: 1.8.1997 / 00:01:58 / cg"
|
|
270 |
!
|
|
271 |
|
5
|
272 |
constantPool
|
|
273 |
^ constantPool
|
7
|
274 |
!
|
|
275 |
|
83
|
276 |
fields
|
|
277 |
^ fields
|
|
278 |
!
|
|
279 |
|
7
|
280 |
fullName
|
|
281 |
^ fullName
|
8
|
282 |
!
|
|
283 |
|
110
|
284 |
interfaces
|
|
285 |
interfaces notNil ifTrue:[
|
172
|
286 |
interfaces := interfaces collect:[:clsRef |
|
|
287 |
clsRef isUnresolved ifTrue:[
|
|
288 |
clsRef preResolve
|
|
289 |
] ifFalse:[
|
|
290 |
clsRef
|
|
291 |
]
|
|
292 |
].
|
110
|
293 |
].
|
|
294 |
^ interfaces
|
|
295 |
!
|
|
296 |
|
90
|
297 |
javaClass
|
|
298 |
^ self
|
|
299 |
!
|
|
300 |
|
8
|
301 |
name
|
27
|
302 |
^ name "/ fullName
|
22
|
303 |
!
|
|
304 |
|
130
|
305 |
nameSpace
|
|
306 |
^ JAVA
|
|
307 |
|
|
308 |
"Created: 20.1.1997 / 13:04:30 / cg"
|
|
309 |
!
|
|
310 |
|
|
311 |
nameWithoutNameSpacePrefix
|
|
312 |
^ fullName
|
|
313 |
|
|
314 |
"Created: 20.1.1997 / 13:05:30 / cg"
|
|
315 |
!
|
|
316 |
|
|
317 |
nameWithoutPrefix
|
|
318 |
^ fullName
|
|
319 |
|
|
320 |
"Created: 20.1.1997 / 13:06:06 / cg"
|
|
321 |
!
|
|
322 |
|
22
|
323 |
package
|
|
324 |
"extract from the fullName"
|
|
325 |
|
|
326 |
|components|
|
|
327 |
|
|
328 |
components := fullName asCollectionOfSubstringsSeparatedBy:$/.
|
24
|
329 |
components size > 1 ifTrue:[
|
172
|
330 |
^ (components copyWithoutLast:1) asStringWith:$/
|
24
|
331 |
].
|
|
332 |
^ fullName
|
22
|
333 |
|
|
334 |
"
|
|
335 |
Java allClasses first fullName
|
|
336 |
Java allClasses first package
|
|
337 |
"
|
24
|
338 |
!
|
|
339 |
|
76
|
340 |
source
|
|
341 |
^ Java classSourceOf:self
|
|
342 |
|
|
343 |
"
|
|
344 |
(Java at:'java.awt.Frame') source
|
175
|
345 |
(Java at:'ArcTest') source
|
|
346 |
(Java at:'ArcCanvas') source
|
76
|
347 |
"
|
175
|
348 |
|
|
349 |
"Modified: 30.7.1997 / 14:31:01 / cg"
|
76
|
350 |
!
|
|
351 |
|
24
|
352 |
sourceFile
|
|
353 |
^ sourceFile
|
83
|
354 |
!
|
|
355 |
|
|
356 |
staticFields
|
|
357 |
^ staticFields
|
132
|
358 |
!
|
|
359 |
|
|
360 |
typeOfField:aFieldName
|
|
361 |
|
|
362 |
fields do:[:aField |
|
172
|
363 |
aField name = aFieldName ifTrue:[
|
|
364 |
^ aField type
|
|
365 |
]
|
132
|
366 |
].
|
|
367 |
self error:'no such field'
|
|
368 |
|
|
369 |
"
|
|
370 |
(JAVA at:#'java/awt/image/ColorModel') typeOfField:'pixel_bits'
|
|
371 |
"
|
|
372 |
|
|
373 |
"Modified: 21.1.1997 / 22:48:28 / cg"
|
5
|
374 |
! !
|
|
375 |
|
213
|
376 |
!JavaClass methodsFor:'adding / removing'!
|
|
377 |
|
|
378 |
removeFromSystem
|
|
379 |
Java removeClass:self
|
|
380 |
|
|
381 |
"Created: 12.8.1997 / 02:46:51 / cg"
|
|
382 |
! !
|
|
383 |
|
261
|
384 |
!JavaClass methodsFor:'browser interface'!
|
|
385 |
|
|
386 |
isVisualStartable
|
|
387 |
"return true, if this is an application class,
|
|
388 |
which can be started via #open"
|
|
389 |
|
|
390 |
^ (self compiledMethodAt:#'main([Ljava/lang/String;)V') notNil
|
|
391 |
|
|
392 |
"Modified: / 15.1.1998 / 17:20:00 / cg"
|
|
393 |
!
|
|
394 |
|
|
395 |
open
|
|
396 |
"start a thread for my main method"
|
|
397 |
|
|
398 |
Java executeMainOf:self
|
|
399 |
|
|
400 |
"Created: / 15.1.1998 / 17:18:30 / cg"
|
|
401 |
"Modified: / 15.1.1998 / 17:18:59 / cg"
|
|
402 |
! !
|
|
403 |
|
183
|
404 |
!JavaClass methodsFor:'compiler interface'!
|
|
405 |
|
|
406 |
compilerClass
|
|
407 |
"return the compiler to use for this class -
|
|
408 |
this can be redefined in special classes, to get classes with
|
|
409 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax."
|
|
410 |
|
197
|
411 |
^ Compiler.
|
|
412 |
|
183
|
413 |
^ JavaCompiler
|
|
414 |
|
|
415 |
"Created: 31.7.1997 / 23:03:37 / cg"
|
197
|
416 |
"Modified: 4.8.1997 / 16:50:08 / cg"
|
183
|
417 |
!
|
|
418 |
|
|
419 |
evaluatorClass
|
|
420 |
"return the compiler to use for expression evaluation for this class -
|
|
421 |
this can be redefined in special classes, to get classes with
|
|
422 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax."
|
|
423 |
|
197
|
424 |
^ Compiler.
|
|
425 |
|
183
|
426 |
^ JavaCompiler
|
|
427 |
|
|
428 |
"Created: 31.7.1997 / 23:03:56 / cg"
|
197
|
429 |
"Modified: 4.8.1997 / 16:49:14 / cg"
|
183
|
430 |
!
|
|
431 |
|
|
432 |
parserClass
|
|
433 |
"return the parser to use for parsing this class -
|
|
434 |
this can be redefined in special classes, to get classes with
|
|
435 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax."
|
|
436 |
|
197
|
437 |
^ Compiler.
|
|
438 |
|
183
|
439 |
^ JavaCompiler
|
|
440 |
|
|
441 |
"Created: 31.7.1997 / 23:04:11 / cg"
|
197
|
442 |
"Modified: 4.8.1997 / 16:50:18 / cg"
|
183
|
443 |
! !
|
|
444 |
|
160
|
445 |
!JavaClass methodsFor:'documentation support'!
|
|
446 |
|
|
447 |
htmlDocumentation
|
|
448 |
^ nil "/ replace by access to javadoc-generated documentation later
|
|
449 |
|
|
450 |
"Modified: 22.3.1997 / 14:18:50 / cg"
|
|
451 |
! !
|
|
452 |
|
130
|
453 |
!JavaClass methodsFor:'fileOut'!
|
|
454 |
|
160
|
455 |
basicFileOutDefinitionOn:aStream withNameSpace:nameSpaceBoolean
|
|
456 |
JavaDecompiler definitionOf:self on:aStream
|
|
457 |
|
|
458 |
"Modified: 22.3.1997 / 14:30:28 / cg"
|
|
459 |
!
|
130
|
460 |
|
160
|
461 |
fileOut
|
|
462 |
self warn:'fileOut not yet supported'
|
|
463 |
|
|
464 |
"Modified: 22.3.1997 / 14:30:28 / cg"
|
|
465 |
"Created: 22.3.1997 / 14:35:43 / cg"
|
130
|
466 |
! !
|
|
467 |
|
43
|
468 |
!JavaClass methodsFor:'java initialization'!
|
|
469 |
|
|
470 |
classInit
|
|
471 |
"call the classes JAVA clinit function"
|
|
472 |
|
63
|
473 |
|m|
|
43
|
474 |
|
252
|
475 |
(accessFlags bitAnd:A_INITIALIZED) ~~ 0 ifTrue:[^ self].
|
|
476 |
|
|
477 |
accessFlags := accessFlags bitOr:A_INITIALIZED.
|
|
478 |
|
|
479 |
superclass ~~ JavaObject ifTrue:[
|
261
|
480 |
superclass classInit
|
252
|
481 |
].
|
|
482 |
"/ "/ also, all referenced classes must be ...
|
|
483 |
"/ constantPool classReferencesDo:[:aClass |
|
|
484 |
"/ aClass classInit
|
|
485 |
"/ ].
|
43
|
486 |
|
63
|
487 |
m := self compiledMethodAt:#'<clinit>()V'.
|
|
488 |
m notNil ifTrue:[
|
90
|
489 |
"/ 'calling clinit() of ' print. self fullName printNL.
|
261
|
490 |
[
|
|
491 |
m valueWithReceiver:self arguments:#()
|
|
492 |
] valueOnUnwindDo:[
|
|
493 |
accessFlags := accessFlags bitXor:A_INITIALIZED.
|
|
494 |
]
|
43
|
495 |
] ifFalse:[
|
71
|
496 |
"/ self fullName print. ' has no clinit()' printNL.
|
43
|
497 |
].
|
|
498 |
|
|
499 |
"
|
261
|
500 |
JavaVM instructionTrace:true.
|
|
501 |
JavaVM callTrace:true.
|
43
|
502 |
|
|
503 |
(Java classNamed:'java.lang.String') classInit
|
|
504 |
(Java classNamed:'java.lang.System') classInit
|
|
505 |
|
|
506 |
(Java classNamed:'java/io/FileDescriptor') classInit
|
|
507 |
(Java classNamed:'java.util.Properties') classInit
|
|
508 |
"
|
175
|
509 |
|
261
|
510 |
"Modified: / 13.1.1998 / 14:43:11 / cg"
|
195
|
511 |
!
|
|
512 |
|
60
|
513 |
initializeStaticFields
|
90
|
514 |
staticFields isNil ifTrue:[^ self].
|
|
515 |
|
60
|
516 |
staticFields do:[:f |
|
172
|
517 |
|val type|
|
86
|
518 |
|
172
|
519 |
(val := f constantValue) isNil ifTrue:[
|
|
520 |
"/ careful: int/long etc. constants must be initialized
|
|
521 |
"/ with correct type.
|
|
522 |
type := f type.
|
|
523 |
type == #long ifTrue:[
|
|
524 |
val := 0.
|
|
525 |
] ifFalse:[type == #int ifTrue:[
|
|
526 |
val := 0.
|
|
527 |
] ifFalse:[type == #float ifTrue:[
|
|
528 |
val := 0.0 asShortFloat
|
|
529 |
] ifFalse:[type == #double ifTrue:[
|
|
530 |
val := 0.0
|
|
531 |
] ifFalse:[type == #byte ifTrue:[
|
|
532 |
val := 0.
|
|
533 |
] ifFalse:[type == #char ifTrue:[
|
|
534 |
val := 0.
|
|
535 |
] ifFalse:[type == #'unsigned short' ifTrue:[
|
|
536 |
val := 0.
|
|
537 |
] ifFalse:[type == #boolean ifTrue:[
|
|
538 |
val := 0.
|
|
539 |
]]]]]]]].
|
|
540 |
].
|
|
541 |
self instVarNamed:(f name) put:val.
|
60
|
542 |
].
|
43
|
543 |
! !
|
|
544 |
|
|
545 |
!JavaClass methodsFor:'java instance creation'!
|
29
|
546 |
|
52
|
547 |
initValueFor:instVarName
|
|
548 |
|idx field|
|
|
549 |
|
|
550 |
idx := fields findFirst:[:field | field name = instVarName].
|
|
551 |
idx == 0 ifTrue:[
|
172
|
552 |
superclass ~~ JavaObject ifTrue:[
|
|
553 |
^ superclass initValueFor:instVarName
|
|
554 |
].
|
|
555 |
self halt
|
52
|
556 |
] ifFalse:[
|
172
|
557 |
field := fields at:idx.
|
|
558 |
^ field initialValue
|
52
|
559 |
].
|
|
560 |
!
|
|
561 |
|
|
562 |
new
|
255
|
563 |
"create a new instance, preset its fields,
|
|
564 |
and call its JAVA init function"
|
52
|
565 |
|
255
|
566 |
|newJavaObject sz "{ Class: SmallInteger }"|
|
52
|
567 |
|
261
|
568 |
"/ (self isInterface or:[self isAbstract]) ifTrue:[
|
|
569 |
(accessFlags bitAnd:(A_INTERFACE bitOr:A_ABSTRACT)) ~~ 0 ifTrue:[
|
|
570 |
JavaVM throwInstantiationExceptionFor:self.
|
|
571 |
^ nil
|
|
572 |
].
|
|
573 |
|
255
|
574 |
newJavaObject := super basicNew.
|
|
575 |
initValues notNil ifTrue:[
|
|
576 |
"/ newJavaObject initializeFields:initValues
|
|
577 |
sz := self instSize.
|
|
578 |
1 to:sz do:[:i |
|
|
579 |
newJavaObject instVarAt:i put:(initValues at:i)
|
|
580 |
].
|
|
581 |
].
|
|
582 |
|
252
|
583 |
newJavaObject perform:#'<init>()V'.
|
52
|
584 |
^ newJavaObject
|
|
585 |
|
|
586 |
"
|
|
587 |
(Java classNamed:'java.lang.String') basicNew inspect
|
|
588 |
(Java classNamed:'java.lang.String') new inspect
|
|
589 |
"
|
|
590 |
|
261
|
591 |
"Modified: / 14.1.1998 / 23:16:19 / cg"
|
52
|
592 |
!
|
|
593 |
|
|
594 |
newCleared
|
148
|
595 |
"create a new cleared JAVA instance.
|
|
596 |
Its instVars are cleared to the corresponding typed values;
|
|
597 |
however, <init> is not invoked for it."
|
43
|
598 |
|
255
|
599 |
|newJavaObject sz "{ Class: SmallInteger }" |
|
29
|
600 |
|
261
|
601 |
"/ (self isInterface or:[self isAbstract]) ifTrue:[
|
|
602 |
(accessFlags bitAnd:(A_INTERFACE bitOr:A_ABSTRACT)) ~~ 0 ifTrue:[
|
|
603 |
JavaVM throwInstantiationExceptionFor:self.
|
|
604 |
^ nil
|
|
605 |
].
|
255
|
606 |
|
261
|
607 |
newJavaObject := super basicNew.
|
|
608 |
initValues notNil ifTrue:[
|
|
609 |
"/ newJavaObject initializeFields:initValues
|
|
610 |
sz := self instSize.
|
|
611 |
1 to:sz do:[:i |
|
|
612 |
newJavaObject instVarAt:i put:(initValues at:i)
|
|
613 |
].
|
|
614 |
].
|
255
|
615 |
|
29
|
616 |
^ newJavaObject
|
43
|
617 |
|
|
618 |
"
|
|
619 |
(Java classNamed:'java.lang.String') basicNew inspect
|
53
|
620 |
(Java classNamed:'java.lang.String') newCleared inspect
|
43
|
621 |
(Java classNamed:'java.lang.String') new inspect
|
|
622 |
"
|
148
|
623 |
|
261
|
624 |
"Modified: / 14.1.1998 / 23:16:26 / cg"
|
148
|
625 |
!
|
|
626 |
|
|
627 |
newFromInterpreter:anInterpreter sender:aJavaContext
|
|
628 |
"create a new instance, and call its JAVA init function.
|
|
629 |
This is done in the context of an already running interpreter."
|
|
630 |
|
|
631 |
|newJavaObject|
|
|
632 |
|
|
633 |
newJavaObject := self newCleared.
|
|
634 |
newJavaObject invoke:#'<init>' interpreter:anInterpreter sender:aJavaContext.
|
|
635 |
^ newJavaObject
|
|
636 |
|
|
637 |
"Created: 18.3.1997 / 17:33:07 / cg"
|
43
|
638 |
! !
|
|
639 |
|
229
|
640 |
!JavaClass methodsFor:'message sending'!
|
43
|
641 |
|
229
|
642 |
invokeJavaMethod:aJavaMethod interpreter:i sender:aContext selector:sel
|
|
643 |
"invoke a static java method, without argument"
|
79
|
644 |
|
229
|
645 |
|val|
|
79
|
646 |
|
|
647 |
aJavaMethod numArgs ~~ 0 ifTrue:[
|
252
|
648 |
self halt:'argument count'
|
79
|
649 |
].
|
|
650 |
aJavaMethod isStatic ifFalse:[
|
252
|
651 |
self halt:'non-static function'
|
79
|
652 |
].
|
|
653 |
|
|
654 |
val := i interpret:aJavaMethod sender:aContext.
|
|
655 |
|
|
656 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
657 |
|
229
|
658 |
"Created: 17.8.1997 / 18:05:14 / cg"
|
|
659 |
"Modified: 17.8.1997 / 18:08:22 / cg"
|
79
|
660 |
!
|
|
661 |
|
229
|
662 |
invokeJavaMethod:aJavaMethod interpreter:i sender:aContext selector:sel with:arg1
|
|
663 |
"invoke a static java method, with 1 argument"
|
175
|
664 |
|
229
|
665 |
|val|
|
43
|
666 |
|
175
|
667 |
aJavaMethod numArgs ~~ 1 ifTrue:[
|
252
|
668 |
self halt:'argument count'
|
175
|
669 |
].
|
|
670 |
aJavaMethod isStatic ifFalse:[
|
252
|
671 |
self halt:'non-static function'
|
175
|
672 |
].
|
43
|
673 |
|
175
|
674 |
i push:arg1.
|
|
675 |
val := i interpret:aJavaMethod sender:aContext.
|
|
676 |
|
|
677 |
^ JavaObject convertJavaObject:val signature:(aJavaMethod retValSignature)
|
|
678 |
|
229
|
679 |
"Created: 17.8.1997 / 18:03:58 / cg"
|
|
680 |
"Modified: 17.8.1997 / 18:08:27 / cg"
|
43
|
681 |
!
|
|
682 |
|
229
|
683 |
invokeJavaMethod:aJavaMethod sender:aContext selector:sel
|
|
684 |
"invoke a static java method, without arguments"
|
79
|
685 |
|
229
|
686 |
^ self
|
252
|
687 |
invokeJavaMethod:aJavaMethod
|
|
688 |
interpreter:(JavaInterpreter new)
|
|
689 |
sender:aContext
|
|
690 |
selector:sel
|
229
|
691 |
|
|
692 |
"Modified: 17.8.1997 / 18:05:35 / cg"
|
|
693 |
!
|
79
|
694 |
|
229
|
695 |
invokeJavaMethod:aJavaMethod sender:aContext selector:sel with:arg1
|
|
696 |
"invoke a static java method, with 1 argument"
|
79
|
697 |
|
229
|
698 |
^ self
|
252
|
699 |
invokeJavaMethod:aJavaMethod
|
|
700 |
interpreter:(JavaInterpreter new)
|
|
701 |
sender:aContext
|
|
702 |
selector:sel
|
|
703 |
with:arg1
|
79
|
704 |
|
229
|
705 |
"Modified: 17.8.1997 / 18:04:44 / cg"
|
79
|
706 |
!
|
|
707 |
|
200
|
708 |
invokeStatic:selector
|
|
709 |
"send a static message, without args."
|
|
710 |
|
|
711 |
|method cls sel|
|
|
712 |
|
|
713 |
sel := selector asSymbolIfInterned.
|
|
714 |
sel notNil ifTrue:[
|
261
|
715 |
cls := self.
|
|
716 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
717 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
200
|
718 |
|
|
719 |
"/ aMethod name printNL.
|
|
720 |
|
261
|
721 |
aMethod isStatic ifTrue:[
|
|
722 |
sel == selector ifTrue:[
|
|
723 |
^ aMethod valueWithReceiver:self arguments:#()
|
|
724 |
]
|
|
725 |
]
|
|
726 |
].
|
|
727 |
cls := cls superclass.
|
|
728 |
].
|
200
|
729 |
].
|
|
730 |
|
|
731 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
732 |
|
261
|
733 |
"Created: / 5.8.1997 / 14:35:34 / cg"
|
|
734 |
"Modified: / 15.1.1998 / 00:31:27 / cg"
|
200
|
735 |
!
|
|
736 |
|
43
|
737 |
lookupMethodFor:selector
|
|
738 |
|method cls sel|
|
|
739 |
|
|
740 |
sel := selector asSymbolIfInterned.
|
|
741 |
sel notNil ifTrue:[
|
172
|
742 |
cls := self.
|
|
743 |
[cls notNil] whileTrue:[
|
|
744 |
method := cls compiledMethodAt:sel.
|
|
745 |
method notNil ifTrue:[ ^ method ].
|
|
746 |
cls := cls superclass.
|
|
747 |
].
|
43
|
748 |
].
|
|
749 |
|
|
750 |
^ nil
|
29
|
751 |
! !
|
|
752 |
|
160
|
753 |
!JavaClass methodsFor:'printOut'!
|
|
754 |
|
|
755 |
printNameInHierarchy
|
|
756 |
"return my name as printed in the hierarchy"
|
|
757 |
|
|
758 |
^ self displayString
|
|
759 |
|
|
760 |
"Modified: 22.3.1997 / 14:16:55 / cg"
|
|
761 |
!
|
|
762 |
|
|
763 |
printOutOn:aStream
|
|
764 |
self warn:'printOut not yet supported'
|
|
765 |
|
|
766 |
"Created: 22.3.1997 / 14:36:12 / cg"
|
|
767 |
!
|
|
768 |
|
|
769 |
printOutProtocolOn:aStream
|
|
770 |
self warn:'printOut not yet supported'
|
|
771 |
|
|
772 |
"Created: 22.3.1997 / 14:36:28 / cg"
|
|
773 |
! !
|
|
774 |
|
1
|
775 |
!JavaClass methodsFor:'printing & storing'!
|
|
776 |
|
|
777 |
displayString
|
252
|
778 |
^ (fullName copyFrom:1) replaceAll:$/ with:$.
|
125
|
779 |
|
41
|
780 |
"/ ^ 'JAVA-' , name .
|
|
781 |
"/ ^ name , '(Java)' "/ 'JavaClass(' , name , ')'
|
1
|
782 |
|
|
783 |
"Created: 15.4.1996 / 16:02:48 / cg"
|
125
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
1
|
788 |
! !
|
|
789 |
|
|
790 |
!JavaClass methodsFor:'private accessing'!
|
|
791 |
|
5
|
792 |
addMethod:m name:name signature:signature
|
63
|
793 |
|sel|
|
|
794 |
|
|
795 |
sel := (name , signature) asSymbol.
|
|
796 |
self addSelector:sel withMethod:m.
|
|
797 |
^ self.
|
|
798 |
|
98
|
799 |
"/ selectorArray isNil ifTrue:[
|
|
800 |
"/ selectorArray := #().
|
|
801 |
"/ methodArray := #()
|
|
802 |
"/ ].
|
|
803 |
"/ selectorArray := selectorArray copyWith:(name , signature) asSymbol. "/ name.
|
|
804 |
"/"/ selectorArray := selectorArray copyWith:name asSymbol. "/ name.
|
|
805 |
"/ methodArray := methodArray copyWith:m
|
5
|
806 |
|
|
807 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
98
|
808 |
|
|
809 |
|
5
|
810 |
!
|
|
811 |
|
130
|
812 |
addSelector:newSelector withMethod:newMethod
|
|
813 |
"redefined to not flush smalltalk caches and send NO smalltalk-class
|
|
814 |
change notification. Will eventually flush Java caches."
|
|
815 |
|
|
816 |
|nargs oldMethod|
|
|
817 |
|
|
818 |
oldMethod := self compiledMethodAt:newSelector.
|
|
819 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false].
|
|
820 |
|
|
821 |
^ true
|
|
822 |
|
|
823 |
"Created: 20.1.1997 / 13:00:48 / cg"
|
|
824 |
!
|
|
825 |
|
204
|
826 |
makeObsolete
|
252
|
827 |
accessFlags := accessFlags bitOr:A_OBSOLETE
|
204
|
828 |
|
|
829 |
"Created: 7.8.1997 / 19:04:48 / cg"
|
|
830 |
!
|
|
831 |
|
43
|
832 |
markUninitialized
|
252
|
833 |
(accessFlags bitAnd:A_INITIALIZED) ~~ 0 ifTrue:[
|
|
834 |
accessFlags := accessFlags bitXor:A_INITIALIZED
|
|
835 |
].
|
43
|
836 |
!
|
|
837 |
|
1
|
838 |
setAccessFlags:flags
|
3
|
839 |
accessFlags := flags.
|
1
|
840 |
|
|
841 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
5
|
842 |
!
|
|
843 |
|
73
|
844 |
setBinaryFilePath:aPathName
|
|
845 |
binaryFilePath := aPathName
|
|
846 |
!
|
|
847 |
|
5
|
848 |
setConstantPool:anArray
|
|
849 |
constantPool := anArray.
|
|
850 |
|
|
851 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
852 |
!
|
|
853 |
|
27
|
854 |
setFields:f
|
54
|
855 |
JavaClass setInstanceVariableStringFromFields:f in:self.
|
|
856 |
|
|
857 |
instSize := superclass instSize + f size.
|
|
858 |
|
52
|
859 |
fields := f.
|
|
860 |
initValues := self allInstVarNames collect:[:nm |
|
172
|
861 |
self initValueFor:nm
|
52
|
862 |
].
|
76
|
863 |
initValues isEmpty ifTrue:[
|
172
|
864 |
initValues := nil
|
76
|
865 |
].
|
27
|
866 |
|
|
867 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
52
|
868 |
|
|
869 |
|
27
|
870 |
!
|
|
871 |
|
7
|
872 |
setFullName:aString
|
|
873 |
|nameComponents|
|
|
874 |
|
125
|
875 |
fullName := aString asSymbol.
|
7
|
876 |
nameComponents := aString asCollectionOfSubstringsSeparatedBy:$/.
|
125
|
877 |
name := nameComponents last asSymbol
|
7
|
878 |
|
|
879 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
|
880 |
!
|
|
881 |
|
110
|
882 |
setInterfaces:i
|
|
883 |
i size > 0 ifTrue:[
|
172
|
884 |
interfaces := i
|
168
|
885 |
] ifFalse:[
|
172
|
886 |
interfaces := nil
|
110
|
887 |
]
|
|
888 |
|
168
|
889 |
"Modified: 7.4.1997 / 15:44:53 / cg"
|
110
|
890 |
!
|
|
891 |
|
5
|
892 |
setSourceFile:aFilename
|
|
893 |
sourceFile := aFilename.
|
|
894 |
|
|
895 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
27
|
896 |
!
|
|
897 |
|
60
|
898 |
setStaticFields:f
|
|
899 |
JavaClass setInstanceVariableStringFromFields:f in:self class.
|
|
900 |
|
|
901 |
staticFields := f.
|
|
902 |
|
|
903 |
|
|
904 |
!
|
|
905 |
|
27
|
906 |
setSuperclass:aClass
|
247
|
907 |
|iVars numIvars|
|
|
908 |
|
27
|
909 |
aClass isNil ifTrue:[
|
252
|
910 |
super setSuperclass:JavaObject
|
29
|
911 |
] ifFalse:[
|
252
|
912 |
(aClass isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
913 |
self halt.
|
|
914 |
].
|
|
915 |
super setSuperclass:aClass.
|
27
|
916 |
].
|
29
|
917 |
|
247
|
918 |
iVars := self instVarNames.
|
|
919 |
((numIvars := iVars size) > 0) ifTrue:[
|
252
|
920 |
(superclass notNil and:[(superclass isMemberOf:JavaUnresolvedClassConstant) not]) ifTrue:[
|
|
921 |
instSize := superclass instSize + numIvars
|
|
922 |
] ifFalse:[
|
|
923 |
instSize := numIvars
|
|
924 |
]
|
29
|
925 |
].
|
27
|
926 |
|
|
927 |
"Created: 15.4.1996 / 16:42:52 / cg"
|
247
|
928 |
"Modified: 22.8.1997 / 15:06:45 / cg"
|
1
|
929 |
! !
|
|
930 |
|
18
|
931 |
!JavaClass methodsFor:'queries'!
|
|
932 |
|
42
|
933 |
browserClass
|
|
934 |
"return the browser to use for this class -
|
|
935 |
this can be redefined in special classes, to get different browsers"
|
|
936 |
|
|
937 |
^ JavaBrowser
|
|
938 |
!
|
|
939 |
|
53
|
940 |
hasInterface:aJavaInterface
|
111
|
941 |
interfaces size > 0 ifTrue:[
|
172
|
942 |
self interfaces do:[:if |
|
|
943 |
aJavaInterface == if ifTrue:[
|
|
944 |
^ true
|
|
945 |
].
|
|
946 |
]
|
111
|
947 |
].
|
|
948 |
"/ ^ false.
|
|
949 |
|
69
|
950 |
aJavaInterface methodDictionary keysAndValuesDo:[:sel :mthd |
|
172
|
951 |
(self canUnderstand:sel) ifFalse:[
|
|
952 |
self halt.
|
|
953 |
^ false.
|
|
954 |
]
|
53
|
955 |
].
|
|
956 |
^ true
|
52
|
957 |
!
|
|
958 |
|
83
|
959 |
isAbstract
|
252
|
960 |
^ (accessFlags bitAnd:A_ABSTRACT) ~~ 0
|
83
|
961 |
!
|
|
962 |
|
27
|
963 |
isClass
|
|
964 |
^ true
|
|
965 |
!
|
|
966 |
|
18
|
967 |
isFinal
|
252
|
968 |
^ (accessFlags bitAnd:A_FINAL) ~~ 0
|
18
|
969 |
!
|
|
970 |
|
43
|
971 |
isInitialized
|
252
|
972 |
^ (accessFlags bitAnd:A_INITIALIZED) ~~ 0
|
43
|
973 |
!
|
|
974 |
|
18
|
975 |
isInterface
|
252
|
976 |
^ (accessFlags bitAnd:A_INTERFACE) ~~ 0
|
18
|
977 |
!
|
|
978 |
|
148
|
979 |
isJavaClass
|
|
980 |
^ self ~~ JavaClass
|
|
981 |
|
|
982 |
"Created: 18.3.1997 / 17:48:01 / cg"
|
|
983 |
!
|
|
984 |
|
71
|
985 |
isObsolete
|
|
986 |
"return true, if the receiver is obsolete
|
|
987 |
Java classes are never."
|
|
988 |
|
252
|
989 |
^ (accessFlags bitAnd:A_OBSOLETE) ~~ 0.
|
71
|
990 |
|
204
|
991 |
"Modified: 7.8.1997 / 19:04:28 / cg"
|
71
|
992 |
!
|
|
993 |
|
18
|
994 |
isPublic
|
252
|
995 |
^ (accessFlags bitAnd:A_PUBLIC) ~~ 0
|
90
|
996 |
!
|
21
|
997 |
|
90
|
998 |
isUnresolved
|
|
999 |
^ false
|
175
|
1000 |
!
|
|
1001 |
|
|
1002 |
supportsMethodCategories
|
|
1003 |
^ self == JavaClass
|
|
1004 |
|
|
1005 |
"Created: 30.7.1997 / 14:58:58 / cg"
|
21
|
1006 |
! !
|
|
1007 |
|
43
|
1008 |
!JavaClass methodsFor:'smalltalk interface'!
|
|
1009 |
|
|
1010 |
invoke:selector
|
175
|
1011 |
"send a message, without args."
|
43
|
1012 |
|
|
1013 |
|method cls sel|
|
|
1014 |
|
|
1015 |
sel := selector asSymbolIfInterned.
|
|
1016 |
sel notNil ifTrue:[
|
252
|
1017 |
cls := self.
|
|
1018 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1019 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
69
|
1020 |
|
43
|
1021 |
"/ aMethod name printNL.
|
175
|
1022 |
|
252
|
1023 |
(aMethod name == selector
|
|
1024 |
or:[aMethod signatureNameWithoutReturnType = selector]) ifTrue:[
|
|
1025 |
aMethod numArgs == 0 ifTrue:[
|
255
|
1026 |
^ aMethod
|
|
1027 |
valueWithReceiver:self
|
|
1028 |
arguments:#()
|
|
1029 |
"/ ^ self
|
|
1030 |
"/ invokeJavaMethod:aMethod
|
|
1031 |
"/ sender:thisContext
|
|
1032 |
"/ selector:selector
|
252
|
1033 |
]
|
|
1034 |
]
|
|
1035 |
].
|
|
1036 |
cls := cls superclass.
|
|
1037 |
].
|
175
|
1038 |
].
|
|
1039 |
|
|
1040 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1041 |
|
|
1042 |
"
|
|
1043 |
|stack|
|
|
1044 |
|
|
1045 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1046 |
stack invoke:#'<init>'.
|
|
1047 |
"
|
|
1048 |
"
|
|
1049 |
|stack|
|
|
1050 |
|
|
1051 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1052 |
stack invoke:#isEmpty.
|
|
1053 |
"
|
|
1054 |
"
|
|
1055 |
|stack|
|
|
1056 |
|
|
1057 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1058 |
stack invoke:#size.
|
|
1059 |
"
|
|
1060 |
|
255
|
1061 |
"Created: / 30.7.1997 / 14:06:50 / cg"
|
|
1062 |
"Modified: / 6.1.1998 / 18:21:34 / cg"
|
175
|
1063 |
!
|
|
1064 |
|
229
|
1065 |
invoke:selector interpreter:i sender:aContext
|
|
1066 |
"send a message, without args"
|
|
1067 |
|
|
1068 |
|method cls sel|
|
|
1069 |
|
|
1070 |
method := JavaClass lookupMethod:selector numArgs:0 in:self static:true.
|
|
1071 |
method notNil ifTrue:[
|
252
|
1072 |
^ self
|
|
1073 |
invokeJavaMethod:method
|
|
1074 |
interpreter:i
|
|
1075 |
sender:aContext
|
|
1076 |
selector:selector
|
229
|
1077 |
].
|
|
1078 |
|
|
1079 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
1080 |
|
|
1081 |
"Created: 17.8.1997 / 18:10:08 / cg"
|
|
1082 |
"Modified: 17.8.1997 / 18:33:59 / cg"
|
|
1083 |
!
|
|
1084 |
|
|
1085 |
invoke:selector interpreter:i sender:aContext with:arg
|
|
1086 |
"send a message, with 1 arg"
|
|
1087 |
|
|
1088 |
|method cls sel|
|
|
1089 |
|
|
1090 |
method := JavaClass lookupMethod:selector numArgs:1 in:self static:true.
|
|
1091 |
method notNil ifTrue:[
|
252
|
1092 |
^ self
|
|
1093 |
invokeJavaMethod:method
|
|
1094 |
interpreter:i
|
|
1095 |
sender:aContext
|
|
1096 |
selector:selector
|
|
1097 |
with:arg
|
229
|
1098 |
].
|
|
1099 |
|
|
1100 |
^ super doesNotUnderstand:(Message selector:selector)
|
|
1101 |
|
|
1102 |
"Created: 17.8.1997 / 18:10:32 / cg"
|
|
1103 |
"Modified: 17.8.1997 / 18:33:52 / cg"
|
|
1104 |
!
|
|
1105 |
|
175
|
1106 |
invoke:selector signature:signature
|
|
1107 |
"send a message, without args."
|
|
1108 |
|
|
1109 |
|method cls sel sig|
|
|
1110 |
|
|
1111 |
sel := selector asSymbolIfInterned.
|
|
1112 |
sel notNil ifTrue:[
|
252
|
1113 |
sig := signature asSymbolIfInterned.
|
|
1114 |
sig notNil ifTrue:[
|
|
1115 |
cls := self.
|
|
1116 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1117 |
method := cls compiledMethodAt:sel signature:signature.
|
|
1118 |
method notNil ifTrue:[
|
|
1119 |
^ self
|
|
1120 |
invokeJavaMethod:method
|
|
1121 |
sender:thisContext
|
|
1122 |
selector:sel
|
|
1123 |
].
|
|
1124 |
cls := cls superclass.
|
|
1125 |
].
|
|
1126 |
].
|
43
|
1127 |
].
|
|
1128 |
|
|
1129 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1130 |
|
|
1131 |
"
|
|
1132 |
|stack|
|
|
1133 |
|
|
1134 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1135 |
stack invoke:#'<init>'.
|
|
1136 |
"
|
|
1137 |
"
|
|
1138 |
|stack|
|
|
1139 |
|
|
1140 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1141 |
stack invoke:#isEmpty.
|
|
1142 |
"
|
|
1143 |
"
|
|
1144 |
|stack|
|
|
1145 |
|
|
1146 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1147 |
stack invoke:#size.
|
|
1148 |
"
|
|
1149 |
|
175
|
1150 |
"Created: 30.7.1997 / 14:12:29 / cg"
|
185
|
1151 |
"Modified: 1.8.1997 / 00:04:45 / cg"
|
175
|
1152 |
!
|
43
|
1153 |
|
175
|
1154 |
invoke:selector signature:signature with:arg
|
|
1155 |
"send a message, with 1 arg1."
|
|
1156 |
|
|
1157 |
|method cls sel sig|
|
|
1158 |
|
|
1159 |
sel := selector asSymbolIfInterned.
|
|
1160 |
sel notNil ifTrue:[
|
255
|
1161 |
sig := signature asSymbolIfInterned.
|
|
1162 |
sig notNil ifTrue:[
|
|
1163 |
cls := self.
|
|
1164 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1165 |
method := cls compiledMethodAt:sel signature:signature.
|
|
1166 |
method notNil ifTrue:[
|
|
1167 |
^ method
|
|
1168 |
valueWithReceiver:self
|
|
1169 |
arguments:(Array with:arg)
|
252
|
1170 |
"/ ^ self
|
|
1171 |
"/ invokeJavaMethod:method
|
|
1172 |
"/ sender:thisContext
|
|
1173 |
"/ selector:sel
|
|
1174 |
"/ with:arg
|
255
|
1175 |
].
|
|
1176 |
cls := cls superclass.
|
|
1177 |
].
|
|
1178 |
].
|
175
|
1179 |
].
|
|
1180 |
|
|
1181 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1182 |
|
|
1183 |
"
|
|
1184 |
|stack|
|
|
1185 |
|
|
1186 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1187 |
stack invoke:#'<init>'.
|
|
1188 |
"
|
|
1189 |
"
|
|
1190 |
|stack|
|
|
1191 |
|
|
1192 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1193 |
stack invoke:#isEmpty.
|
|
1194 |
"
|
|
1195 |
"
|
|
1196 |
|stack|
|
|
1197 |
|
|
1198 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1199 |
stack invoke:#size.
|
|
1200 |
"
|
|
1201 |
|
252
|
1202 |
"Created: / 30.7.1997 / 14:13:30 / cg"
|
|
1203 |
"Modified: / 4.1.1998 / 16:32:45 / cg"
|
113
|
1204 |
!
|
|
1205 |
|
|
1206 |
invoke:selector with:arg
|
175
|
1207 |
"send a message, with one arg"
|
|
1208 |
|
|
1209 |
|method cls sel|
|
|
1210 |
|
|
1211 |
sel := selector asSymbolIfInterned.
|
|
1212 |
sel notNil ifTrue:[
|
255
|
1213 |
cls := self.
|
|
1214 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1215 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
175
|
1216 |
|
|
1217 |
"/ aMethod name printNL.
|
255
|
1218 |
(sel == selector
|
|
1219 |
or:[aMethod name == selector
|
|
1220 |
or:[aMethod signatureNameWithoutReturnType = selector]]) ifTrue:[
|
|
1221 |
aMethod numArgs == 1 ifTrue:[
|
|
1222 |
^ aMethod
|
|
1223 |
valueWithReceiver:self
|
|
1224 |
arguments:(Array with:arg)
|
|
1225 |
"/ ^ self
|
|
1226 |
"/ invokeJavaMethod:aMethod
|
|
1227 |
"/ sender:thisContext
|
|
1228 |
"/ selector:selector
|
|
1229 |
"/ with:arg
|
|
1230 |
]
|
|
1231 |
]
|
|
1232 |
].
|
|
1233 |
cls := cls superclass.
|
|
1234 |
].
|
175
|
1235 |
].
|
|
1236 |
|
|
1237 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1238 |
|
255
|
1239 |
"Modified: / 6.1.1998 / 21:04:04 / cg"
|
175
|
1240 |
!
|
|
1241 |
|
|
1242 |
invoke:selector with:arg1 with:arg2
|
|
1243 |
"send a message, with two args"
|
113
|
1244 |
|
|
1245 |
|method cls sel|
|
|
1246 |
|
|
1247 |
sel := selector asSymbolIfInterned.
|
|
1248 |
sel notNil ifTrue:[
|
252
|
1249 |
cls := self.
|
|
1250 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1251 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
113
|
1252 |
|
|
1253 |
"/ aMethod name printNL.
|
252
|
1254 |
(aMethod name == selector
|
|
1255 |
or:[aMethod signatureNameWithoutReturnType = selector]) ifTrue:[
|
|
1256 |
aMethod numArgs == 2 ifTrue:[
|
|
1257 |
^ self
|
|
1258 |
invokeJavaMethod:aMethod
|
|
1259 |
sender:thisContext
|
|
1260 |
selector:selector
|
|
1261 |
with:arg1
|
|
1262 |
with:arg2
|
|
1263 |
]
|
|
1264 |
]
|
|
1265 |
].
|
|
1266 |
cls := cls superclass.
|
|
1267 |
].
|
113
|
1268 |
].
|
|
1269 |
|
|
1270 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1271 |
|
175
|
1272 |
"Modified: 30.7.1997 / 13:39:15 / cg"
|
|
1273 |
"Created: 30.7.1997 / 14:00:09 / cg"
|
|
1274 |
!
|
|
1275 |
|
|
1276 |
invoke:selector withAll:args
|
|
1277 |
"send a message, with a number of args"
|
|
1278 |
|
|
1279 |
|method cls sel numArgGiven|
|
|
1280 |
|
|
1281 |
numArgGiven := args size.
|
|
1282 |
|
|
1283 |
sel := selector asSymbolIfInterned.
|
|
1284 |
sel notNil ifTrue:[
|
252
|
1285 |
cls := self.
|
|
1286 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1287 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
175
|
1288 |
|
|
1289 |
"/ aMethod name printNL.
|
252
|
1290 |
(aMethod name == selector
|
|
1291 |
or:[aMethod signatureNameWithoutReturnType = selector]) ifTrue:[
|
|
1292 |
aMethod numArgs == numArgGiven ifTrue:[
|
|
1293 |
^ self
|
|
1294 |
invokeJavaMethod:aMethod
|
|
1295 |
sender:thisContext
|
|
1296 |
selector:selector
|
|
1297 |
withAll:args
|
|
1298 |
]
|
|
1299 |
]
|
|
1300 |
].
|
|
1301 |
cls := cls superclass.
|
|
1302 |
].
|
175
|
1303 |
].
|
|
1304 |
|
|
1305 |
^ self doesNotUnderstand:(Message selector:selector)
|
|
1306 |
|
|
1307 |
"Modified: 30.7.1997 / 13:39:15 / cg"
|
|
1308 |
"Created: 30.7.1997 / 14:00:53 / cg"
|
|
1309 |
!
|
|
1310 |
|
|
1311 |
invokeSignature:signature
|
|
1312 |
"send a message, without args."
|
|
1313 |
|
|
1314 |
|method cls sel|
|
|
1315 |
|
|
1316 |
sel := signature asSymbolIfInterned.
|
|
1317 |
sel notNil ifTrue:[
|
252
|
1318 |
cls := self.
|
|
1319 |
[cls notNil and:[cls ~~ JavaObject]] whileTrue:[
|
|
1320 |
cls methodDictionary keysAndValuesDo:[:sel :aMethod |
|
175
|
1321 |
|
|
1322 |
"/ aMethod name printNL.
|
|
1323 |
|
252
|
1324 |
aMethod signatureName = signature ifTrue:[
|
|
1325 |
aMethod numArgs == 0 ifTrue:[
|
|
1326 |
^ self
|
|
1327 |
invokeJavaMethod:aMethod
|
|
1328 |
sender:thisContext
|
|
1329 |
selector:signature
|
|
1330 |
]
|
|
1331 |
]
|
|
1332 |
].
|
|
1333 |
cls := cls superclass.
|
|
1334 |
].
|
175
|
1335 |
].
|
|
1336 |
|
|
1337 |
^ self doesNotUnderstand:(Message selector:signature)
|
|
1338 |
|
|
1339 |
"
|
|
1340 |
|stack|
|
|
1341 |
|
|
1342 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1343 |
stack invoke:#'<init>'.
|
|
1344 |
"
|
|
1345 |
"
|
|
1346 |
|stack|
|
|
1347 |
|
|
1348 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1349 |
stack invoke:#isEmpty.
|
|
1350 |
"
|
|
1351 |
"
|
|
1352 |
|stack|
|
|
1353 |
|
|
1354 |
stack := (Java at:'java/util/Stack') basicNew.
|
|
1355 |
stack invoke:#size.
|
|
1356 |
"
|
|
1357 |
|
|
1358 |
"Modified: 30.7.1997 / 14:07:55 / cg"
|
|
1359 |
"Created: 30.7.1997 / 14:09:31 / cg"
|
133
|
1360 |
!
|
|
1361 |
|
|
1362 |
methodMatching:aSmalltalkSelector
|
|
1363 |
|numArgs cls|
|
|
1364 |
|
|
1365 |
numArgs := aSmalltalkSelector numArgs.
|
|
1366 |
cls := self.
|
|
1367 |
[cls notNil] whileTrue:[
|
172
|
1368 |
methodDictionary keysAndValuesDo:[:jSelector :aMethod |
|
|
1369 |
aMethod numArgs == numArgs ifTrue:[
|
|
1370 |
aMethod name = aSmalltalkSelector ifTrue:[
|
|
1371 |
^ aMethod
|
|
1372 |
]
|
|
1373 |
]
|
|
1374 |
].
|
|
1375 |
cls := cls superclass
|
133
|
1376 |
].
|
|
1377 |
^ nil
|
|
1378 |
|
|
1379 |
"Modified: 1.2.1997 / 21:57:36 / cg"
|
|
1380 |
"Created: 1.2.1997 / 21:57:53 / cg"
|
43
|
1381 |
! !
|
|
1382 |
|
203
|
1383 |
!JavaClass methodsFor:'special'!
|
|
1384 |
|
|
1385 |
updateClassRefsFrom:oldClass to:newClass
|
204
|
1386 |
self == oldClass ifTrue:[
|
252
|
1387 |
self makeObsolete.
|
|
1388 |
^ self
|
204
|
1389 |
].
|
|
1390 |
|
203
|
1391 |
constantPool updateClassRefsFrom:oldClass to:newClass.
|
|
1392 |
interfaces notNil ifTrue:[
|
252
|
1393 |
interfaces := interfaces collect:[:anInterface |
|
|
1394 |
anInterface == oldClass ifTrue:[
|
|
1395 |
newClass
|
|
1396 |
] ifFalse:[
|
|
1397 |
anInterface
|
|
1398 |
]
|
|
1399 |
]
|
203
|
1400 |
]
|
|
1401 |
|
204
|
1402 |
"Modified: 8.8.1997 / 12:19:14 / cg"
|
203
|
1403 |
! !
|
|
1404 |
|
130
|
1405 |
!JavaClass class methodsFor:'documentation'!
|
1
|
1406 |
|
|
1407 |
version
|
261
|
1408 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClass.st,v 1.68 1998/01/16 16:11:12 cg Exp $'
|
1
|
1409 |
! !
|
52
|
1410 |
JavaClass initialize!
|