JavaMethodref.st
author cg
Tue, 09 Nov 1999 14:56:20 +0000
changeset 619 b4868e432de3
parent 454 38f590639d65
child 713 75e92ac63bf1
permissions -rw-r--r--
added #isJavaMethodRef query

"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

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



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

!JavaMethodref class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

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


! !

!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) in:nil.

    "Modified: / 8.1.1998 / 19:07:41 / 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:'queries'!

isJavaMethodRef
    ^ true

    "Created: / 9.11.1999 / 15:39:49 / cg"
! !

!JavaMethodref methodsFor:'resolving'!

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

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

method
    ^ self resolveMethod

    "Modified: / 9.11.1998 / 23:42:33 / 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"
!

resolveMethod
    |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: / 16.10.1998 / 00:22:59 / cg"
    "Created: / 9.11.1998 / 23:42:20 / cg"
! !

!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.35 1999/11/09 14:56:20 cg Exp $'
! !