JavaUnresolvedClassConstant.st
author cg
Thu, 12 Nov 1998 20:33:33 +0000
changeset 443 f5c1f55d8bdb
parent 431 fe362bcc1aeb
child 454 38f590639d65
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 setFullName:nm.
    Java rememberUnresolved:ref.
    ^ ref

    "Modified: / 19.10.1998 / 20:18:13 / cg"
!

pool:aPool poolIndex:slotIndex fullName:aString
    ^ self new 
          pool:aPool poolIndex:slotIndex fullName:aString

    "Created: / 4.2.1998 / 22:13:13 / cg"
    "Modified: / 4.2.1998 / 22:13:28 / cg"
!

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

    "Modified: / 4.2.1998 / 22:13:38 / cg"
! !

!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 in:nil.
        ^ nm
    ].
    ^ fullName

    "Modified: / 8.1.1998 / 19:11:37 / cg"
!

deref
    |refClassName cls|

    (fullName startsWith:'[L') ifTrue:[
        refClassName := fullName copyFrom:3 to:(fullName indexOf:$;)-1.
        cls := Java at:refClassName.
        cls notNil ifTrue:[
            ^ cls
        ].
        ^ JavaUnresolvedClassConstant basicNew setFullName:refClassName
    ].
    (fullName startsWith:'[[C') ifTrue:[
        ^ JavaBuiltInClassPointerRef new nameandType:'[C'.
    ].

    "Created: / 7.4.1997 / 13:38:07 / cg"
    "Modified: / 6.2.1998 / 01:21:01 / cg"
!

fullName
    ^ fullName

!

javaClass
    |clsName|

    fullName isNil ifTrue:[
        self preResolve.
        fullName isNil ifTrue:[
            self halt.
        ]
    ].
    (fullName startsWith:$[) ifTrue:[
        clsName := self className
    ] ifFalse:[
        clsName := fullName
    ].
    ^ Java classForName:clsName.

    "Modified: / 10.11.1998 / 19:29:28 / cg"
!

name
    ^ fullName copyReplaceAll:$/ with:$.

    "Created: / 7.2.1997 / 23:44:47 / cg"
    "Modified: / 18.7.1998 / 22:57:47 / cg"
!

pool:aPool poolIndex:slotIndex fullName:aString
    constantPool := aPool.
    constantPoolIndex := slotIndex.
    fullName := aString.

    "Created: / 4.2.1998 / 22:15:22 / 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
    ].
    (fullName startsWith:'[C') ifTrue:[
        ^ JavaClassPointerRef class:String nameandType:fullName
    ].
    self halt.

    "Created: / 7.4.1997 / 13:40:29 / cg"
    "Modified: / 25.1.1998 / 19:56:54 / cg"
! !

!JavaUnresolvedClassConstant methodsFor:'printing & storing'!

displayString
    fullName isNil ifTrue:[
        ^ 'UnresolvedClass(** nil **)'
    ].
    ^ 'UnresolvedClass(' , (fullName copyReplaceAll:$/ with:$.) , ')'

    "Modified: / 18.7.1998 / 22:57:36 / cg"
! !

!JavaUnresolvedClassConstant methodsFor:'queries'!

isUnresolvedClass
    ^ true

    "Created: / 20.10.1998 / 17:43:36 / cg"
!

package
    "extract from the fullName"

    |components|

    components := fullName asCollectionOfSubstringsSeparatedBy:$/.
    components size > 1 ifTrue:[
        ^ (components copyWithoutLast:1) asStringWith:$/
    ].
    ^ fullName

    "Created: / 12.11.1998 / 21:11:30 / cg"
! !

!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) in:nil.
        [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 = '[Z' ifTrue:[    "/ boolean[]
            ref := JavaBuiltInClassPointerRef class:ByteArray nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[I' ifTrue:[     "/ int[]
            ref := JavaBuiltInClassPointerRef class:SignedIntegerArray nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[J' ifTrue:[     "/ long[]
            ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[S' ifTrue:[     "/ short[]
            ref := JavaBuiltInClassPointerRef class:SignedWordArray nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[C' ifTrue:[     "/ char[]
            "/ should be TwoByteString ...
            ref := JavaBuiltInClassPointerRef class:String nameandType:fullName.
            constantPool at:constantPoolIndex put:ref.
            ^ ref
        ].
        fullName = '[F' ifTrue:[     "/ float[]
            ref := JavaBuiltInClassPointerRef class:FloatArray 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: / 8.1.1998 / 19:11:43 / cg"
! !

!JavaUnresolvedClassConstant class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaUnresolvedClassConstant.st,v 1.33 1998/11/12 20:33:33 cg Exp $'
! !