JavaMethod.st
author cg
Wed, 17 Apr 1996 21:59:40 +0000
changeset 18 6c07dc4b1118
parent 10 1f803ce6d3fc
child 19 512a19e2d46f
permissions -rw-r--r--
checkin from browser

CompiledCode subclass:#JavaMethod
	instanceVariableNames:'javaByteCode accessFlags name signature exceptionTable
		lineNumberTable javaClass'
	classVariableNames:'SignatureTypeCodes'
	poolDictionaries:''
	category:'Java-Classes'
!


!JavaMethod class methodsFor:'initialization'!

initialize
    SignatureTypeCodes := IdentityDictionary new.
    SignatureTypeCodes at:$B put:#byte.
    SignatureTypeCodes at:$C put:#char.
    SignatureTypeCodes at:$D put:#double.
    SignatureTypeCodes at:$F put:#float.
    SignatureTypeCodes at:$I put:#int.
    SignatureTypeCodes at:$J put:#long.
    SignatureTypeCodes at:$S put:#'unsigned short'.
    SignatureTypeCodes at:$Z put:#boolean.
    SignatureTypeCodes at:$L put:#object.
    SignatureTypeCodes at:$[ put:#array.

    "
     JavaMethod initialize
    "
! !

!JavaMethod class methodsFor:'signature parsing'!

argSpecFromStream:s
    "parse an argSpec - see java doc"

    |argSpec spec|

    spec := ''.
    [s atEnd or:[s peek == $)]] whileFalse:[
        argSpec := self fieldTypeFromStream:s.
        spec size ~~ 0 ifTrue:[
            spec := spec , ' '
        ].
        spec := spec , argSpec.
    ].
    ^ spec


!

fieldTypeFromStream:s
    "parse a fieldTypeSpec - see java doc"

    |typeChar typeSym spec elType size className|

    typeChar := s next.

    typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.

    typeSym == #unknown ifTrue:[
        ^ typeSym
    ].
    typeSym == #object ifTrue:[
        className := s upTo:$;.
        "/ strip off default
        (className startsWith:'java/lang/') ifTrue:[
            ^ className copyFrom:11
        ].
        ^ className
    ].
    typeSym == #array ifTrue:[
        s peek isDigit ifTrue:[
            size := Integer readFrom:s.
            elType := self fieldTypeFromStream:s.
            ^ elType , '[' , size printString , ']'
        ].
        elType := self fieldTypeFromStream:s.
        ^ elType , '[]'
    ].
    ^ typeSym
!

retvalSpecFromStream:s
    "parse a retvalSpec - see java doc"

    |argSpec spec|

    s atEnd ifTrue:[self halt. ^ 'void'].
    s peek == $V ifTrue:[^ 'void'].
    ^ self fieldTypeFromStream:s

!

specFromSignature:aSignature withName:name
    "given a signature, return a spec"

    |s argSpec retvalSpec|

    s := aSignature readStream.
    s next ~~ $( ifTrue:[self halt. ^ name].

    argSpec := self argSpecFromStream:s.

    s next ~~ $) ifTrue:[self halt. ^ name].

    retvalSpec := self retvalSpecFromStream:s.

    ^ retvalSpec , ' ' , name , ' (' , argSpec , ')'

    "
     JavaMethod specFromSignature:'(LObject;)V' withName:'foo' 
     JavaMethod specFromSignature:'(B;)S'       withName:'foo'
    "
! !

!JavaMethod methodsFor:'accessing'!

constantPool
    ^ javaClass constantPool

    "Modified: 16.4.1996 / 12:36:27 / cg"
    "Created: 16.4.1996 / 15:28:50 / cg"
!

javaByteCode
    ^ javaByteCode

    "Modified: 16.4.1996 / 12:36:27 / cg"
    "Created: 16.4.1996 / 14:55:44 / cg"
!

setAccessFlags:flags
    accessFlags := flags.

    "Created: 16.4.1996 / 11:34:14 / cg"
!

setCode:code
    javaByteCode := code

    "Modified: 16.4.1996 / 12:36:27 / cg"
!

setExceptionTable:anArray
    exceptionTable := anArray.

    "Created: 16.4.1996 / 12:34:04 / cg"
!

setJavaClass:aJavaClass
    javaClass := aJavaClass

    "Modified: 16.4.1996 / 12:36:27 / cg"
    "Created: 16.4.1996 / 15:28:15 / cg"
!

setLineNumberTable:anArray
    lineNumberTable := anArray.

    "Created: 16.4.1996 / 12:34:04 / cg"
    "Modified: 16.4.1996 / 12:49:06 / cg"
!

setMaxLocals:max_locals
"/    maxLocals := max_locals

    "Created: 16.4.1996 / 12:36:13 / cg"
!

setMaxStack:max_stack
"/    maxStack := max_stack

    "Created: 16.4.1996 / 12:36:00 / cg"
!

setName:aString
    name := aString.

    "Created: 16.4.1996 / 11:34:22 / cg"
!

setSignature:aString
    signature := aString.

    "Created: 16.4.1996 / 11:34:29 / cg"
! !

!JavaMethod methodsFor:'decompiling'!

decompileTo:aStream
    JavaDecompiler decompile:self to:aStream.
    ^ true


! !

!JavaMethod methodsFor:'printing & storing'!

printStringForBrowserWithSelector:selector
    ^ self signatureName
!

signatureName
    "return a string to be used when browsing"

    ^ self class specFromSignature:signature withName:name
! !

!JavaMethod methodsFor:'queries'!

isCFunction
    ^ (accessFlags bitAnd:16r100) ~~ 0
!

isUnloaded
    ^ false
!

who
    "return the class and selector of where I am defined in."

    |idx|

    idx := javaClass methodArray identityIndexOf:self.
    idx == 0 ifTrue:[^ nil].
    ^ Array with:javaClass with:(javaClass selectorArray at:idx)
! !

!JavaMethod class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaMethod.st,v 1.5 1996/04/17 21:55:19 cg Exp $'
! !
JavaMethod initialize!