JavaBehavior.st
author Claus Gittinger <cg@exept.de>
Sun, 23 Feb 2020 14:03:15 +0100
branchcvs_MAIN
changeset 3997 5bb44f7e1d20
parent 3956 9d3fd717c20a
permissions -rw-r--r--
#REFACTORING by exept class: Java class changed: #dumpConfigOn:

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 1996-2015 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2015 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' }"

"{ NameSpace: Smalltalk }"

Class subclass:#JavaBehavior
	instanceVariableNames:'constantPool interfaces accessFlags initValues _lockWord_'
	classVariableNames:'InitialValuePerType ACX_ABSTRACT_OR_INTERFACE'
	poolDictionaries:'JavaConstants'
	category:'Languages-Java-Classes'
!

!JavaBehavior class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2015 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2015 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

"
!

documentation
"
    A base class for all Java classes. Slots & behavior defined here
    is known to the VM. Do not change the order of slots and
    add only to the end. You will have to modify stc.h then.

    Non-VM known stuff could be added to JavaClass safely.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]
        constantPool
        interfaces
        accessFlags
    [class variables:]

    [see also:]

"
! !

!JavaBehavior class methodsFor:'initialization'!

initialize

    "/ Cannot do this as the constant pool may not be initialized
    "/ACX_ABSTRACT_OR_INTERFACE := ACC_ABSTRACT bitOr:ACC_INTERFACE.
    ACX_ABSTRACT_OR_INTERFACE := 16r0000400 bitOr: 16r0000200.

    InitialValuePerType := IdentityDictionary new.
    InitialValuePerType at:$B put:0.
    InitialValuePerType at:$C put:0.
    InitialValuePerType at:$D put:0.0.
    InitialValuePerType at:$F put:(0.0 asShortFloat).
    InitialValuePerType at:$I put:0.
    InitialValuePerType at:$J put:0.
    InitialValuePerType at:$S put:0.
    InitialValuePerType at:$Z put:0.
    InitialValuePerType at:$L put:nil.
    InitialValuePerType at:$[ put:nil.

    "
     JavaBehavior initialize
    "

    "Modified: / 13-11-1998 / 14:09:52 / cg"
    "Modified: / 11-02-2012 / 16:55:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior class methodsFor:'constants'!

ACC_NATIVE
    ^ ACC_NATIVE

    "Created: / 16.5.1998 / 01:18:43 / cg"
!

ACC_PUBLIC
    ^ ACC_PUBLIC

    "Created: / 13.5.1998 / 13:03:18 / cg"
!

ACC_STATIC
    ^ ACC_STATIC

    "Created: / 16.5.1998 / 00:02:07 / cg"
! !

!JavaBehavior class methodsFor:'signature parsing'!

initialValueFromSignature:aSignature
    "given a signature, return an initializer value"

    |s|

    s := aSignature readStream.
    ^ self initialValueFromStream:s.

    "
     JavaBehavior initialValueFromSignature:'LObject;'
     JavaBehavior initialValueFromSignature:'B'
     JavaBehavior initialValueFromSignature:'I'
    "
!

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

    |typeChar|

    typeChar := s next.
    ^ InitialValuePerType at:typeChar ifAbsent:nil.
! !

!JavaBehavior methodsFor:'accessing'!

accessFlags
    ^ accessFlags
!

constantPool
    ^ constantPool
!

interfaceNames
    "Returns set of intefaces as java names (dotted)"

    | cp |

    cp := self constantPool.
    interfaces notNil ifTrue:[
         ^ interfaces collect:[:ifaceRefIndex | | ifaceRef | ifaceRef := cp at: ifaceRefIndex. ifaceRef isJavaClassRef ifTrue:[ifaceRef javaClassName] ifFalse:[ifaceRef javaName]].
    ].
    ^ #()

    "Created: / 13-02-2013 / 09:33:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-11-2014 / 17:00:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

interfaces
    | cp |

    cp := self constantPool.
    interfaces notNil ifTrue:[ 
        ^ interfaces collect: [:ifaceRefIndex | (cp at: ifaceRefIndex) javaClass ] 
    ].

    ^ #()

    "Modified: / 27-11-2014 / 16:58:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior methodsFor:'accessing-Java'!

getJavaLockWord
    "Returns a Java lock word for given object. The returned
     value is 
        - either SmallInteger that encodes the thinlock
        - or a fat lock, instance of JavaMonitor
    "

    ^ _lockWord_

    "Created: / 26-08-2012 / 14:03:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 06-12-2013 / 21:47:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

getJavaMonitor
    "Returns fat JavaMonitor associated with the receiver"

    "/ For Java objects, check if there is already a thinlock,
    "/ inflate it and return the fatlock

    _lockWord_ class == SmallInteger ifTrue:[
        _lockWord_ := JavaVM inflateLockFor: self lockword: _lockWord_.
    ].
    ^_lockWord_

    "Created: / 26-08-2012 / 18:35:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 06-12-2013 / 21:47:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior methodsFor:'compiler interface'!

programmingLanguage

    ^JavaLanguage instance

    "Created: / 26-10-2010 / 23:42:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior methodsFor:'private accessing'!

getInterfaces
    ^ interfaces

    "Created: / 15-09-2013 / 00:29:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hasMultipleVersions
    "
    return true if this class has multiple coexisting versions
    "
    ^ ((accessFlags bitAnd:ACX_HASMULTIVERS) == 0) not.

    "Created: / 02-10-2013 / 21:48:24 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
    "Modified: / 28-10-2013 / 13:01:32 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

makeObsolete
    accessFlags := accessFlags bitOr:ACC_OBSOLETE

    "Created: 7.8.1997 / 19:04:48 / cg"
!

markMultipleVersions
    "
     mark this class non cacheable - references to this class have to be
     resolved over and over again, cannot be cached."
    
    self hasMultipleVersions not ifTrue: [
        accessFlags := accessFlags bitXor: ACX_HASMULTIVERS
    ].

    "Created: / 14-04-2013 / 14:17:38 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
    "Modified (comment): / 28-10-2013 / 14:07:35 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

markNonMultipleVersions
    "
     mark this class cacheable - references to this class dont have to be
     resolved over and over again, can be cached."
    
    self hasMultipleVersions ifTrue: [
        accessFlags := accessFlags bitXor: ACX_HASMULTIVERS
    ].

    "Created: / 14-04-2013 / 14:25:23 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
    "Modified (comment): / 28-10-2013 / 14:07:59 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

markUninitialized
    (accessFlags bitAnd:ACX_INITIALIZED) ~~ 0 ifTrue:[
	accessFlags := accessFlags bitXor:ACX_INITIALIZED
    ].
!

setAccessFlags:flags
    accessFlags := flags.

    "Created: 15.4.1996 / 16:42:52 / cg"
!

setConstantPool:aJavaConstantPool 
    constantPool := aJavaConstantPool.
    constantPool notNil ifTrue:[
        constantPool owner:self
    ].

    "Created: / 15-04-1996 / 16:42:52 / cg"
    "Modified: / 04-08-2014 / 15:51:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setInterfaces:aCollection
    interfaces := aCollection asNilIfEmpty

    "Modified: / 07-04-1997 / 15:44:53 / cg"
    "Modified: / 05-05-2014 / 09:44:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior methodsFor:'queries'!

hasInterface:aJavaInterface
    "return true, if I respond to all methods as
     required by the argument, an aJavaInterface"

    interfaces notEmptyOrNil ifTrue:[
        (self interfaces includesIdentical:aJavaInterface) ifTrue:[
            ^ true
        ]
    ].
    superclass isJavaClass ifTrue:[
        ^ superclass hasInterface:aJavaInterface
    ].
    ^ false.

"/    aJavaInterface methodDictionary keysAndValuesDo:[:sel :mthd |
"/        (self canUnderstand:sel) ifFalse:[
"/            ^ false.
"/        ]
"/    ].
"/    ^ true

    "Modified: / 28-01-1998 / 01:46:16 / cg"
    "Modified: / 14-02-2017 / 10:17:30 / stefan"
!

isAbstract
    "return true, if the receiver is abstract
     (i.e. may not have instances)"

    ^ (accessFlags bitAnd:ACC_ABSTRACT) ~~ 0

    "Modified: / 7.5.1998 / 12:24:42 / cg"
!

isAnnotation
    "return true, if the receiver is an interface"

    ^ (accessFlags bitAnd:ACC_ANNOTATION) ~~ 0

    "Modified: / 07-05-1998 / 12:23:39 / cg"
    "Created: / 11-02-2012 / 16:55:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isEnum
    "return true, if the receiver is an interface"

    ^ (accessFlags bitAnd:ACC_ENUM) ~~ 0

    "Modified: / 07-05-1998 / 12:23:39 / cg"
    "Created: / 11-02-2012 / 16:55:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isFinal
    "return true, if the receiver is final
     (i.e. may not be subclassed)"

    ^ (accessFlags bitAnd:ACC_FINAL) ~~ 0

    "Modified: / 7.5.1998 / 12:24:21 / cg"
!

isInitialized
    "return true, if the receiver is initialized"

    ^ (accessFlags bitAnd:ACX_INITIALIZED) ~~ 0

    "Modified: / 7.5.1998 / 12:23:54 / cg"
!

isInterface
    "return true, if the receiver is an interface"

    ^ (accessFlags bitAnd:ACC_INTERFACE) ~~ 0

    "Modified: / 7.5.1998 / 12:23:39 / cg"
!

isObsolete
    "return true, if the receiver is obsolete
     Java classes are never."

    ^ (accessFlags bitAnd:ACC_OBSOLETE) ~~ 0.

    "Modified: 7.8.1997 / 19:04:28 / cg"
!

isPackagePrivate
    ^ (accessFlags bitAnd:((ACC_PRIVATE bitOr: ACC_PUBLIC) bitOr: ACC_PROTECTED)) == 0

    "Created: / 05-07-2012 / 10:13:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isPrivate
    "return true, if the receiver is an interface"

    ^ (accessFlags bitAnd:ACC_PRIVATE) ~~ 0

    "Modified: / 07-05-1998 / 12:23:39 / cg"
    "Created: / 11-02-2012 / 16:55:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isProtected
    "return true, if the receiver is an interface"

    ^ (accessFlags bitAnd:ACC_PROTECTED) ~~ 0

    "Modified: / 07-05-1998 / 12:23:39 / cg"
    "Created: / 11-02-2012 / 16:56:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isPublic
    "return true, if the receiver is public"

    ^ (accessFlags bitAnd:ACC_PUBLIC) ~~ 0

    "Modified: / 7.5.1998 / 12:22:44 / cg"
!

isSynthetic
    "return true, if the receiver is a synthetic class
     (usually a proxy generated at runtime)"

    ^ (accessFlags bitAnd:ACC_SYNTHETIC) ~~ 0

    "Created: / 13-04-2012 / 18:51:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaBehavior class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id$'
! !


JavaBehavior initialize!