src/JavaRef2.st
author hlopkmar
Wed, 07 Dec 2011 14:16:13 +0000
branchjk_new_structure
changeset 1235 8a3b56d4ba26
parent 1226 bd1d5c4ca4a8
child 1243 c6fa3c2b0ce1
permissions -rw-r--r--
method resolving unified.. fields to follow

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 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.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ 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

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 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.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!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: / 06-12-2011 / 17:02:11 / 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

    Logger log: arg severity: #info facility: 'JVM'

    "Created: / 10-05-2011 / 16:50:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 14-09-2011 / 21:47:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

warning: arg 

    Logger log: arg severity: #warn facility: 'JVM'

    "Created: / 10-05-2011 / 15:01:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 14-09-2011 / 21:47:01 / Jan Vrany <jan.vrany@fit.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$'
! !