JavaLookup.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Nov 2011 12:54:24 +0100
changeset 2290 cd61fd0b66ac
parent 2224 03ad71af7cf0
child 2293 d272dc6897a6
permissions -rw-r--r--
fixed: #version_SVN ($ to §)

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 Parts of the code written by Claus Gittinger are under following
 license:

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

 [1] Code written at SWING Research Group contain a signature
     of one of the above copright owners.
"
"{ Package: 'stx:libjava' }"

Lookup subclass:#JavaLookup
	instanceVariableNames:''
	classVariableNames:'Instance'
	poolDictionaries:''
	category:'Languages-Java-Lookup'
!

!JavaLookup class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 Parts of the code written by Claus Gittinger are under following
 license:

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

 [1] Code written at SWING Research Group contain a signature
     of one of the above copright owners.

"
! !

!JavaLookup class methodsFor:'instance creation'!

instance
    Instance ifNil: [
        Instance := self basicNew.
    ].
    ^ Instance.

    "Modified: / 25-02-2011 / 14:45:03 / kursjan <kursjan@fit.cvut.cz>"
!

new
    ^ self instance.

    "Created: / 25-02-2011 / 14:44:43 / kursjan <kursjan@fit.cvut.cz>"
! !

!JavaLookup methodsFor:'lookup'!

javaLookupMethodForSelector:selector for:receiver withArguments:argArrayOrNil
    "as a courtesy to the smalltalker, try to map methods"

    |args numArgs javaMethod sel m cls|

    args := argArrayOrNil.
    numArgs := args size.
    sel := selector.
    cls := receiver class.

    javaMethod := JavaClass lookupMethod:sel numArgs:numArgs in: cls static:false.

    javaMethod notNil ifTrue:[
        args notNil ifTrue:[
            args := JavaClass 
                        convertArgsToJava:args 
                        asSpecifiedIn:(javaMethod argSignature)
                        numArgs:numArgs.
        ].
        javaMethod isWrapped ifTrue:[
            m := javaMethod originalMethod
        ] ifFalse:[
            m := javaMethod
        ].
    ].
    ^ m.
"/        retVal := javaMethod 
"/            valueWithReceiver:self 
"/            arguments:args
"/            selector:m selector 
"/            search:m javaClass
"/            sender:nil.
"/
"/        ^ JavaClass convertToSmalltalk:retVal type:(m returnType).

    "Created: / 25-02-2011 / 19:49:22 / kursjan <kursjan@fit.cvut.cz>"
!

lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext

    "As a courtesy to a Smalltalker, try to map smalltalk selectors to a
     java ones."

    (selector includes: $() ifTrue:[
        "Probably a Java selector, so no fancy mapping here"
        ^super lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext
    ].

    "Created: / 21-02-2011 / 13:38:55 / kursjan <kursjan@fit.cvut.cz>"
    "Modified: / 11-04-2011 / 20:19:50 / kursjan <kursjan@fit.cvut.cz>"
    "Modified: / 16-08-2011 / 09:40:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

smalltalkLookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext
    ^ Lookup builtin lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext.

    "Created: / 25-02-2011 / 19:46:54 / kursjan <kursjan@fit.cvut.cz>"
! !

!JavaLookup class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/JavaLookup.st,v 1.2 2011-11-24 11:22:41 cg Exp $'
!

version_SVN
    ^ '§Id: JavaLookup.st,v 1.1 2011/08/18 19:06:53 vrany Exp §'
! !