SmalltalkCodeGeneratorTool.st
changeset 11523 d0f296d32d73
parent 11223 52963b06ef66
child 11637 b7ab3efa491e
equal deleted inserted replaced
11522:03f5a6c8f136 11523:d0f296d32d73
   210 ' bindWith:method with:aSelector.
   210 ' bindWith:method with:aSelector.
   211 
   211 
   212     alreadyInSuperclass ifTrue:[
   212     alreadyInSuperclass ifTrue:[
   213         code := code, (('\    super %1\' bindWith:method) withCRs).
   213         code := code, (('\    super %1\' bindWith:method) withCRs).
   214     ].
   214     ].
   215     self compile:code forClass:aClass inCategory:(aCategory ? 'actions').
   215     self compile:code forClass:aClass inCategory:(aCategory ? #actions).
   216     ^ code
   216     ^ code
   217 !
   217 !
   218 
   218 
   219 createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine
   219 createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine
   220     |alreadyInSuperclass method code text|
   220     |alreadyInSuperclass method code text|
   248         text := '    ^ super %1\' bindWith:method.
   248         text := '    ^ super %1\' bindWith:method.
   249     ] ifFalse:[
   249     ] ifFalse:[
   250         text := '    ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector.
   250         text := '    ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector.
   251     ].
   251     ].
   252     code := code, (text withCRs).
   252     code := code, (text withCRs).
   253     self compile:code forClass:aClass inCategory:(aCategory ? 'actions').
   253     self compile:code forClass:aClass inCategory:(aCategory ? #actions).
   254     ^ code
   254     ^ code
   255 ! !
   255 ! !
   256 
   256 
   257 !SmalltalkCodeGeneratorTool class methodsFor:'private'!
   257 !SmalltalkCodeGeneratorTool class methodsFor:'private'!
   258 
   258 
   314         code := (self codeFor_classInitialize) expandPlaceholdersWith:bindings.
   314         code := (self codeFor_classInitialize) expandPlaceholdersWith:bindings.
   315 
   315 
   316         self 
   316         self 
   317             compile:code
   317             compile:code
   318             forClass:metaClass 
   318             forClass:metaClass 
   319             inCategory:'initialization'.
   319             inCategory:#initialization.
   320     ].
   320     ].
   321 
   321 
   322     self executeCollectedChangesNamed:('Add Class Initializer to ' , className).
   322     self executeCollectedChangesNamed:('Add Class Initializer to ' , className).
   323 !
   323 !
   324 
   324 
   337         (aClass includesSelector:selector) ifFalse:[
   337         (aClass includesSelector:selector) ifFalse:[
   338             code := (selector , '\    ^ false') withCRs.
   338             code := (selector , '\    ^ false') withCRs.
   339             self 
   339             self 
   340                 compile:code
   340                 compile:code
   341                 forClass:aClass 
   341                 forClass:aClass 
   342                 inCategory:'testing'.
   342                 inCategory:#testing.
   343         ].
   343         ].
   344         (eachSubClass includesSelector:selector) ifFalse:[
   344         (eachSubClass includesSelector:selector) ifFalse:[
   345             code := (selector , '\    ^ true') withCRs.
   345             code := (selector , '\    ^ true') withCRs.
   346             self 
   346             self 
   347                 compile:code
   347                 compile:code
   348                 forClass:eachSubClass 
   348                 forClass:eachSubClass 
   349                 inCategory:'testing'.
   349                 inCategory:#testing.
   350         ].
   350         ].
   351     ].
   351     ].
   352 
   352 
   353     self executeCollectedChangesNamed:'Add ClassType Tests'
   353     self executeCollectedChangesNamed:'Add ClassType Tests'
   354 !
   354 !
   416     initCode nextPutLine:'    "'.
   416     initCode nextPutLine:'    "'.
   417 
   417 
   418     self
   418     self
   419         compile:(initCode contents)
   419         compile:(initCode contents)
   420         forClass:metaClass 
   420         forClass:metaClass 
   421         inCategory:'class initialization'.
   421         inCategory:#'class initialization'.
   422 
   422 
   423 
   423 
   424     code := 'allStateNames\    ^ #( ' ,
   424     code := 'allStateNames\    ^ #( ' ,
   425                 ((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')',
   425                 ((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')',
   426                 '\\    "\' ,
   426                 '\\    "\' ,
   427                 '     ',className, ' allStateNames\' ,
   427                 '     ',className, ' allStateNames\' ,
   428                 '    "\'.
   428                 '    "\'.
   429     self
   429     self
   430         compile:code withCRs
   430         compile:code withCRs
   431         forClass:metaClass 
   431         forClass:metaClass 
   432         inCategory:'queries'.
   432         inCategory:#queries.
   433 
   433 
   434     self executeCollectedChangesNamed:('Generate EnumType Code for ' , className).
   434     self executeCollectedChangesNamed:('Generate EnumType Code for ' , className).
   435 
   435 
   436     aClass initialize.
   436     aClass initialize.
   437 
   437 
   477 ' bindWith:className.    
   477 ' bindWith:className.    
   478 
   478 
   479         self 
   479         self 
   480             compile:code
   480             compile:code
   481             forClass:metaClass 
   481             forClass:metaClass 
   482             inCategory:'documentation'.
   482             inCategory:#documentation.
   483     ].
   483     ].
   484 
   484 
   485     self executeCollectedChangesNamed:('Add Example to ' , className).
   485     self executeCollectedChangesNamed:('Add Example to ' , className).
   486 !
   486 !
   487 
   487 
   494     metaClass := aClass theMetaclass.
   494     metaClass := aClass theMetaclass.
   495     className := nonMetaClass name.
   495     className := nonMetaClass name.
   496 
   496 
   497     self startCollectChanges.
   497     self startCollectChanges.
   498 
   498 
   499     (nonMetaClass includesSelector:#'initialize') ifFalse:[
   499     (nonMetaClass includesSelector:#initialize) ifFalse:[
   500         code :=
   500         code :=
   501 'initialize
   501 'initialize
   502     "Invoked when a new instance is created."
   502     "Invoked when a new instance is created."
   503 
   503 
   504     "/ please change as required (and remove this comment)
   504     "/ please change as required (and remove this comment)
   523         ].
   523         ].
   524 
   524 
   525         self 
   525         self 
   526             compile:code
   526             compile:code
   527             forClass:nonMetaClass 
   527             forClass:nonMetaClass 
   528             inCategory:'initialization'.
   528             inCategory:#initialization.
   529     ].
   529     ].
   530 
   530 
   531     self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
   531     self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
   532 !
   532 !
   533 
   533 
   542 
   542 
   543     self startCollectChanges.
   543     self startCollectChanges.
   544 
   544 
   545     self createInitializationMethodIn:aClass.
   545     self createInitializationMethodIn:aClass.
   546 
   546 
   547     (metaClass includesSelector:#'new') ifFalse:[
   547     (metaClass includesSelector:#new) ifFalse:[
   548         m := metaClass responseTo:#new.
   548         m := metaClass responseTo:#new.
   549         (m isNil 
   549         (m isNil 
   550         or:[ (m sends:#initialize) not 
   550         or:[ (m sends:#initialize) not 
   551         or:[ 
   551         or:[ 
   552             (Dialog 
   552             (Dialog 
   561     ^ self basicNew initialize.
   561     ^ self basicNew initialize.
   562 '.
   562 '.
   563             self 
   563             self 
   564                 compile:code
   564                 compile:code
   565                 forClass:metaClass 
   565                 forClass:metaClass 
   566                 inCategory:'instance creation'.
   566                 inCategory:#'instance creation'.
   567         ].
   567         ].
   568     ].
   568     ].
   569 
   569 
   570     self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
   570     self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className).
   571 
   571 
   613         ].
   613         ].
   614 
   614 
   615         self 
   615         self 
   616             compile:code
   616             compile:code
   617             forClass:nonMetaClass 
   617             forClass:nonMetaClass 
   618             inCategory:'initialization'.
   618             inCategory:#initialization.
   619     ].
   619     ].
   620 
   620 
   621     (metaClass includesSelector:selector) ifFalse:[
   621     (metaClass includesSelector:selector) ifFalse:[
   622         m := metaClass responseTo:selector.
   622         m := metaClass responseTo:selector.
   623         (m isNil 
   623         (m isNil 
   630     ^ self basicNew initialize',dfn asUppercaseFirst,'
   630     ^ self basicNew initialize',dfn asUppercaseFirst,'
   631 '.
   631 '.
   632             self 
   632             self 
   633                 compile:code
   633                 compile:code
   634                 forClass:metaClass 
   634                 forClass:metaClass 
   635                 inCategory:'instance creation'.
   635                 inCategory:#'instance creation'.
   636         ].
   636         ].
   637     ].
   637     ].
   638 
   638 
   639     self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className).
   639     self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className).
   640 !
   640 !
   641 
   641 
   642 createPoolInitializationCodeFor:aClass
   642 createPoolInitializationCodeFor:aClass
   643     |nonMetaClass metaClass className poolVars code initCode runValue maxValue|
   643     |nonMetaClass metaClass className poolVars initCode|
   644 
   644 
   645     self startCollectChanges.
   645     self startCollectChanges.
   646 
   646 
   647     nonMetaClass := aClass theNonMetaclass.
   647     nonMetaClass := aClass theNonMetaclass.
   648     metaClass := aClass theMetaclass.
   648     metaClass := aClass theMetaclass.
   675     initCode nextPutLine:'    "'.
   675     initCode nextPutLine:'    "'.
   676 
   676 
   677     self
   677     self
   678         compile:(initCode contents)
   678         compile:(initCode contents)
   679         forClass:metaClass 
   679         forClass:metaClass 
   680         inCategory:'class initialization'.
   680         inCategory:#'class initialization'.
   681 
   681 
   682     self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className).
   682     self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className).
   683 
   683 
   684     aClass initialize.
   684     aClass initialize.
   685 
   685 
   703     ^ super new.
   703     ^ super new.
   704 '.
   704 '.
   705         self 
   705         self 
   706             compile:code
   706             compile:code
   707             forClass:metaClass 
   707             forClass:metaClass 
   708             inCategory:'redefined instance creation'.
   708             inCategory:#'redefined instance creation'.
   709     ].
   709     ].
   710     (metaClass includesSelector:#'new:') ifFalse:[
   710     (metaClass includesSelector:#'new:') ifFalse:[
   711         code :=
   711         code :=
   712 'new:n
   712 'new:n
   713     ^ super new:n.
   713     ^ super new:n.
   714 '.
   714 '.
   715         self 
   715         self 
   716             compile:code
   716             compile:code
   717             forClass:metaClass 
   717             forClass:metaClass 
   718             inCategory:'redefined instance creation'.
   718             inCategory:#'redefined instance creation'.
   719     ].
   719     ].
   720 
   720 
   721     self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className).
   721     self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className).
   722 !
   722 !
   723 
   723 
   731     metaClass := aClass theMetaclass.
   731     metaClass := aClass theMetaclass.
   732     className := nonMetaClass name.
   732     className := nonMetaClass name.
   733 
   733 
   734     self startCollectChanges.
   734     self startCollectChanges.
   735 
   735 
   736     (metaClass includesSelector:#'theOneAndOnlyInstance') ifFalse:[
   736     (metaClass includesSelector:#theOneAndOnlyInstance) ifFalse:[
   737         code :=
   737         code :=
   738 'theOneAndOnlyInstance
   738 'theOneAndOnlyInstance
   739     "returns a singleton"
   739     "returns a singleton"
   740 
   740 
   741     %1 isNil ifTrue:[
   741     %1 isNil ifTrue:[
   744     ^ %1.
   744     ^ %1.
   745 '.
   745 '.
   746         self 
   746         self 
   747             compile:(code bindWith:varName)
   747             compile:(code bindWith:varName)
   748             forClass:metaClass 
   748             forClass:metaClass 
   749             inCategory:'instance creation'.
   749             inCategory:#'instance creation'.
   750     ].
   750     ].
   751 
   751 
   752     (metaClass includesSelector:#'new') ifFalse:[
   752     (metaClass includesSelector:#new) ifFalse:[
   753         code :=
   753         code :=
   754 'new
   754 'new
   755     "returns a singleton"
   755     "returns a singleton"
   756 
   756 
   757     ^ self theOneAndOnlyInstance.
   757     ^ self theOneAndOnlyInstance.
   758 '.
   758 '.
   759         self 
   759         self 
   760             compile:(code bindWith:varName)
   760             compile:(code bindWith:varName)
   761             forClass:metaClass 
   761             forClass:metaClass 
   762             inCategory:'instance creation'.
   762             inCategory:#'instance creation'.
   763     ].
   763     ].
   764 
   764 
   765    (metaClass includesSelector:#'flushSingleton') ifFalse:[
   765    (metaClass includesSelector:#flushSingleton) ifFalse:[
   766         code :=
   766         code :=
   767 'flushSingleton
   767 'flushSingleton
   768     "flushes the cached singleton"
   768     "flushes the cached singleton"
   769 
   769 
   770     %1 := nil
   770     %1 := nil
   774     "
   774     "
   775 '.
   775 '.
   776         self 
   776         self 
   777             compile:(code bindWith:varName)
   777             compile:(code bindWith:varName)
   778             forClass:metaClass 
   778             forClass:metaClass 
   779             inCategory:'instance creation'.
   779             inCategory:#'instance creation'.
   780     ].
   780     ].
   781 
   781 
   782     self executeCollectedChangesNamed:('Singleton Pattern for ' , className).
   782     self executeCollectedChangesNamed:('Singleton Pattern for ' , className).
   783 
   783 
   784     "Created: / 10-02-2011 / 16:32:48 / cg"
   784     "Created: / 10-02-2011 / 16:32:48 / cg"
   791 
   791 
   792     nonMetaClass := aClass theNonMetaclass.
   792     nonMetaClass := aClass theNonMetaclass.
   793 
   793 
   794     self startCollectChanges.
   794     self startCollectChanges.
   795 
   795 
   796     (nonMetaClass includesSelector:#'printOn:') ifFalse:[
   796     (nonMetaClass includesSelector:#printOn:) ifFalse:[
   797         code :=
   797         code :=
   798 'printOn:aStream
   798 'printOn:aStream
   799     "append a printed representation if the receiver to the argument, aStream"
   799     "append a printed representation if the receiver to the argument, aStream"
   800 
   800 
   801     super printOn:aStream.
   801     super printOn:aStream.
   812         ].
   812         ].
   813 
   813 
   814         self 
   814         self 
   815             compile:code
   815             compile:code
   816             forClass:nonMetaClass 
   816             forClass:nonMetaClass 
   817             inCategory:'printing & storing'.
   817             inCategory:#'printing & storing'.
   818     ].
   818     ].
   819 
   819 
   820 
   820 
   821     self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name).
   821     self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name).
   822 
   822 
   859             ifTrue: [anApplicationClassOrNil name]
   859             ifTrue: [anApplicationClassOrNil name]
   860             ifFalse: [className.].
   860             ifFalse: [className.].
   861         self
   861         self
   862             compile:(source bindWith:anApplicationClassNameOrStartupClassName)
   862             compile:(source bindWith:anApplicationClassNameOrStartupClassName)
   863             forClass:metaClass 
   863             forClass:metaClass 
   864             inCategory:'startup'.
   864             inCategory:#startup.
   865     ].
   865     ].
   866     self executeCollectedChangesNamed:('Add Startup Code to ' , className).
   866     self executeCollectedChangesNamed:('Add Startup Code to ' , className).
   867 !
   867 !
   868 
   868 
   869 createTestCaseSampleCodeFor:aClass
   869 createTestCaseSampleCodeFor:aClass
   895      self run:#test1
   895      self run:#test1
   896      self new test1
   896      self new test1
   897     "
   897     "
   898 '
   898 '
   899             forClass:nonMetaClass 
   899             forClass:nonMetaClass 
   900             inCategory:'tests'.
   900             inCategory:#tests.
   901     ].
   901     ].
   902 
   902 
   903     ( nonMetaClass includesSelector:#test2 ) ifFalse:[
   903     ( nonMetaClass includesSelector:#test2 ) ifFalse:[
   904         self
   904         self
   905             compile:
   905             compile:
   918      self run:#test2
   918      self run:#test2
   919      self new test2
   919      self new test2
   920     "
   920     "
   921 '
   921 '
   922             forClass:nonMetaClass 
   922             forClass:nonMetaClass 
   923             inCategory:'tests'.
   923             inCategory:#tests.
   924     ].
   924     ].
   925 
   925 
   926     ( nonMetaClass includesSelector:#test3 ) ifFalse:[
   926     ( nonMetaClass includesSelector:#test3 ) ifFalse:[
   927         self
   927         self
   928             compile:
   928             compile:
   941      self run:#test3
   941      self run:#test3
   942      self new test3
   942      self new test3
   943     "
   943     "
   944 '
   944 '
   945             forClass:nonMetaClass 
   945             forClass:nonMetaClass 
   946             inCategory:'tests'.
   946             inCategory:#tests.
   947     ].
   947     ].
   948 
   948 
   949     ( nonMetaClass includesSelector:#setUp ) ifFalse:[
   949     ( nonMetaClass includesSelector:#setUp ) ifFalse:[
   950         self
   950         self
   951             compile:
   951             compile:
   953     "common setup - invoked before testing."
   953     "common setup - invoked before testing."
   954 
   954 
   955     super setUp
   955     super setUp
   956 '
   956 '
   957             forClass:nonMetaClass 
   957             forClass:nonMetaClass 
   958             inCategory:'initialize / release'.
   958             inCategory:#'initialize / release'.
   959     ].
   959     ].
   960 
   960 
   961     ( nonMetaClass includesSelector:#tearDown ) ifFalse:[
   961     ( nonMetaClass includesSelector:#tearDown ) ifFalse:[
   962         self
   962         self
   963             compile:
   963             compile:
   965     "common cleanup - invoked after testing."
   965     "common cleanup - invoked after testing."
   966 
   966 
   967     super tearDown
   967     super tearDown
   968 '
   968 '
   969             forClass:nonMetaClass 
   969             forClass:nonMetaClass 
   970             inCategory:'initialize / release'.
   970             inCategory:#'initialize / release'.
   971     ]
   971     ]
   972 !
   972 !
   973 
   973 
   974 createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass
   974 createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass
   975     "create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)"
   975     "create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)"
   993     "fall back to general object-case - please change as required"
   993     "fall back to general object-case - please change as required"
   994 
   994 
   995     ^ self visitObject:anObject
   995     ^ self visitObject:anObject
   996 ') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst)
   996 ') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst)
   997             forClass:visitorClass 
   997             forClass:visitorClass 
   998             inCategory:'visiting'.
   998             inCategory:#visiting.
   999     ].
   999     ].
  1000 
  1000 
  1001     (visitorClass includesSelector:#'visitObject:') ifFalse:[
  1001     (visitorClass includesSelector:#visitObject:) ifFalse:[
  1002         self 
  1002         self 
  1003             compile:
  1003             compile:
  1004 ('visitObject:anObject 
  1004 ('visitObject:anObject 
  1005     "dispatched back from the visited objects (visitor pattern)"
  1005     "dispatched back from the visited objects (visitor pattern)"
  1006 
  1006 
  1007     "general fallBack - please change as required"
  1007     "general fallBack - please change as required"
  1008 
  1008 
  1009     self halt:''not yet implemented''
  1009     self halt:''not yet implemented''
  1010 ')
  1010 ')
  1011             forClass:visitorClass 
  1011             forClass:visitorClass 
  1012             inCategory:'visiting'.
  1012             inCategory:#visiting.
  1013     ].
  1013     ].
  1014 
  1014 
  1015     (visitorClass includesSelector:#'visit:') ifFalse:[
  1015     (visitorClass includesSelector:#visit:) ifFalse:[
  1016         self 
  1016         self 
  1017             compile:
  1017             compile:
  1018 ('visit:anObject 
  1018 ('visit:anObject 
  1019     "visit anObject (visitor pattern).
  1019     "visit anObject (visitor pattern).
  1020      The object should call back one of my visitXXXX methods."
  1020      The object should call back one of my visitXXXX methods."
  1021 
  1021 
  1022     ^ anObject acceptVisitor:self
  1022     ^ anObject acceptVisitor:self
  1023 ')
  1023 ')
  1024             forClass:visitorClass 
  1024             forClass:visitorClass 
  1025             inCategory:'visiting'.
  1025             inCategory:#visiting.
  1026     ].
  1026     ].
  1027 
  1027 
  1028     self executeCollectedChangesNamed:('Add Visitor Pattern').
  1028     self executeCollectedChangesNamed:('Add Visitor Pattern').
  1029 !
  1029 !
  1030 
  1030 
  1042     (metaClass includesSelector:#pageSpec) ifFalse:[
  1042     (metaClass includesSelector:#pageSpec) ifFalse:[
  1043         txt := self class initialPageSpecMethodSourceForWebApplications.
  1043         txt := self class initialPageSpecMethodSourceForWebApplications.
  1044         self
  1044         self
  1045             compile:(txt bindWith:className)
  1045             compile:(txt bindWith:className)
  1046             forClass:metaClass 
  1046             forClass:metaClass 
  1047             inCategory:'page specs'.
  1047             inCategory:#'page specs'.
  1048     ].
  1048     ].
  1049 
  1049 
  1050     self executeCollectedChangesNamed:('Add WebApplication Code for ' , className).
  1050     self executeCollectedChangesNamed:('Add WebApplication Code for ' , className).
  1051 
  1051 
  1052     "Modified: / 1.2.1998 / 16:10:03 / cg"
  1052     "Modified: / 1.2.1998 / 16:10:03 / cg"
  1083     response nextPutLine:''</HTML>''.
  1083     response nextPutLine:''</HTML>''.
  1084 '.
  1084 '.
  1085         self
  1085         self
  1086             compile:txt
  1086             compile:txt
  1087             forClass:nonMetaClass 
  1087             forClass:nonMetaClass 
  1088             inCategory:'response generation - pages'.
  1088             inCategory:#'response generation - pages'.
  1089     ].
  1089     ].
  1090 
  1090 
  1091     (nonMetaClass includesSelector:#page2:) ifFalse:[
  1091     (nonMetaClass includesSelector:#page2:) ifFalse:[
  1092         txt :=
  1092         txt :=
  1093 'page2:aRequest
  1093 'page2:aRequest
  1117     aRequest reply:(page htmlString).
  1117     aRequest reply:(page htmlString).
  1118 '.
  1118 '.
  1119         self
  1119         self
  1120             compile:txt
  1120             compile:txt
  1121             forClass:nonMetaClass 
  1121             forClass:nonMetaClass 
  1122             inCategory:'response generation - pages'.
  1122             inCategory:#'response generation - pages'.
  1123     ].
  1123     ].
  1124 
  1124 
  1125     (nonMetaClass includesSelector:#page3:) ifFalse:[
  1125     (nonMetaClass includesSelector:#page3:) ifFalse:[
  1126         txt :=
  1126         txt :=
  1127 'page3:aRequest
  1127 'page3:aRequest
  1133 without any html formatting.''
  1133 without any html formatting.''
  1134 '.
  1134 '.
  1135         self
  1135         self
  1136             compile:txt
  1136             compile:txt
  1137             forClass:nonMetaClass 
  1137             forClass:nonMetaClass 
  1138             inCategory:'response generation - pages'.
  1138             inCategory:#'response generation - pages'.
  1139     ].
  1139     ].
  1140 
  1140 
  1141     (nonMetaClass includesSelector:#process:) ifFalse:[
  1141     (nonMetaClass includesSelector:#process:) ifFalse:[
  1142         txt :=
  1142         txt :=
  1143 'process:aRequest
  1143 'process:aRequest
  1169     aRequest reportNotFound:''No such page in this service''.
  1169     aRequest reportNotFound:''No such page in this service''.
  1170 '.
  1170 '.
  1171         self
  1171         self
  1172             compile:txt
  1172             compile:txt
  1173             forClass:nonMetaClass 
  1173             forClass:nonMetaClass 
  1174             inCategory:'response generation'.
  1174             inCategory:#'response generation'.
  1175     ].
  1175     ].
  1176 
  1176 
  1177     (metaClass includesSelector:#linkName) ifFalse:[
  1177     (metaClass includesSelector:#linkName) ifFalse:[
  1178         txt :=
  1178         txt :=
  1179 'linkName
  1179 'linkName
  1182     ^ ''/NewService''
  1182     ^ ''/NewService''
  1183 '.
  1183 '.
  1184         self
  1184         self
  1185             compile:txt
  1185             compile:txt
  1186             forClass:metaClass 
  1186             forClass:metaClass 
  1187             inCategory:'defaults'.
  1187             inCategory:#defaults.
  1188     ].
  1188     ].
  1189 
  1189 
  1190     (metaClass includesSelector:#settingsApplicationClass) ifFalse:[
  1190     (metaClass includesSelector:#settingsApplicationClass) ifFalse:[
  1191         txt :=
  1191         txt :=
  1192 'settingsApplicationClass
  1192 'settingsApplicationClass
  1195     ^ nil
  1195     ^ nil
  1196 '.
  1196 '.
  1197         self
  1197         self
  1198             compile:txt
  1198             compile:txt
  1199             forClass:metaClass 
  1199             forClass:metaClass 
  1200             inCategory:'defaults'.
  1200             inCategory:#defaults.
  1201     ].
  1201     ].
  1202 
  1202 
  1203 
  1203 
  1204     self executeCollectedChangesNamed:('Add WebService Code for ' , className).
  1204     self executeCollectedChangesNamed:('Add WebService Code for ' , className).
  1205 
  1205 
  1229                     inCategory:category.
  1229                     inCategory:category.
  1230             ]
  1230             ]
  1231         ].
  1231         ].
  1232 
  1232 
  1233     #(
  1233     #(
  1234         #'initialize'               #code_forWidget_initialize  'initialization & release'
  1234         initialize               code_forWidget_initialize  #'initialization & release'
  1235         #'update:with:from:'        #code_forWidget_update      'change & update'
  1235         update:with:from:        code_forWidget_update      #'change & update'
  1236         #'redrawX:y:width:height:'  #code_forWidget_redraw      'drawing'
  1236         redrawX:y:width:height:  code_forWidget_redraw      #'drawing'
  1237         #'buttonPress:x:y:'         #code_forWidget_buttonPress 'event handling'
  1237         buttonPress:x:y:         code_forWidget_buttonPress #'event handling'
  1238         #'keyPress:x:y:'            #code_forWidget_keyPress    'event handling'
  1238         keyPress:x:y:            code_forWidget_keyPress    #'event handling'
  1239         #'sizeChanged:'             #code_forWidget_sizeChanged 'event handling'
  1239         sizeChanged:             code_forWidget_sizeChanged #'event handling'
  1240     ) inGroupsOf:3 do:compileTemplateAction.
  1240     ) inGroupsOf:3 do:compileTemplateAction.
  1241 
  1241 
  1242     self executeCollectedChangesNamed:('Add Widget Code for ' , className).
  1242     self executeCollectedChangesNamed:('Add Widget Code for ' , className).
  1243 ! !
  1243 ! !
  1244 
  1244 
  1319                         source := source
  1319                         source := source
  1320                                     , '    ^ %2'.
  1320                                     , '    ^ %2'.
  1321                     ].
  1321                     ].
  1322                 ].
  1322                 ].
  1323                 source := (source bindWith:varType with:name with:defaultMethodName) withCRs.
  1323                 source := (source bindWith:varType with:name with:defaultMethodName) withCRs.
  1324                 self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']).
  1324                 self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:[#aspects] ifFalse:[#accessing]).
  1325             ] ifTrue:[
  1325             ] ifTrue:[
  1326                 Transcript showCR:'method ''', methodName , ''' already present'
  1326                 Transcript showCR:'method ''', methodName , ''' already present'
  1327             ].
  1327             ].
  1328 
  1328 
  1329             "/ default for lazy on class side
  1329             "/ default for lazy on class side
  1335                     ].
  1335                     ].
  1336                     source := source    
  1336                     source := source    
  1337                                , '    self shouldImplement.\'
  1337                                , '    self shouldImplement.\'
  1338                                , '    ^ nil.'.
  1338                                , '    ^ nil.'.
  1339                     source := (source bindWith:varType with:name) withCRs.
  1339                     source := (source bindWith:varType with:name) withCRs.
  1340                     self compile:source forClass:aClass theMetaclass inCategory:'defaults'.
  1340                     self compile:source forClass:aClass theMetaclass inCategory:#defaults.
  1341                 ].
  1341                 ].
  1342             ].
  1342             ].
  1343         ].
  1343         ].
  1344 
  1344 
  1345         "/ the SETTER
  1345         "/ the SETTER
  1396                 ].
  1396                 ].
  1397                 source := (source bindWith:varType with:name with:argName) withCRs.
  1397                 source := (source bindWith:varType with:name with:argName) withCRs.
  1398                 self 
  1398                 self 
  1399                     compile:source 
  1399                     compile:source 
  1400                     forClass:aClass 
  1400                     forClass:aClass 
  1401                     inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']).
  1401                     inCategory:(asValueHolder ifTrue:[#aspects] ifFalse:[#accessing]).
  1402             ] ifTrue:[
  1402             ] ifTrue:[
  1403                 Transcript showCR:'method ''', methodName , ':'' already present'
  1403                 Transcript showCR:'method ''', methodName , ':'' already present'
  1404             ].
  1404             ].
  1405         ].
  1405         ].
  1406     ].
  1406     ].
  1442                            , '        %2 := OrderedCollection new.\'.
  1442                            , '        %2 := OrderedCollection new.\'.
  1443             source := source
  1443             source := source
  1444                        , '    ].\'
  1444                        , '    ].\'
  1445                        , '    %2 add: a%1'.
  1445                        , '    %2 add: a%1'.
  1446             source := (source bindWith:methodNameBase with:name) withCRs.
  1446             source := (source bindWith:methodNameBase with:name) withCRs.
  1447             self compile:source forClass:aClass inCategory:'accessing'.
  1447             self compile:source forClass:aClass inCategory:#accessing.
  1448         ] ifTrue:[
  1448         ] ifTrue:[
  1449             Transcript showCR:'method ''', methodName , ''' already present'
  1449             Transcript showCR:'method ''', methodName , ''' already present'
  1450         ].
  1450         ].
  1451 
  1451 
  1452         methodName := 'remove' , methodNameBase, ':'. 
  1452         methodName := 'remove' , methodNameBase, ':'. 
  1458                 source := source , '    "remove a ',methodNameBase,'"\\'. 
  1458                 source := source , '    "remove a ',methodNameBase,'"\\'. 
  1459             ].
  1459             ].
  1460             source := source
  1460             source := source
  1461                        , '    %2 remove: a%1'.
  1461                        , '    %2 remove: a%1'.
  1462             source := (source bindWith:methodNameBase with:name) withCRs.
  1462             source := (source bindWith:methodNameBase with:name) withCRs.
  1463             self compile:source forClass:aClass inCategory:'accessing'.
  1463             self compile:source forClass:aClass inCategory:#accessing.
  1464         ] ifTrue:[
  1464         ] ifTrue:[
  1465             Transcript showCR:'method ''', methodName , ''' already present'
  1465             Transcript showCR:'method ''', methodName , ''' already present'
  1466         ].
  1466         ].
  1467     ].
  1467     ].
  1468 
  1468 
  1515                 generateComments ifTrue:[
  1515                 generateComments ifTrue:[
  1516                     source := source , '    "return the value in ''%2''"\\'. 
  1516                     source := source , '    "return the value in ''%2''"\\'. 
  1517                 ].
  1517                 ].
  1518                 source := source , '    ^ self %2 value'.
  1518                 source := source , '    ^ self %2 value'.
  1519                 source := (source bindWith:methodName with:holderMethodName) withCRs.
  1519                 source := (source bindWith:methodName with:holderMethodName) withCRs.
  1520                 self compile:source forClass:nonMetaClass inCategory:('accessing').
  1520                 self compile:source forClass:nonMetaClass inCategory:#accessing.
  1521             ] ifTrue:[
  1521             ] ifTrue:[
  1522                 Transcript showCR:'method ''', methodName , ''' already present'
  1522                 Transcript showCR:'method ''', methodName , ''' already present'
  1523             ].
  1523             ].
  1524 
  1524 
  1525             (metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[
  1525             (metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[
  1527                 generateComments ifTrue:[
  1527                 generateComments ifTrue:[
  1528                     source := source , '    "set the value in ''%2''"\\'. 
  1528                     source := source , '    "set the value in ''%2''"\\'. 
  1529                 ].
  1529                 ].
  1530                 source := source , '    self %2 value: newValue'.
  1530                 source := source , '    self %2 value: newValue'.
  1531                 source := (source bindWith:methodName with:holderMethodName) withCRs.
  1531                 source := (source bindWith:methodName with:holderMethodName) withCRs.
  1532                 self compile:source forClass:nonMetaClass inCategory:('accessing').
  1532                 self compile:source forClass:nonMetaClass inCategory:#accessing.
  1533             ] ifTrue:[
  1533             ] ifTrue:[
  1534                 Transcript showCR:'method ''', methodName , ':'' already present'
  1534                 Transcript showCR:'method ''', methodName , ':'' already present'
  1535             ].
  1535             ].
  1536         ].
  1536         ].
  1537         (metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[
  1537         (metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[
  1542             source := source , '    %1 isNil ifTrue:[\'.
  1542             source := source , '    %1 isNil ifTrue:[\'.
  1543             source := source , '        %1 := ValueHolder with:nil "defaultValue here".\'.
  1543             source := source , '        %1 := ValueHolder with:nil "defaultValue here".\'.
  1544             source := source , '    ].\'.
  1544             source := source , '    ].\'.
  1545             source := source , '    ^ %1\'.
  1545             source := source , '    ^ %1\'.
  1546             source := (source bindWith:holderMethodName) withCRs.
  1546             source := (source bindWith:holderMethodName) withCRs.
  1547             self compile:source forClass:nonMetaClass inCategory:('accessing').
  1547             self compile:source forClass:nonMetaClass inCategory:#accessing.
  1548         ] ifTrue:[
  1548         ] ifTrue:[
  1549             Transcript showCR:'method ''', methodName , ''' already present'
  1549             Transcript showCR:'method ''', methodName , ''' already present'
  1550         ].
  1550         ].
  1551     ].
  1551     ].
  1552 
  1552 
  1571     "stub code automatically generated - please change if required"
  1571     "stub code automatically generated - please change if required"
  1572 
  1572 
  1573     ^ aVisitor %1self
  1573     ^ aVisitor %1self
  1574 ') bindWith:selector)
  1574 ') bindWith:selector)
  1575             forClass:aClass 
  1575             forClass:aClass 
  1576             inCategory:'visiting'.
  1576             inCategory:#visiting.
  1577     ]
  1577     ]
  1578 !
  1578 !
  1579 
  1579 
  1580 createAcceptVisitorMethodIn:aClass
  1580 createAcceptVisitorMethodIn:aClass
  1581     "create an acceptVisitor: method
  1581     "create an acceptVisitor: method
  1599 'copyright
  1599 'copyright
  1600 "
  1600 "
  1601 ' , txt , '
  1601 ' , txt , '
  1602 "
  1602 "
  1603 '             forClass:aClass 
  1603 '             forClass:aClass 
  1604               inCategory:'documentation'.
  1604               inCategory:#documentation.
  1605         ]
  1605         ]
  1606     ].
  1606     ].
  1607 !
  1607 !
  1608 
  1608 
  1609 createDocumentationMethodFor:aClass
  1609 createDocumentationMethodFor:aClass
  1678         ].
  1678         ].
  1679 
  1679 
  1680         self 
  1680         self 
  1681             compile:code
  1681             compile:code
  1682             forClass:metaClass 
  1682             forClass:metaClass 
  1683             inCategory:'documentation'.
  1683             inCategory:#documentation.
  1684     ].
  1684     ].
  1685 
  1685 
  1686     "Modified: / 24-11-2006 / 15:54:27 / cg"
  1686     "Modified: / 24-11-2006 / 15:54:27 / cg"
  1687     "Modified: / 04-02-2011 / 08:24:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1687     "Modified: / 04-02-2011 / 08:24:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1688 !
  1688 !
  1727     ... executable example here ...
  1727     ... executable example here ...
  1728                                                                 [exEnd]
  1728                                                                 [exEnd]
  1729 "
  1729 "
  1730 '                   
  1730 '                   
  1731             forClass:aClass 
  1731             forClass:aClass 
  1732             inCategory:'documentation'.
  1732             inCategory:#documentation.
  1733     ].
  1733     ].
  1734 !
  1734 !
  1735 
  1735 
  1736 createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel
  1736 createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel
  1737     |imageStoreStream mthd imageKey category|
  1737     |imageStoreStream mthd imageKey category|
  1738 
  1738 
  1739     anImage storeOn: (imageStoreStream := WriteStream on: '').
  1739     anImage storeOn: (imageStoreStream := WriteStream on: '').
  1740 
  1740 
  1741     "/ if that method already exists, do not overwrite the category
  1741     "/ if that method already exists, do not overwrite the category
  1742     category := 'image specs'.
  1742     category := #'image specs'.
  1743     (mthd := aClass compiledMethodAt:sel) notNil ifTrue:[
  1743     (mthd := aClass compiledMethodAt:sel) notNil ifTrue:[
  1744         category := mthd category.
  1744         category := mthd category.
  1745     ].
  1745     ].
  1746 
  1746 
  1747     imageKey :=  (aClass name, ' ', sel) asSymbol.
  1747     imageKey :=  aClass theNonMetaclass name, ' ', sel.
  1748     Icon constantNamed: imageKey put:nil.
  1748     Icon constantNamed: imageKey put:nil.
  1749     self
  1749     self
  1750         compile: ((sel,
  1750         compile: ((sel,
  1751             '\', comment,
  1751             '\', comment,
  1752             '\\' , 
  1752             '\\' , 
  1777         HistoryManager notNil ifTrue:[
  1777         HistoryManager notNil ifTrue:[
  1778             code := HistoryManager codeForInitialHistoryMethodIn:aClass.
  1778             code := HistoryManager codeForInitialHistoryMethodIn:aClass.
  1779             self
  1779             self
  1780                 compile:code
  1780                 compile:code
  1781                 forClass:aClass 
  1781                 forClass:aClass 
  1782                 inCategory:'documentation'.
  1782                 inCategory:#documentation.
  1783         ].
  1783         ].
  1784     ].
  1784     ].
  1785 !
  1785 !
  1786 
  1786 
  1787 createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass
  1787 createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass
  1823         source := source , ('    "set instance variables"' , Character cr , Character cr).
  1823         source := source , ('    "set instance variables"' , Character cr , Character cr).
  1824     ].
  1824     ].
  1825     aCollectionOfVarNames do:[:eachVar |
  1825     aCollectionOfVarNames do:[:eachVar |
  1826         source := source , ('    ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr).
  1826         source := source , ('    ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr).
  1827     ].
  1827     ].
  1828     self compile:source forClass:aClass inCategory:'accessing'.
  1828     self compile:source forClass:aClass inCategory:#accessing.
  1829 !
  1829 !
  1830 
  1830 
  1831 createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass
  1831 createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass
  1832     "add a subclassResponsibility method;
  1832     "add a subclassResponsibility method;
  1833      but only if not already present."
  1833      but only if not already present."
  1850     "create an update:with:from:-method
  1850     "create an update:with:from:-method
  1851      (I'm tired of typing)"
  1851      (I'm tired of typing)"
  1852 
  1852 
  1853     |code|
  1853     |code|
  1854 
  1854 
  1855     (aClass includesSelector:#'update:with:from:') ifFalse:[
  1855     (aClass includesSelector:#update:with:from:) ifFalse:[
  1856         generateComments ifFalse:[
  1856         generateComments ifFalse:[
  1857             code :=
  1857             code :=
  1858 'update:something with:aParameter from:changedObject
  1858 'update:something with:aParameter from:changedObject
  1859     super update:something with:aParameter from:changedObject
  1859     super update:something with:aParameter from:changedObject
  1860 '
  1860 '
  1874         ].
  1874         ].
  1875 
  1875 
  1876         self 
  1876         self 
  1877             compile:code
  1877             compile:code
  1878             forClass:aClass 
  1878             forClass:aClass 
  1879             inCategory:'change & update'.
  1879             inCategory:#'change & update'.
  1880     ]
  1880     ]
  1881 !
  1881 !
  1882 
  1882 
  1883 createVersionMethodFor:aClass
  1883 createVersionMethodFor:aClass
  1884     <resource: #obsolete>
  1884     <resource: #obsolete>
  1898                 code:= ('version\    ^ ''$' , 'Header$''') withCRs
  1898                 code:= ('version\    ^ ''$' , 'Header$''') withCRs
  1899             ].
  1899             ].
  1900             self 
  1900             self 
  1901                 compile:code
  1901                 compile:code
  1902                 forClass:aClass 
  1902                 forClass:aClass 
  1903                 inCategory:'documentation'.
  1903                 inCategory:#documentation.
  1904         ]
  1904         ]
  1905     ].
  1905     ].
  1906 ! !
  1906 ! !
  1907 
  1907 
  1908 !SmalltalkCodeGeneratorTool methodsFor:'code templates'!
  1908 !SmalltalkCodeGeneratorTool methodsFor:'code templates'!
  2491 ! !
  2491 ! !
  2492 
  2492 
  2493 !SmalltalkCodeGeneratorTool class methodsFor:'documentation'!
  2493 !SmalltalkCodeGeneratorTool class methodsFor:'documentation'!
  2494 
  2494 
  2495 version
  2495 version
  2496     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.12 2012-01-27 13:55:22 cg Exp $'
  2496     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.13 2012-05-22 16:33:26 stefan Exp $'
  2497 !
  2497 !
  2498 
  2498 
  2499 version_CVS
  2499 version_CVS
  2500     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.12 2012-01-27 13:55:22 cg Exp $'
  2500     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.13 2012-05-22 16:33:26 stefan Exp $'
  2501 !
  2501 !
  2502 
  2502 
  2503 version_SVN
  2503 version_SVN
  2504     ^ '§Id§'
  2504     ^ '§Id§'
  2505 ! !
  2505 ! !