JavaRef2.st
author Claus Gittinger <cg@exept.de>
Wed, 10 Dec 2003 11:06:45 +0100
changeset 2114 cbdc4c02a8e2
parent 749 e898eaeff091
child 2152 1cbdfbcc685c
permissions -rw-r--r--
ExecutionErrorSignal -> ExecutionError

"
 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' }"

Object subclass:#JavaRef2
	instanceVariableNames:'valueCache constantPool'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Reader-Support-new'
!

!JavaRef2 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.

"
!

documentation
"
    I am parent of all reference types found in runtime constant pool. I define basic api - resolve and invalidate.
    Basic use case is to call resolve on my instance to get resolved thing, or to call invalidate to tell me,
    that world has changed and my cache is no longer valid.

    [author:]
        Marcel Hlopko <hlopkmar@fel.cvut.cz>

    [instance variables:]
        isResolved - flag telling whether instance is resolved
        valueCache - field holding resolved object
        owner - java class owning constant pool
    [class variables:]

    [see also:]

"
! !

!JavaRef2 class methodsFor:'instance creation'!

new
    "Don't call me directly"
    
    '[JavaRef] Dont instantiate me with new. Call my custom overriden object creation method' 
        infoPrintCR.
    ^ self basicNew initialize.

    "Modified: / 11-04-2011 / 19:44:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'accessing'!

constantPool
^constantPool.

    "Created: / 10-05-2011 / 17:16:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

constantPool: aJavaConstantPool
    constantPool := aJavaConstantPool.

    "Created: / 10-05-2011 / 17:16:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

isResolved
    ^ valueCache isNil not.

    "Created: / 08-04-2011 / 11:36:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-04-2011 / 17:39:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

name
^ self subclassResponsibility.

    "Created: / 08-04-2011 / 13:53:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

owner
    ^ constantPool owner.

    "Modified: / 12-05-2011 / 18:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

owner: javaClass 
    constantPool owner: javaClass.

    "Modified: / 12-05-2011 / 18:32:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

valueCache
    ^ valueCache.

    "Created: / 08-04-2011 / 11:37:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'comparing'!

= anotherJavaRef
^ self subclassResponsibility.

    "Created: / 08-04-2011 / 12:15:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

hash

^ self subclassResponsibility.

    "Created: / 08-04-2011 / 12:15:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'initialization'!

initialize
    valueCache := nil.
    super initialize.

    "Modified: / 08-04-2011 / 17:39:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'logging'!

info: arg 
    Transcript show: arg printString.

    "Created: / 10-05-2011 / 16:50:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

warning: arg 
    Transcript show: arg printString.

    "Created: / 10-05-2011 / 15:01:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'printing'!

displayString

    ^self subclassResponsibility

    "Created: / 14-08-2011 / 21:18:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRef2 methodsFor:'private - resolving'!

findResolvedStaticValue
    "raise an error: must be redefined in concrete subclass(es)"

    ^ self subclassResponsibility
!

findResolvedValue
    "raise an error: must be redefined in concrete subclass(es)"

    ^ self subclassResponsibility
! !

!JavaRef2 methodsFor:'queries'!

isJavaRef
"return true if object represents reference in java constant pool"
^ true.

    "Created: / 08-04-2011 / 16:15:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

isNewJavaRef
    "only temporary, to know if ref is old (claus' version) or new (m version)"
    
    ^ true.

    "Created: / 10-05-2011 / 12:20:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'resolving'!

invalidate
    "Invalidate reference. Cache will be cleared and next call to resolve will cause resolving from scratch."
    
    valueCache := nil.

    "Created: / 08-04-2011 / 11:42:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-04-2011 / 17:39:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

invalidateForClass: internalJavaClassName 
    "Invalidate (means call invalidate) reference if it has something to do with given class (e.g Class named internalJavaClassName was unloaded).
     Return true, if reference was invalidated."
    
    ^ self subclassResponsibility.

    "Created: / 08-04-2011 / 15:59:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

resolve
    "
     Do it all method - resolves current reference and returns expected element (JavaMethod, JavaField etc.)
     Hides implementation details of the way of dealing with invalidation etc. User should not need to call anything
     else."
    
    self isResolved ifFalse: [ self findResolvedValue ].
    ^ valueCache.

    "Created: / 08-04-2011 / 11:30:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

resolveStatic
    "
     Do it all method - resolves current reference and returns expected element (JavaMethod, JavaField etc.)
     Hides implementation details of the way of dealing with invalidation etc. User should not need to call anything
     else."
    
    self isResolved ifFalse: [ self findResolvedStaticValue ].
    ^ valueCache.

    "Created: / 26-04-2011 / 13:19:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

updateClassRefsFrom: oldOwner to: newOwner 
    self owner = oldOwner ifTrue: [
        self owner: newOwner.
    ].

    "Created: / 10-05-2011 / 16:50:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 04-06-2011 / 17:54:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRef2 methodsFor:'testing'!

isUnresolved

    ^valueCache isNil

    "Created: / 22-05-2011 / 14:01:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRef2 class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !