src/JavaClass.st
branchjk_new_structure
changeset 1281 b46adbe75503
parent 1271 2caa288596fd
child 1286 c974ff108e7f
--- a/src/JavaClass.st	Wed Dec 14 20:59:31 2011 +0000
+++ b/src/JavaClass.st	Wed Dec 14 21:44:44 2011 +0000
@@ -1186,9 +1186,17 @@
 !JavaClass methodsFor:'fileOut'!
 
 basicFileOutDefinitionOn:aStream withNameSpace:nameSpaceBoolean
-    JavaDecompiler definitionOf:self on:aStream
-
-    "Modified: 22.3.1997 / 14:30:28 / cg"
+
+    | source |
+    source := self theNonMetaclass source.
+    source notNil ifTrue:[
+        aStream nextPutAll: source
+    ] ifFalse:[
+        JavaDecompiler definitionOf:self on:aStream
+    ]
+
+    "Modified: / 22-03-1997 / 14:30:28 / cg"
+    "Modified: / 14-12-2011 / 22:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 fileOut
@@ -1408,103 +1416,35 @@
 !JavaClass methodsFor:'message sending'!
 
 doesNotUnderstand:aMessage
-    "as a courtesy to the smalltalker, try to map static methods as
-     Smalltalk-class methods"
-
-    |r args numArgs methods javaMethod sel anyMethodsFound argType
-     argSignature newArgs oArgIdx nArgIdx canConvert
-     retVal|
-
+
+    | method  selector class args|
+    selector := aMessage selector.
     args := aMessage arguments.
-    numArgs := args size.
-    sel := aMessage selector.
-
-    methods := JavaClass lookupMethods:sel numArgs:numArgs in:self static:true.
-    methods size == 1 ifTrue:[
-	javaMethod := methods first.
-	"/ there is only one - try that one.
-    ] ifFalse:[
-	methods size > 1 ifTrue:[
-	    "/ more than one - select the ones that could be used.
-	    methods := methods select:[:aMethod |
-		|argSignature|
-
-		argSignature := aMethod argSignature.
-		(JavaClass canConvertArgsToJava:args asSpecifiedIn:argSignature)
-	    ].
-	    methods size == 1 ifTrue:[
-		javaMethod := methods first.
-	    ]
-	]
+    class := self class.
+
+    JavaLookup isNil ifTrue:[
+        (Smalltalk loadPackage: 'stx:libjava/experiments') ifFalse:[
+            self error: 'You should load package stx:libjava/experiments if you want some interop - still experimental' mayProceed: true.
+            ^nil                        
+        ]
     ].
 
-    javaMethod notNil ifTrue:[
-	(ArgumentConversionErrorSignal catch:[
-	    args notNil ifTrue:[
-		args := JavaClass
-			    convertArgsToJava:args
-			    asSpecifiedIn:(javaMethod argSignature)
-			    numArgs:numArgs.
-	    ].
-	]) ifFalse:[
-	    retVal := javaMethod
-			valueWithReceiver:self "/ (javaMethod javaClass)
-			arguments:args
-			selector:(javaMethod selector)
-			search:self "/ (javaMethod javaClass class)
-			sender:nil.
-	    ^ JavaClass convertToSmalltalk:retVal type:(javaMethod returnType).
-	].
-	^ MessageNotUnderstoodSignal
-		    raiseRequestWith:aMessage
-			 errorString:'no method for given argument(s)'
-				  in:thisContext "sender"
+    method := JavaLookup instance lookupMethodForSelector: selector
+            directedTo: class
+            for: self
+            withArguments: args
+            from: thisContext sender
+            ilc: nil.
+
+    method isNil ifTrue:[
+        ^super doesNotUnderstand:aMessage
+    ] ifFalse:[
+        ^ method valueWithReceiver: self arguments: args
     ].
 
-    anyMethodsFound := false.
-
-    "/ try all with that name (the number of args could be different ...
-
-    methods := JavaClass lookupMethods:sel numArgs:nil in:self static:true.
-    methods size > 0 ifTrue:[
-	anyMethodsFound := true.
-	numArgs > 0 ifTrue:[
-	    methods do:[:methodToTry |
-		(ArgumentConversionErrorSignal catch:[
-		    newArgs := JavaClass
-				convertArgsToJava:args
-				asSpecifiedIn:(methodToTry argSignature)
-				numArgs:methodToTry numArgs.
-		]) ifFalse:[
-		    retVal :=  methodToTry
-				    valueWithReceiver:self "/ (methodToTry javaClass)
-				    arguments:newArgs
-				    selector:(methodToTry selector)
-				    search:self "/ (methodToTry javaClass class)
-				    sender:nil.
-		    ^ JavaClass convertToSmalltalk:retVal type:(methodToTry returnType).
-		].
-	    ].
-	]
-    ].
-
-    anyMethodsFound ifTrue:[
-	methods size == 1 ifTrue:[
-	    javaMethod := methods first.
-
-	    ^ MessageNotUnderstoodSignal
-			raiseRequestWith:aMessage
-			     errorString:(sel , ' expects ' , javaMethod argSignature size printString , ' argument(s)')
-				      in:thisContext "sender"
-	].
-	^ MessageNotUnderstoodSignal
-		    raiseRequestWith:aMessage
-			 errorString:'no method for given argument count or type'
-				  in:thisContext "sender"
-    ].
-    ^ super doesNotUnderstand:aMessage
-
-    "Modified: / 6.11.1998 / 00:57:22 / cg"
+    "Modified: / 16-11-1998 / 16:50:56 / cg"
+    "Modified: / 19-09-2011 / 23:43:56 / Jan Kurs <kursjan@fit.cvut.cz>"
+    "Modified: / 10-12-2011 / 20:14:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 lookupMethodFor:selector
@@ -1976,11 +1916,12 @@
 selectMethodsAnnotatedWith:aJavaTypeName 
     ^ self methodDictionary values select:
             [:method | 
-            (method annotations 
-                ifNotNil:[ method annotations runtimeVisible at:aJavaTypeName ifAbsent:nil ]) 
-                    isNil not ]
+            (method isJavaMethod 
+                and:[method annotations notNil
+                    and:[(method annotations runtimeVisible at:aJavaTypeName ifAbsent:nil) notNil]])].
 
     "Created: / 02-03-2011 / 23:06:42 / Marcel Hlopko <hlopik@gmail.com>"
+    "Modified: / 14-12-2011 / 22:35:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 supportsMethodCategories