JavaMethodref.st
author stefan
Fri, 29 Aug 1997 16:01:35 +0000
changeset 250 ea3955e7f791
parent 203 67af98594672
child 252 04b330744577
permissions -rw-r--r--
Cache methods and resolve special methods.

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
    "resolve the methodRef in its class.
     Used for invokenonvirtual and to get a method prototype
     for virtual invokes."

    |nm sig mthd cls|

    method notNil ifTrue:[^ method].

    "/ resolve the possibly unresolved class
    cls := class javaClass.
    cls ~~ class ifTrue:[
        class := cls.
    ].

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

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

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

    "Modified: 31.7.1997 / 22:16:24 / cg"
    "Modified: 28.8.1997 / 12:15:50 / stefan"
!

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"
!

specialMethod:classOfCurrentMethod
    "resolve a method for invokespecial"

    |mthd|

    mthd := self method.
    mthd isNil ifTrue:[
        ^ nil.
    ].
    (((mthd isPrivate not 
     and:[class useSpecialSuper]) 
     and:[mthd name ~~ #'<init>'])
     and:[classOfCurrentMethod isSubclassOf:class]) ifTrue:[
        |cls superMethod|
        cls := class.
        [superMethod isNil and:[(cls := cls superclass) notNil]] whileTrue:[
            superMethod := cls compiledMethodAt:sel.
        ].
        (superMethod notNil and:[superMethod isAbstract not]) ifTrue:[
            mthd := superMethod.
        ].
    ].
    ^ mthd

    "Modified: 28.8.1997 / 14:30:30 / stefan"
! !

!JavaMethodref methodsFor:'special'!

updateClassRefsFrom:oldClass to:newClass
    lastClass := nil.
    lastMethod := nil.
    super updateClassRefsFrom:oldClass to:newClass

    "Created: 7.8.1997 / 15:00:46 / cg"
! !

!JavaMethodref class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaMethodref.st,v 1.28 1997/08/29 16:01:35 stefan Exp $'
! !