WrappedMethod.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 29 Jan 2012 12:51:41 +0000
branchjv
changeset 3011 1997ff6e7e55
parent 2644 4d81c1be973d
child 3012 4f40b8304d54
permissions -rw-r--r--
trunk branched into /branches/jv

"
 COPYRIGHT (c) 1994 by Claus Gittinger
	      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.
"
"{ Package: 'stx:libbasic3' }"

Method variableSubclass:#WrappedMethod
	instanceVariableNames:''
	classVariableNames:'AllWrappedMethods'
	poolDictionaries:''
	category:'Kernel-Methods'
!

!WrappedMethod class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1994 by Claus Gittinger
	      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.
"
!

documentation
"
    support for MessageTracer

    notice: remembers wrappers in a weak classvar, because finding the wrapper for a
    method is required for single stepping, and used to take a long time when using allInstances.
    Therefore, wrappers are remembered.

    [author:]
        Claus Gittinger

    [see also:]
        MessageTracer
"
! !

!WrappedMethod class methodsFor:'registration'!

allInstancesDo:aBlock
    AllWrappedMethods notNil ifTrue:[
        AllWrappedMethods copy do:aBlock
    ].

    "Created: / 01-07-2011 / 09:45:29 / cg"
!

register:aWrappedMethod
    AllWrappedMethods isNil ifTrue:[
        AllWrappedMethods := WeakIdentitySet new.
    ].
    AllWrappedMethods add:aWrappedMethod

    "Created: / 01-07-2011 / 09:44:56 / cg"
!

unregister:aWrappedMethod
    AllWrappedMethods notNil ifTrue:[
        AllWrappedMethods remove:aWrappedMethod ifAbsent:[]
    ].

    "Created: / 01-07-2011 / 10:03:55 / cg"
! !

!WrappedMethod methodsFor:'accessing'!

annotations
    "return the wrapped methods annotations"

    ^ self originalMethod annotations

    "Created: / 04-12-2011 / 11:22:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

basicLiterals
    "return my literals"

    ^ super literals

    "Modified: 24.6.1996 / 14:10:34 / stefan"
!

category:newCategory
    super category:newCategory.
    self originalMethod category:newCategory
!

literals
    "return the wrapped methods literals"

    ^ self originalMethod literals
!

literalsDetect:aBlock ifNone:exceptionBlock
    "access the wrapped methods literals"

    ^ self originalMethod literalsDetect:aBlock ifNone:exceptionBlock

    "Created: / 23.1.1998 / 13:23:15 / stefan"
!

literalsDo:aBlock
    "access the wrapped methods literals"

    ^ self originalMethod literalsDo:aBlock

    "Created: / 23.1.1998 / 13:09:36 / stefan"
    "Modified: / 23.1.1998 / 13:22:38 / stefan"
!

methodArgAndVarNames
    "return the names of the args and locals of the wrapped method."

    ^ self originalMethod methodArgAndVarNames
!

methodVarNames
    "return the names of the locals of the wrapped method."

    ^ self originalMethod methodVarNames 
!

numVars
    "return the number of locals in the wrapped method."

    ^ self originalMethod numVars

    "Created: 4.11.1996 / 21:40:10 / cg"
!

originalMethod
    "return the method the receiver is wrapping"

    "a kludge: it must be in my literal array somewhere"
    super literalsDo:[:aLiteral |
        aLiteral isMethod ifTrue:[
            ^ aLiteral
        ]
    ].
    ^ nil

    "Modified: / 23.1.1998 / 13:08:25 / stefan"
!

originalMethodIfWrapped
    "return the method the receiver is wrapping"

    ^ self originalMethod

    "Created: / 22-10-2010 / 11:45:42 / cg"
!

package:aSymbol
    super package:aSymbol.
    self originalMethod package:aSymbol
!

privacy
    "return the wrapped methods privacy"

    ^ self originalMethod privacy

    "Created: / 23.1.1998 / 13:09:17 / stefan"
    "Modified: / 23.1.1998 / 13:20:59 / stefan"
!

privacy:aSymbol
    "set the wrapped methods privacy"

    ^ self originalMethod privacy:aSymbol
!

programmingLanguage
    ^ self originalMethod programmingLanguage
!

restricted:aBoolean
    ^ self originalMethod restricted:aBoolean
!

setPrivacy:aSymbol
    "set the wrapped methods privacy"

    ^ self originalMethod setPrivacy:aSymbol

    "Modified: / 23.1.1998 / 13:21:26 / stefan"
    "Created: / 23.1.1998 / 15:26:26 / stefan"
!

source
    "return the source of the method"

    ^ self originalMethod source
! !

!WrappedMethod methodsFor:'misc'!

register
    self class register:self

    "Created: / 01-07-2011 / 10:03:26 / cg"
!

unregister
    self class unregister:self

    "Created: / 01-07-2011 / 10:03:32 / cg"
! !

!WrappedMethod methodsFor:'private'!

annotationAtIndex: index

    "return annotation at given index.
     any raw annotation array is lazily
     initialized"

    ^self originalMethod annotationAtIndex: index

    "Created: / 16-12-2011 / 19:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

annotationIndexOf: key

    "Returns index of annotation with given key
     or nil if there is no such annotation"

    ^self originalMethod annotationIndexOf: key

    "Created: / 16-12-2011 / 19:53:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!WrappedMethod methodsFor:'queries'!

argSignature
    ^ self originalMethod argSignature

    "Created: / 27.1.1999 / 20:23:17 / cg"
!

hasResource
    "return the wrapped methods hasResource"

    ^ self originalMethod hasResource
!

isBreakpointed
    "return true, if the receiver is a wrapped method for a breakpoint.
     Ask the messageTracer, since I dont know if its a break or trace"

    ^ (MessageTracer isTrapped:self)

    "Created: 7.4.1997 / 17:25:40 / cg"
!

isTimed
    "return true, if the receiver is a wrapped method for a time measurement.
     Ask the messageTracer, since I dont know if its a break or trace"

    ^ (MessageTracer isTiming:self)

    "Created: 11.4.1997 / 17:06:14 / cg"
!

isTraced
    "return true, if the receiver is a wrapped method for a trace point.
     Ask the messageTracer, since I dont know if its a break or trace"

    ^ (MessageTracer isTrapped:self) not

    "Created: 7.4.1997 / 17:25:54 / cg"
!

isWrapped
    "return true, if the receiver is a wrapped method.
     True is returned here, since the receiver is always a wrapped one"

    ^ true
!

messagesSent
    "return a collection of message selectors sent by this method"

    ^ self originalMethod messagesSent 
!

messagesSentToSelf
    "return a collection of message selectors sent to self by this method"

    ^ self originalMethod messagesSentToSelf 
!

messagesSentToSuper
    "return a collection of message selectors sent to super by this method"

    ^ self originalMethod messagesSentToSuper 
!

resources
    "return the wrapped methods resources"

    ^ self originalMethod resources
!

signature
    ^ self originalMethod signature

    "Created: / 14.11.1998 / 00:01:50 / cg"
!

signatureNameWithoutReturnType
    ^ self originalMethod signatureNameWithoutReturnType

    "Created: / 27.1.1999 / 20:52:25 / cg"
! !

!WrappedMethod class methodsFor:'documentation'!

version_CVS
    ^ '§Header: /cvs/stx/stx/libbasic3/WrappedMethod.st,v 1.31 2011/12/19 08:38:46 vrany Exp §'
! !