experiments/StCounter.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Nov 2011 12:54:24 +0100
changeset 2290 cd61fd0b66ac
parent 2152 1cbdfbcc685c
permissions -rw-r--r--
fixed: #version_SVN ($ to ยง)

"{ Package: 'stx:libjava/experiments' }"

Object subclass:#StCounter
	instanceVariableNames:'foo count javaObject'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tests'
!


!StCounter class methodsFor:'instance creation'!

new
    "return an initialized instance"

    ^ self basicNew initialize.
! !

!StCounter class methodsFor:'accessing'!

javaObject
    ^ JavaObjectDictionary new reflectionOf: self name

    "Created: / 09-01-2011 / 21:02:37 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter methodsFor:'accessing'!

count
    ^ count
!

inc
    count := count + 2.

    "Created: / 09-01-2011 / 13:51:22 / Jan Kurs <kurs.jan@post.cz>"
!

javaObject
    ^ self class javaObject.
"/    javaObject ifNil: [
"/        javaObject:= Java classForName: 'Counter'.
"/    ].
"/    ^ javaObject.

    "Created: / 09-01-2011 / 13:56:56 / Jan Kurs <kurs.jan@post.cz>"
    "Modified: / 09-01-2011 / 21:02:18 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter methodsFor:'error handling'!

doesNotUnderstand:aMessage 
    | method |
    aMessage selector = #'getCount()I' ifTrue:[ ^ self getCount.].
    aMessage selector = #'incCount()V' ifTrue:[ ^ self incCount.].
    method := JavaClass 
                lookupMethod:aMessage selector
                numArgs:aMessage arguments size
                in:self javaObject
                static:false.
    ^ method 
        ifNil:[  super doesNotUnderstand:aMessage.]
        ifNotNil:[ method valueWithReceiver:self arguments:aMessage arguments.]

    "Created: / 09-01-2011 / 13:42:08 / Jan Kurs <kurs.jan@post.cz>"
    "Modified: / 09-01-2011 / 15:54:04 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."
    foo := 123.
    count := 0.

    "/ super initialize.   -- commented since inherited method does nothing

    "Modified: / 09-01-2011 / 15:59:47 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter methodsFor:'java protocol'!

getCount
    Transcript showCR: 'aaa'.
    ^ count

    "Created: / 09-01-2011 / 12:59:04 / Jan Kurs <kurs.jan@post.cz>"
    "Modified: / 09-01-2011 / 15:52:19 / Jan Kurs <kurs.jan@post.cz>"
!

incCount
    count := count + 2.

    "Created: / 09-01-2011 / 13:03:29 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter methodsFor:'testing'!

isKindOf: aClass
    "This override is neccessary for ST <-> Java Object conversions"
    (self javaObject includesBehavior: aClass) ifTrue:
    [
        ^ true.
    ].
    ^ super isKindOf: aClass.

    "Created: / 09-01-2011 / 13:28:10 / Jan Kurs <kurs.jan@post.cz>"
    "Modified: / 09-01-2011 / 21:22:41 / Jan Kurs <kurs.jan@post.cz>"
! !

!StCounter class methodsFor:'documentation'!

version_SVN
    ^ '$Id: StCounter.st,v 1.1 2011-08-18 19:06:54 vrany Exp $'
! !