src/JavaClassRef2.st
author hlopkmar
Mon, 23 May 2011 14:53:35 +0000
branchjk_new_structure
changeset 814 68df82c46fb0
parent 809 0fd3dbe06abb
child 877 f5a5b93e1c78
permissions -rw-r--r--
finally forced myself to refactor tests.. fieldRef tests are ok now.. methodRef to come..

"{ Package: 'stx:libjava' }"

JavaRef2 subclass:#JavaClassRef2
	instanceVariableNames:'nameIndex'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Reader-Support-new'
!


!JavaClassRef2 class methodsFor:'instance creation'!

in: aJavaConstantPool withNameAt: nameIndex
   
    
    ^ self basicNew initializeIn: aJavaConstantPool withNameAt: nameIndex.

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

!JavaClassRef2 methodsFor:'accessing'!

classLoader
    self owner ifNil: [ ^ nil ] ifNotNil: [ ^ self owner classLoader ].

    "Created: / 11-04-2011 / 21:52:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 12-05-2011 / 18:32:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

javaClass

    valueCache ifNil:[self resolve].
    ^valueCache

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

javaClassName
    "return java class name as written in java programs e.g. java.util.String
     in case of array, return class name without square brackets"
    
    | tmp |

    tmp := self name copy.
    [ tmp startsWith: '[' ] whileTrue: [ tmp := tmp copyFrom: 2 ].
    tmp := tmp replaceAll: $/ with: $..
    (tmp startsWith: 'L') ifTrue: [ tmp := tmp copyFrom: 2 to: tmp size ].
    (tmp endsWith: ';') ifTrue: [ tmp := tmp copyFrom: 1 to: tmp size - 1 ].
    ^ tmp.

    "Created: / 08-04-2011 / 18:30:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 23-05-2011 / 15:30:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

name
    ^constantPool at: nameIndex.

    "Created: / 08-04-2011 / 13:48:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 13-05-2011 / 09:59:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'array support'!

arrayDimensions
    ^ self name occurrencesOf: $[.

    "Created: / 08-04-2011 / 18:42:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 13-05-2011 / 10:00:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

isJavaArrayClassRef
    ^ self name startsWith: '['.

    "Created: / 08-04-2011 / 18:40:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 13-05-2011 / 10:00:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'comparing'!

= anotherJavaClassRef 
    "superclass JavaRef2 says that I am responsible to implement this method"
    
    anotherJavaClassRef isJavaClassRef ifFalse: [ ^ false ].
    ^ self name = anotherJavaClassRef name.

    "Modified: / 08-04-2011 / 13:48:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

hash
    ^ self name hash.

    "Modified: / 13-05-2011 / 10:00:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'initialization'!

initializeIn: aJavaConstantPool withNameAt: nameCPIndex
    nameIndex := nameCPIndex.
    constantPool := aJavaConstantPool.
    super initialize.

    "Modified: / 10-05-2011 / 14:57:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'printing'!

fullName
    ^ self name.

    "Created: / 10-05-2011 / 14:19:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

printString
    ^ 'JavaClassRef for: ' , self name printString.

    "Created: / 10-05-2011 / 14:16:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 13-05-2011 / 10:00:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'private - resolving'!

findResolvedStaticValue
    "Resolving static inner classes is not different from resolving any other class, it's only done in different circumstances"
    
    ^ self findResolvedValue.

    "Created: / 28-04-2011 / 21:57:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

findResolvedValue
    "Resolve reference and set valueCache."
    
    valueCache := JavaResolver uniqueInstance 
                resolveClassIndentifiedByRef: self.

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

!JavaClassRef2 methodsFor:'queries'!

isJavaClassRef
^true.

    "Created: / 11-04-2011 / 19:10:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 methodsFor:'resolving'!

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 name = internalJavaClassName 
        ifTrue: 
            [ 
            self invalidate.
            ^ true ].
    ^ false.

    "Modified: / 23-05-2011 / 15:21:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaClassRef2 class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !