JavaMethodref.st
author cg
Tue, 05 Aug 1997 15:28:43 +0000
changeset 198 5543d1079a4a
parent 180 b77168d0e07c
child 203 67af98594672
permissions -rw-r--r--
*** empty log message ***

JavaRef subclass:#JavaMethodref
	instanceVariableNames:'method sel lastClass lastMethod'
	classVariableNames:''
	poolDictionaries:''
	category:'Java-Reader-Support'
!


!JavaMethodref class methodsFor:'flushing'!

flushCaches
    self allInstancesDo:[:ref |
        ref flush
    ].

    "
     JavaMethodref flushCaches
    "

    "Modified: 20.3.1997 / 00:10:24 / cg"
! !

!JavaMethodref methodsFor:'accessing'!

argSignature
    ^ JavaMethod argSigArrayFromSignature:(self signature)

    "Created: 24.3.1997 / 12:22:50 / cg"
!

lastClass
    "return lastClass"

    ^ lastClass!

lastClass:something
    "set lastClass"

    lastClass := something.!

lastMethod
    "return lastMethod"

    ^ lastMethod!

lastMethod:something
    "set lastMethod"

    lastMethod := something.!

lastMethod:someMethod lastClass:someClass
    "set lastMethod & lastClass"

    lastMethod := someMethod.
    lastClass := someClass.

    "Created: 4.8.1997 / 18:21:11 / cg"
!

name
    ^ nameandType name.
!

returnType
    ^ JavaMethod returnTypeFromSignature:(self signature).

    "Modified: 24.3.1997 / 12:25:11 / cg"
!

selector
    sel isNil ifTrue:[
        sel := (nameandType name , nameandType signature) asSymbol.
    ].
    ^ sel
!

signature
    ^ nameandType signature.
! !

!JavaMethodref methodsFor:'printing & storing'!

displayString
    ^ 'JavaMethodRef (' , class displayString , ' ' 
                        , '''' , nameandType name , '''' , nameandType signature , ')'
! !

!JavaMethodref methodsFor:'resolving'!

flush
    method := nil.
    lastClass := nil.
    lastMethod := nil

    "Created: 20.3.1997 / 00:10:01 / cg"
!

method
    |nm sig mthd cls|

    method notNil ifTrue:[^ method].

    cls := class javaClass.
    cls ~~ class ifTrue:[
        class := cls.
    ].

"/    (class isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
"/        cls := class resolve.
"/        cls notNil ifTrue:[
"/            class := cls
"/        ]
"/    ].
"/    (class isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
"/        self halt:'unresolved class'.
"/    ].

    sel isNil ifTrue:[
        nm := nameandType name asSymbol.
        sig := nameandType signature.
        sel := (nm , sig) asSymbol.
    ].

"/ 'search in: ' print. class fullName print. ' for ' print. nm print. ' sig: ' print. sig printNL.

    mthd := class compiledMethodAt:sel.
    mthd isNil ifTrue:[
"/        self halt:'no method found for: ' , self displayString.
        ^ nil.
"/ old:        ^ self.
    ].
    mthd checkForNOOPMethod.
    ^ mthd

    "Modified: 31.7.1997 / 22:16:24 / cg"
!

methodFor:aClass
    |nm sig mthd cls|

    cls := aClass.

    cls == Array ifTrue:[
        cls := Java classNamed:'java.lang.Object'.
    ] ifFalse:[
        cls == UndefinedObject ifTrue:[
            cls := Java classNamed:'java.lang.Object'.
        ] ifFalse:[
            cls isBehavior ifTrue:[
                cls isMeta ifTrue:[
                    cls := cls soleInstance.
                ].
                (cls isKindOf:JavaClass) ifFalse:[
"/                    self halt:'not a javaClass'.
                    ^ nil
                ]
            ].
    "/        cls := cls javaClass.
        ].
    ].

    cls isUnresolved ifTrue:[
        self halt:'unresolved class'.
    ].

    sel isNil ifTrue:[
        nm := nameandType name asSymbol.
        sig := nameandType signature.
        sel := (nm , sig) asSymbol.
    ].

    [cls notNil] whileTrue:[
        mthd := cls compiledMethodAt:sel.
        mthd notNil ifTrue:[
            lastClass := aClass.
            lastMethod := mthd.
            ^ mthd
        ].

        cls := cls superclass
    ].

    ^ nil

    "Modified: 26.3.1997 / 13:32:39 / cg"
! !

!JavaMethodref class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaMethodref.st,v 1.26 1997/08/05 15:27:13 cg Exp $'
! !