JavaUnresolvedClassConstant.st
author cg
Mon, 07 Apr 1997 17:28:23 +0000
changeset 168 90e39cb3fa04
parent 148 db560ebab8b5
child 251 4898461c0cca
permissions -rw-r--r--
*** empty log message ***

JavaUnresolvedConstant subclass:#JavaUnresolvedClassConstant
	instanceVariableNames:'nameIndex fullName'
	classVariableNames:''
	poolDictionaries:''
	category:'Java-Reader-Support'
!


!JavaUnresolvedClassConstant class methodsFor:'instance creation'!

fullName:nm
    |ref|

    ref := Java unresolvedClassRefFor:nm.
    ref notNil ifTrue:[^ ref].

    ref := self new fullName:nm.
    Java rememberUnresolved:ref.
    ^ ref
!

pool:aPool poolIndex:slotIndex nameIndex:index
    ^ self new pool:aPool poolIndex:slotIndex nameIndex:index
! !

!JavaUnresolvedClassConstant methodsFor:'accessing'!

className
    |s nm|

    (fullName startsWith:$[) ifTrue:[
        "/ a ref for newarray or new or checkCast

        s := fullName readStream.
        s next.
        nm := JavaMethod retvalSpecFromStream:s.
        ^ nm
    ].
    ^ fullName

!

deref
    (fullName startsWith:'[') ifTrue:[
        ^ JavaUnresolvedClassConstant basicNew setFullName:(fullName copyFrom:2)
    ].
    self halt.

    "Created: 7.4.1997 / 13:38:07 / cg"
!

fullName
    ^ fullName

!

javaClass
    |cls|

    fullName isNil ifTrue:[
        self halt.
    ].
    ^ Java classForName:fullName.

    "Modified: 18.3.1997 / 16:47:22 / cg"
!

name
    ^ fullName copy replaceAll:$/ with:$.

    "Created: 7.2.1997 / 23:44:47 / cg"
!

pool:aPool poolIndex:slotIndex nameIndex:name_index
    constantPool := aPool.
    constantPoolIndex := slotIndex.
    nameIndex := name_index.

!

setFullName:aNameString
    fullName := aNameString

    "Created: 7.4.1997 / 13:37:45 / cg"
!

smalltalkArrayClass
    (fullName startsWith:'[[') ifTrue:[
        ^ Array
    ].
    (fullName startsWith:'[F') ifTrue:[
        ^ FloatArray
    ].
    (fullName startsWith:'[B') ifTrue:[
        ^ ByteArray
    ].
    self halt.

    "Created: 7.4.1997 / 13:35:25 / cg"
! !

!JavaUnresolvedClassConstant methodsFor:'converting'!

asClassPointerRef
    (fullName startsWith:'[[') ifTrue:[
        ^ JavaClassPointerRef class:Array nameandType:fullName
    ].
    (fullName startsWith:'[F') ifTrue:[
        ^ JavaClassPointerRef class:FloatArray nameandType:fullName
    ].
    (fullName startsWith:'[B') ifTrue:[
        ^ JavaClassPointerRef class:ByteArray nameandType:fullName
    ].
    self halt.

    "Created: 7.4.1997 / 13:40:29 / cg"
! !

!JavaUnresolvedClassConstant methodsFor:'printing & storing'!

displayString
    fullName isNil ifTrue:[
        ^ 'UnresolvedClass(** nil **)'
    ].
    ^ 'UnresolvedClass(' , (fullName copy replaceAll:$/ by:$.) , ')'
! !

!JavaUnresolvedClassConstant methodsFor:'resolving'!

preResolve
    |clsName cls nm s ref|

    fullName isNil ifTrue:[
        "/ first, resolve my name ...

        clsName := constantPool at:nameIndex.
        "/ DEBUGGING
        clsName isString ifFalse:[
            self halt:'oops - no class name string in const pool'.
        ].

        fullName := clsName
    ].

    "/ try to resolve the class

    "/ 'resolve: ' print. fullName printCR.

    cls := Java classNamed:fullName.
    cls notNil ifTrue:[
        "/ good - the class is already loaded.

        constantPool at:constantPoolIndex put:cls.
        ^ cls
    ].

    (fullName startsWith:$[) ifTrue:[
        "/ a ref for newarray or new

        nm := JavaMethod retvalSpecFromStream:(ReadStream on:fullName).
        [nm endsWith:'[]'] whileTrue:[
            nm := nm copyWithoutLast:2
        ].

        cls := Java classNamed:nm.
        cls notNil ifTrue:[
            ref := JavaClassPointerRef class:cls nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].

        "/ look for specials like byte[], int[] etc.
        "/ there are only a few of them - forgive me nameing them here ...
        fullName = '[B' ifTrue:[    "/ byte[]
            ref := JavaBuiltInClassPointerRef class:ByteArray nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[I' ifTrue:[     "/ int[]
            ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[D' ifTrue:[     "/ double[]
            ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[[D' ifTrue:[    "/ double[][]
            ref := JavaBuiltInClassPointerRef class:DoubleArray nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[[I' ifTrue:[    "/ int[][]
            ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        (fullName startsWith:'[L') ifFalse:[
            ('JAVA: oops - unresolvable funny class: ' , fullName) errorPrintCR.
        ]
    ] ifFalse:[
        nm := self className.
    ].

    self rememberForResolveWith:nm.
    ^ self

    "Created: 15.4.1996 / 15:51:42 / cg"
    "Modified: 15.4.1996 / 16:26:05 / cg"
! !

!JavaUnresolvedClassConstant class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaUnresolvedClassConstant.st,v 1.20 1997/04/07 17:26:29 cg Exp $'
! !