JavaObject.st
changeset 415 b8abde6f5a0d
parent 407 568d64f6d7d6
child 419 679a4b82b3bb
equal deleted inserted replaced
414:0f33ff2c2fd3 415:b8abde6f5a0d
    97 	self instVarAt:i put:0
    97 	self instVarAt:i put:0
    98     ]
    98     ]
    99 ! !
    99 ! !
   100 
   100 
   101 !JavaObject methodsFor:'interpreter interface'!
   101 !JavaObject methodsFor:'interpreter interface'!
   102 
       
   103 invoke:selector interpreter:i sender:aContext
       
   104     "send a message, without args"
       
   105 
       
   106     |method cls sel|
       
   107 
       
   108     method := JavaClass lookupMethod:selector numArgs:0 in:self class static:false.
       
   109 "/    method := self lookupMethod:selector numArgs:0.
       
   110     method notNil ifTrue:[
       
   111         ^ method
       
   112             valueWithReceiver:self
       
   113             arguments:#()
       
   114             selector:selector 
       
   115             search:nil
       
   116             sender:nil
       
   117 
       
   118 "/        ^ self 
       
   119 "/            invokeJavaMethod:method 
       
   120 "/            interpreter:i 
       
   121 "/            sender:aContext
       
   122 "/            selector:selector
       
   123     ].
       
   124 
       
   125     ^ super doesNotUnderstand:(Message selector:selector)
       
   126 
       
   127     "
       
   128      |stack|
       
   129 
       
   130      stack := (Java at:'java/util/Stack') basicNew.
       
   131      stack invoke:#'<init>'. 
       
   132     "
       
   133     "
       
   134      |stack|
       
   135 
       
   136      stack := (Java at:'java/util/Stack') new.
       
   137      stack invoke:#isEmpty. 
       
   138     "
       
   139     "
       
   140      |stack|
       
   141 
       
   142      stack := (Java at:'java/util/Stack') new.
       
   143      stack invoke:#size. 
       
   144     "
       
   145 
       
   146     "Modified: / 7.1.1998 / 11:02:13 / cg"
       
   147 !
       
   148 
   102 
   149 invoke:selector interpreter:i sender:aContext with:argument
   103 invoke:selector interpreter:i sender:aContext with:argument
   150     "send a message, with 1 argument. 
   104     "send a message, with 1 argument. 
   151      TEMPORARY: This method needs more work."
   105      TEMPORARY: This method needs more work."
   152 
   106 
   228      stack invoke:#pop. 
   182      stack invoke:#pop. 
   229      stack invoke:#pop. 
   183      stack invoke:#pop. 
   230     "
   184     "
   231 
   185 
   232     "Modified: / 5.1.1998 / 02:21:22 / cg"
   186     "Modified: / 5.1.1998 / 02:21:22 / cg"
   233 !
       
   234 
       
   235 invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 
       
   236     "send a message, with 2 arguments. 
       
   237      TEMPORARY: This method needs more work."
       
   238 
       
   239     |sel method cls argClass jSel|
       
   240 
       
   241     sel := selector asSymbolIfInterned.
       
   242     sel notNil ifTrue:[
       
   243 	method := JavaClass lookupMethod:sel numArgs:2 in:self class static:false.
       
   244 	"/ method := self lookupMethod:sel numArgs:2.
       
   245 	method notNil ifTrue:[
       
   246 	    ^ method    
       
   247 		valueWithReceiver:self
       
   248 		arguments:(Array with:arg1 with:arg2)
       
   249 "/            ^ self 
       
   250 "/                invokeJavaMethod:method 
       
   251 "/                interpreter:i 
       
   252 "/                sender:aContext
       
   253 "/                selector:selector
       
   254 "/                with:arg1 with:arg2
       
   255 	].
       
   256     ].
       
   257 
       
   258     ^ super doesNotUnderstand:(Message selector:selector)
       
   259 
       
   260     "Modified: / 5.1.1998 / 02:28:34 / cg"
       
   261 !
       
   262 
       
   263 invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3
       
   264     "send a message, with 3 arguments. 
       
   265      TEMPORARY: This method needs more work."
       
   266 
       
   267     |sel method cls argClass jSel|
       
   268 
       
   269     sel := selector asSymbolIfInterned.
       
   270     sel notNil ifTrue:[
       
   271 	method := JavaClass lookupMethod:sel numArgs:3 in:self class static:false.
       
   272 	"/ method := self lookupMethod:sel numArgs:3.
       
   273 	method notNil ifTrue:[
       
   274 	    ^ self 
       
   275 		invokeJavaMethod:method 
       
   276 		interpreter:i 
       
   277 		sender:aContext 
       
   278 		selector:selector
       
   279 		with:arg1 with:arg2 with:arg3
       
   280 	].
       
   281     ].
       
   282 
       
   283     ^ super doesNotUnderstand:(Message selector:selector)
       
   284 
       
   285     "Modified: 17.8.1997 / 18:26:27 / cg"
       
   286 !
       
   287 
       
   288 invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4
       
   289     "send a message, with 4 arguments. 
       
   290      TEMPORARY: This method needs more work."
       
   291 
       
   292     |sel method cls argClass jSel|
       
   293 
       
   294     sel := selector asSymbolIfInterned.
       
   295     sel notNil ifTrue:[
       
   296 	method := JavaClass lookupMethod:sel numArgs:4 in:self class static:false.
       
   297 	"/ method := self lookupMethod:sel numArgs:4.
       
   298 	method notNil ifTrue:[
       
   299 	    ^ self 
       
   300 		invokeJavaMethod:method 
       
   301 		interpreter:i
       
   302 		sender:aContext 
       
   303 		selector:selector
       
   304 		with:arg1 with:arg2 with:arg3 with:arg4
       
   305 	].
       
   306     ].
       
   307 
       
   308     ^ super doesNotUnderstand:(Message selector:selector)
       
   309 
       
   310     "Modified: 17.8.1997 / 18:26:31 / cg"
       
   311 !
       
   312 
       
   313 invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
       
   314     "send a message, with 5 arguments. 
       
   315      TEMPORARY: This method needs more work."
       
   316 
       
   317     |sel method cls argClass jSel|
       
   318 
       
   319     sel := selector asSymbolIfInterned.
       
   320     sel notNil ifTrue:[
       
   321         method := JavaClass lookupMethod:sel numArgs:5 in:self class static:false.
       
   322         "/ method := self lookupMethod:sel numArgs:5.
       
   323         method notNil ifTrue:[
       
   324             ^ method    
       
   325                 valueWithReceiver:self
       
   326                 arguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5)
       
   327 "/            ^ self 
       
   328 "/                invokeJavaMethod:method 
       
   329 "/                interpreter:i 
       
   330 "/                sender:aContext 
       
   331 "/                selector:selector
       
   332 "/                with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
       
   333         ].
       
   334     ].
       
   335 
       
   336     ^ super doesNotUnderstand:(Message selector:selector)
       
   337 
       
   338     "Modified: / 6.1.1998 / 18:25:24 / cg"
       
   339 !
       
   340 
       
   341 invoke:selector interpreter:i sender:aContext with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
       
   342     "send a message, with 6 arguments. 
       
   343      TEMPORARY: This method needs more work."
       
   344 
       
   345     |sel method cls argClass jSel|
       
   346 
       
   347     sel := selector asSymbolIfInterned.
       
   348     sel notNil ifTrue:[
       
   349 	method := JavaClass lookupMethod:sel numArgs:6 in:self class static:false.
       
   350 	"/ method := self lookupMethod:sel numArgs:6.
       
   351 	method notNil ifTrue:[
       
   352 	    ^ self 
       
   353 		invokeJavaMethod:method 
       
   354 		interpreter:i 
       
   355 		sender:aContext 
       
   356 		selector:selector
       
   357 		with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
       
   358 	].
       
   359     ].
       
   360 
       
   361     ^ super doesNotUnderstand:(Message selector:selector)
       
   362 
       
   363     "Created: 7.8.1997 / 20:57:12 / cg"
       
   364     "Modified: 17.8.1997 / 18:26:39 / cg"
       
   365 !
       
   366 
       
   367 invoke:selector interpreter:i sender:aContext withAll:arguments
       
   368     "send a message, with arguments. 
       
   369      TEMPORARY: This method needs more work."
       
   370 
       
   371     |sel method cls argClass jSel|
       
   372 
       
   373     sel := selector asSymbolIfInterned.
       
   374     sel notNil ifTrue:[
       
   375 	method := JavaClass lookupMethod:sel numArgs:arguments size in:self class static:false.
       
   376 	"/ method := self lookupMethod:sel numArgs:arguments size.
       
   377 	method notNil ifTrue:[
       
   378 	    ^ self 
       
   379 		invokeJavaMethod:method 
       
   380 		interpreter:i 
       
   381 		sender:aContext 
       
   382 		selector:selector
       
   383 		withAll:arguments
       
   384 	].
       
   385     ].
       
   386 
       
   387     ^ super doesNotUnderstand:(Message selector:selector)
       
   388 
       
   389     "Modified: 17.8.1997 / 18:26:45 / cg"
       
   390 ! !
   187 ! !
   391 
   188 
   392 !JavaObject methodsFor:'message sending'!
   189 !JavaObject methodsFor:'message sending'!
   393 
   190 
   394 doesNotUnderstand:aMessage
   191 doesNotUnderstand:aMessage
       
   192     "as a courtesy to the smalltalker, try to map methods"
       
   193 
   395     |args numArgs javaMethod sel|
   194     |args numArgs javaMethod sel|
   396 
   195 
   397     args := aMessage arguments.
   196     args := aMessage arguments.
   398     numArgs := args size.
   197     numArgs := args size.
   399     sel := aMessage selector.
   198     sel := aMessage selector.
   410             search:nil
   209             search:nil
   411             sender:nil
   210             sender:nil
   412     ].
   211     ].
   413     ^ super doesNotUnderstand:aMessage
   212     ^ super doesNotUnderstand:aMessage
   414 
   213 
   415     "Modified: / 9.4.1998 / 21:41:13 / cg"
   214     "Modified: / 4.11.1998 / 17:10:43 / cg"
   416 !
   215 !
   417 
   216 
   418 invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel
   217 invokeJavaMethod:aJavaMethod interpreter:i sender:s selector:sel
   419     "invoke a java method, without arguments."
   218     "invoke a java method, without arguments."
   420 
   219 
   727 
   526 
   728     self class == (Java at:'java.lang.reflect.Method') ifTrue:[
   527     self class == (Java at:'java.lang.reflect.Method') ifTrue:[
   729         ^ super displayString , '(' , (JavaVM methodForJavaMethodObject:self) displayString , ')'
   528         ^ super displayString , '(' , (JavaVM methodForJavaMethodObject:self) displayString , ')'
   730     ].
   529     ].
   731 
   530 
       
   531 "/    Object errorSignal handle:[:ex |
       
   532 "/        ^ super displayString.
       
   533 "/    ] do:[
       
   534 "/        ^ Java as_ST_String:(self perform:#toString).
       
   535 "/    ].
       
   536 
   732     ^ super displayString.
   537     ^ super displayString.
   733 
   538 
   734     Object errorSignal handle:[:ex |
   539     "Modified: / 4.11.1998 / 18:35:00 / cg"
   735         ^ super displayString.
       
   736     ] do:[
       
   737         ^ Java as_ST_String:(self invoke:#toString).
       
   738     ].
       
   739 
       
   740     ^ super displayString. "/ ^ 'a JavaObject(' , self class name , ')'
       
   741 
       
   742     "Modified: / 21.10.1998 / 02:56:37 / cg"
       
   743 !
   540 !
   744 
   541 
   745 javaDisplayString
   542 javaDisplayString
   746     Object errorSignal handle:[:ex |
   543     Object errorSignal handle:[:ex |
   747 	ex return.
   544 	ex return.
   802     "
   599     "
   803 
   600 
   804     "Modified: / 7.1.1998 / 14:04:03 / cg"
   601     "Modified: / 7.1.1998 / 14:04:03 / cg"
   805 !
   602 !
   806 
   603 
   807 invoke:selector sender:aContext
       
   808     "send a message, without args"
       
   809 
       
   810     ^ self      
       
   811 	invoke:selector 
       
   812 	interpreter:(JavaInterpreter new) 
       
   813 	sender:aContext
       
   814 
       
   815     "Modified: 30.7.1997 / 13:59:18 / cg"
       
   816 !
       
   817 
       
   818 invoke:selector with:arg
   604 invoke:selector with:arg
   819     "send a message, with 1 argument. 
   605     "send a message, with 1 argument. 
   820      TEMPORARY: This method needs more work."
   606      TEMPORARY: This method needs more work."
   821 
   607 
   822     ^ self 
   608     ^ self 
   841      stack invoke:#pop. 
   627      stack invoke:#pop. 
   842      stack invoke:#pop. 
   628      stack invoke:#pop. 
   843     "
   629     "
   844 
   630 
   845     "Modified: 17.8.1997 / 18:07:39 / cg"
   631     "Modified: 17.8.1997 / 18:07:39 / cg"
   846 !
       
   847 
       
   848 invoke:selector with:arg1 with:arg2
       
   849     "send a message, with 2 argument. 
       
   850      TEMPORARY: This method needs more work."
       
   851 
       
   852     ^ self 
       
   853 	invoke:selector 
       
   854 	interpreter:(JavaInterpreter new) 
       
   855 	sender:thisContext sender 
       
   856 	with:arg1
       
   857 	with:arg2
       
   858 
       
   859     "Modified: 17.8.1997 / 18:07:45 / cg"
       
   860 !
       
   861 
       
   862 invoke:selector with:arg1 with:arg2 with:arg3
       
   863     "send a message, with 3 argument. 
       
   864      TEMPORARY: This method needs more work."
       
   865 
       
   866     ^ self 
       
   867 	invoke:selector 
       
   868 	interpreter:(JavaInterpreter new) 
       
   869 	sender:thisContext sender 
       
   870 	with:arg1
       
   871 	with:arg2
       
   872 	with:arg3
       
   873 
       
   874     "Created: 30.7.1997 / 13:48:24 / cg"
       
   875     "Modified: 17.8.1997 / 18:07:48 / cg"
       
   876 !
       
   877 
       
   878 invoke:selector with:arg1 with:arg2 with:arg3 with:arg4
       
   879     "send a message, with 5 argument. 
       
   880      TEMPORARY: This method needs more work."
       
   881 
       
   882     ^ self 
       
   883 	invoke:selector 
       
   884 	interpreter:(JavaInterpreter new) 
       
   885 	sender:thisContext sender 
       
   886 	with:arg1
       
   887 	with:arg2
       
   888 	with:arg3
       
   889 	with:arg4
       
   890 
       
   891     "Created: 6.8.1997 / 02:38:44 / cg"
       
   892     "Modified: 17.8.1997 / 18:07:52 / cg"
       
   893 !
       
   894 
       
   895 invoke:selector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5
       
   896     "send a message, with 5 argument. 
       
   897      TEMPORARY: This method needs more work."
       
   898 
       
   899     ^ self 
       
   900 	invoke:selector 
       
   901 	interpreter:(JavaInterpreter new) 
       
   902 	sender:thisContext sender 
       
   903 	with:arg1
       
   904 	with:arg2
       
   905 	with:arg3
       
   906 	with:arg4
       
   907 	with:arg5
       
   908 
       
   909     "Created: 3.8.1997 / 20:30:22 / cg"
       
   910     "Modified: 17.8.1997 / 18:07:55 / cg"
       
   911 !
       
   912 
       
   913 invoke:selector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6
       
   914     "send a message, with 6 argument. 
       
   915      TEMPORARY: This method needs more work."
       
   916 
       
   917     ^ self 
       
   918 	invoke:selector 
       
   919 	interpreter:(JavaInterpreter new) 
       
   920 	sender:thisContext sender 
       
   921 	with:arg1
       
   922 	with:arg2
       
   923 	with:arg3
       
   924 	with:arg4
       
   925 	with:arg5
       
   926 	with:arg6
       
   927 
       
   928     "Created: 7.8.1997 / 20:56:49 / cg"
       
   929     "Modified: 17.8.1997 / 18:07:58 / cg"
       
   930 !
       
   931 
       
   932 invoke:selector withAll:args
       
   933     "send a message, with anumber of arguments. 
       
   934      TEMPORARY: This method needs more work."
       
   935 
       
   936     ^ self 
       
   937 	invoke:selector 
       
   938 	interpreter:(JavaInterpreter new) 
       
   939 	sender:thisContext sender 
       
   940 	withAll:args
       
   941 
       
   942     "Created: 30.7.1997 / 13:56:33 / cg"
       
   943     "Modified: 17.8.1997 / 18:08:01 / cg"
       
   944 !
   632 !
   945 
   633 
   946 lookupMethod:selector numArgs:nargs
   634 lookupMethod:selector numArgs:nargs
   947     "lookup a method"
   635     "lookup a method"
   948 
   636 
   999 ! !
   687 ! !
  1000 
   688 
  1001 !JavaObject class methodsFor:'documentation'!
   689 !JavaObject class methodsFor:'documentation'!
  1002 
   690 
  1003 version
   691 version
  1004     ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaObject.st,v 1.39 1998/10/22 18:09:00 cg Exp $'
   692     ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaObject.st,v 1.40 1998/11/04 18:58:14 cg Exp $'
  1005 ! !
   693 ! !