src/JavaRef2.st
author vranyj1
Tue, 21 Feb 2012 11:29:41 +0000
branchjk_new_structure
changeset 1372 dea574a1b6b3
parent 1353 2968f8acb434
child 1378 9d64d8357509
permissions -rw-r--r--
Some initial class reloading support. Not yet finished, just sketched out.

"
 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
    self findResolvedValue: true.

    "Modified: / 09-02-2012 / 23:10:09 / mh <hlopik@gmail.com>"
!

findResolvedValue:arg
    self shouldImplement

    "Created: / 09-02-2012 / 23:08:15 / mh <hlopik@gmail.com>"
! !

!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 
    "Invalidates receiver iff it refers (even indirectly)
     to a class ref that has been resolved to given class.
     Returns true, if the receiver has been invalidated,
     false otherwise"

    ^ self subclassResponsibility.

    "Created: / 08-04-2011 / 15:59:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified (comment): / 21-02-2012 / 10:20:46 / Jan Vrany <jan.vrany@fit.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>"
!

resolve: doClassInit
    "
     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: doClassInit ].
    ^ valueCache.

    "Created: / 08-04-2011 / 11:30:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Created: / 09-02-2012 / 23:08:15 / mh <hlopik@gmail.com>"
!

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."
    
"/    Logger log: self printString , ': dont call resolveStatic anymore, call resolve its safe' severity:#info facility:#JVM.
    ^ self resolve.

    "Created: / 26-04-2011 / 13:19:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-12-2011 / 22:21:57 / Jan Vrany <jan.vrany@fit.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$'
! !