help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [GOODIE] !ClassDescription methodsFor: 'code-generation


From: Markus Fritsche
Subject: [Help-smalltalk] [GOODIE] !ClassDescription methodsFor: 'code-generation'!
Date: Wed, 07 Aug 2002 20:37:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1a) Gecko/20020610

This little source file should assist in writing getters and setters. Just file it in and say "MyClass publish" and you'll get a string containing all getters and setters.

Feedback welcome!

Regards, Markus
!ClassDescription methodsFor: 'code-generation'!
publish
    | stream |
    stream := WriteStream on: String new.
    self publishOn: stream.
    ^stream contents.
!
publishOn: stream
    | vars | 
    vars := self instanceVariableString substrings.
    vars addAll: (self classVariableString substrings).
    vars do: [ :var | 
        stream      nextPutAll: '!', self name asString;
            nextPutAll: ' methodsFor: ''accessing''!'; cr;
            nextPutAll: var; cr;
            nextPutAll: '  "generated source"'; cr;
            nextPutAll: '    ^',var; cr; 
            nextPutAll: '! !'; cr; cr;
            nextPutAll: '!', self name asString;
            nextPutAll: ' methodsFor: ''accessing''!'; cr;
            nextPutAll: var, ': anObject'; cr;
            nextPutAll: '  "generated source"'; cr;
            nextPutAll: '    ', var, ' := anObject'; cr;
            nextPutAll: '! !'; cr; cr.
        ].
! !

reply via email to

[Prev in Thread] Current Thread [Next in Thread]