--- a/CodeGeneratorTool.st Thu Jan 16 10:26:21 2003 +0100
+++ b/CodeGeneratorTool.st Thu Jan 16 11:15:27 2003 +0100
@@ -22,6 +22,17 @@
!CodeGeneratorTool class methodsFor:'code generation'!
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly
+ ^ self
+ createAccessMethodsFor:aCollectionOfVarNames
+ in:aClass
+ withChange:withChange
+ asValueHolder:asValueHolder
+ readersOnly:readersOnly
+ writersOnly:writersOnly
+ lazyInitialization:false
+!
+
+createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization
"workhorse for creating access methods for instvars."
|classesClassVars|
@@ -29,7 +40,7 @@
classesClassVars := aClass theNonMetaclass allClassVarNames.
aCollectionOfVarNames do:[:name |
- |source varType methodName|
+ |source varType methodName defaultMethodName|
varType := (classesClassVars includes:name)
ifTrue:['static']
@@ -41,14 +52,26 @@
methodName := methodName asLowercaseFirst.
].
+ "/ the GETTER
writersOnly ifFalse:[
+ lazyInitialization ifTrue:[
+ defaultMethodName := 'default' , name asUppercaseFirst.
+ ].
+
"check, if method is not already present"
(aClass includesSelector:(methodName asSymbol)) ifFalse:[
asValueHolder ifTrue:[
source := methodName
, '\ "return/create the ''%2'' value holder (automatically generated)"\\'
- , ' %2 isNil ifTrue:[\'
- , ' %2 := ValueHolder new.\'.
+ , ' %2 isNil ifTrue:[\'.
+ lazyInitialization ifTrue:[
+ source := source
+ , ' %2 := self class %3 asValue.\'.
+ ] ifFalse:[
+ source := source
+ , ' %2 := ValueHolder new.\'.
+ ].
+
withChange ifTrue:[
source := source
, ' %2 addDependent:self.\'.
@@ -58,16 +81,38 @@
, ' ^ %2'.
] ifFalse:[
source := methodName
- , '\ "return the value of the %1 variable ''%2'' (automatically generated)"\\'
- , ' ^ %2'.
+ , '\ "return the value of the %1 variable ''%2'' (automatically generated)"\\'.
+ lazyInitialization ifTrue:[
+ source := source
+ , ' %2 isNil ifTrue:[\'
+ , ' %2 := self class %3.\'
+ , ' ].\'
+ , ' ^ %2'.
+ ] ifFalse:[
+ source := source
+ , ' ^ %2'.
+ ].
].
- source := (source bindWith:varType with:name) withCRs.
+ source := (source bindWith:varType with:name with:defaultMethodName) withCRs.
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']).
] ifTrue:[
Transcript showCR:'method ''', methodName , ''' already present'
].
+
+ "/ default for lazy on class side
+ lazyInitialization ifTrue:[
+ (aClass class includesSelector:(defaultMethodName asSymbol)) ifFalse:[
+ source := defaultMethodName
+ , '\ "default value for the ''%2'' instance variable (automatically generated)"\\'
+ , ' self halt:''unfinished code''.\'
+ , ' ^ nil.'.
+ source := (source bindWith:varType with:name) withCRs.
+ self compile:source forClass:aClass class inCategory:'defaults'.
+ ].
+ ].
].
+ "/ the SETTER
readersOnly ifFalse:[
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[
asValueHolder ifTrue:[
@@ -1114,5 +1159,5 @@
!CodeGeneratorTool class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.9 2002-12-06 10:44:20 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.10 2003-01-16 10:15:16 cg Exp $'
! !