diff -r da1f6c48571a -r 7fb67608aa3e CodeGeneratorTool.st --- a/CodeGeneratorTool.st Mon Feb 11 15:23:12 2008 +0100 +++ b/CodeGeneratorTool.st Mon Feb 11 15:24:42 2008 +0100 @@ -117,6 +117,12 @@ ^ self new createWebApplicationCodeFor:aClass ! +createWebServiceCodeFor:aClass + "create an empty webService framework" + + ^ self new createWebServiceCodeFor:aClass +! + initialMenuSpecMethodSourceForApplications "return a menuSpec with typical stuff in it" @@ -209,6 +215,155 @@ '. ! +initialPageMenuSpec + "return a menuSpec with typical stuff in it" + + "This resource specification was automatically generated by the CodeGeneratorTool." + + "Do not manually edit this!! If it is corrupted, + the MenuEditor may not be able to read the specification." + + " + MenuEditor new openOnClass:%1 andSelector:#mainMenu + " + + + + ^ #(#Menu + #( + #(#MenuItem + #label: 'AAA' + #translateLabel: true + #submenu: + #(#Menu + #( + #(#MenuItem + #label: 'New' + #translateLabel: true + #value: #menuNew + ) + #(#MenuItem + #label: '-' + ) + #(#MenuItem + #label: 'Open...' + #translateLabel: true + #value: #menuOpen + ) + #(#MenuItem + #label: '-' + ) + #(#MenuItem + #label: 'Save' + #translateLabel: true + #value: #menuSave + ) + #(#MenuItem + #label: 'Save As...' + #translateLabel: true + #value: #menuSaveAs + ) + #(#MenuItem + #label: '-' + ) + #(#MenuItem + #label: 'Exit' + #translateLabel: true + #value: #closeRequest + ) + ) nil + nil + ) + ) + #(#MenuItem + #label: 'Help' + #translateLabel: true + #startGroup: #right + #submenu: + #(#Menu + #( + #(#MenuItem + #label: 'Documentation' + #translateLabel: true + #value: #openDocumentation + ) + #(#MenuItem + #label: '-' + ) + #(#MenuItem + #label: 'About this Application...' + #translateLabel: true + #value: #openAboutThisApplication + ) + ) nil + nil + ) + ) + ) nil + nil + ) +! + +initialPageMenuSpecMethodSourceForWebApplications + "return a menuSpec with typical stuff in it" + + ^ +'mainMenu + "This resource specification was automatically generated by the CodeGeneratorTool." + + "Do not manually edit this!! If it is corrupted, + the MenuEditor may not be able to read the specification." + + " + MenuEditor new openOnClass:%1 andSelector:#mainMenu + " + + + + ^ ',(self initialPageMenuSpec decodeAsLiteralArray literalArrayEncoding storeString),' +'. + + " + self initialPageMenuSpecMethodSourceForWebApplications + " +! + +initialPageSpecMethodSourceForWebApplications + "return an empty pageSpec" + + ^ +'pageSpec + "This resource specification was automatically generated by the CodeGeneratorTool." + + "Do not manually edit this!! If it is corrupted, + the UIPainter may not be able to read the specification." + + " + UIPainter new openOnClass:%1 andSelector:#windowSpec + " + + + + ^ #(#FullSpec + #window: + #(#WindowSpec + #name: ''%1'' + #layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) + #label: ''%1'' + #min: #(#Point 10 10) + #max: #(#Point 1024 768) + #bounds: #(#Rectangle 204 162 504 462) + #menu: #pageMenu + #usePreferredExtent: false + ) + #component: + #(#SpecCollection + #collection: #() + ) + ) +'. +! + initialWindowSpecMethodSourceForApplications "return an empty windowSpec with an initial menubar in it" @@ -409,6 +564,80 @@ ^ self new createVersionMethodFor:aClass ! ! +!CodeGeneratorTool class methodsFor:'code generation-menus'! + +createActionMethodFor:aSelector in:aClass category:aCategory redefine:redefine + |alreadyInSuperclass method code| + + (aClass includesSelector:aSelector) ifTrue:[ + ^ nil + ]. + + alreadyInSuperclass := aClass superclass canUnderstand:aSelector. + (alreadyInSuperclass and:[redefine not]) ifTrue:[ + ^ nil + ]. + + method := self methodNameTemplateFor:aSelector. + + code := '%1 + "automatically generated by UIEditor ..." + + "*** the code below performs no action" + "*** (except for some feedback on the Transcript)" + "*** Please change as required and accept in the browser." + "*** (and replace this comment by something more useful ;-)" + + "action to be added ..." + + Transcript showCR:self class name, '': action for #%2 ...''. +' bindWith:method with:aSelector. + + alreadyInSuperclass ifTrue:[ + code := code, (('\ super %1\' bindWith:method) withCRs). + ]. + self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). + ^ code +! + +createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine + |alreadyInSuperclass method code text| + + (aClass includesSelector:aSelector) ifTrue:[ + ^ nil + ]. + + alreadyInSuperclass := aClass superclass canUnderstand:aSelector. + (alreadyInSuperclass and:[redefine not]) ifTrue:[ + ^ nil + ]. + + method := self methodNameTemplateFor:aSelector. + + code := '%1 + "automatically generated by UIEditor ..." + + "*** the code below creates a default model when invoked" + "*** (which may not be the one you wanted)" + "*** Please change as required and accept in the browser." + "*** (and replace this comment by something more useful ;-)" + + "aspect to be added ..." + + Transcript showCR:self class name, '': aspect for #%2 ...''. + +' bindWith:method with:aSelector. + + alreadyInSuperclass ifTrue:[ + text := ' ^ super %1\' bindWith:method. + ] ifFalse:[ + text := ' ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector. + ]. + code := code, (text withCRs). + self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). + ^ code +! ! + !CodeGeneratorTool class methodsFor:'compilation'! compile:theCode forClass:aClass inCategory:cat @@ -426,6 +655,25 @@ ^ RefactoryChangeManager notNil and:[RefactoryChangeManager isLoaded and:[UserPreferences current useRefactoringSupport]] +! + +methodNameTemplateFor:aSelector + |numArgs method| + + numArgs := aSelector numArgs. + numArgs == 1 ifTrue:[ + method := aSelector, 'anArgument'. + ] ifFalse:[ + numArgs == 0 ifTrue:[ + method := aSelector + ] ifFalse:[ + method := ''. + aSelector keywords keysAndValuesDo:[:i :key| + method := method, key, 'arg', i printString, ' '. + ]. + ] + ]. + ^ method ! ! !CodeGeneratorTool methodsFor:'buld changes'! @@ -1100,10 +1348,34 @@ metaClass := aClass theMetaclass. className := nonMetaClass name. + (metaClass includesSelector:#pageSpec) ifFalse:[ + txt := self class initialPageSpecMethodSourceForWebApplications. + self + compile:(txt bindWith:className) + forClass:metaClass + inCategory:'page specs'. + ]. + + self executeCollectedChangesNamed:('Add WebApplication Code for ' , className). + + "Modified: / 1.2.1998 / 16:10:03 / cg" +! + +createWebServiceCodeFor:aClass + "create an empty webService framework" + + |nonMetaClass metaClass className txt| + + self startCollectChanges. + + nonMetaClass := aClass theNonMetaclass. + metaClass := aClass theMetaclass. + className := nonMetaClass name. + (nonMetaClass includesSelector:#process:) ifFalse:[ txt := 'process:aRequest - "This is the web applications main processing method. + "This is the web services main processing method. It will be invoked for every incoming webBrowser-request. The argument, aRequest contains the parameters (url, fields, parameters etc.)." @@ -1152,7 +1424,7 @@ ]. - self executeCollectedChangesNamed:('Add WebApplication Code for ' , className). + self executeCollectedChangesNamed:('Add WebService Code for ' , className). "Modified: / 1.2.1998 / 16:10:03 / cg" ! ! @@ -2102,5 +2374,5 @@ !CodeGeneratorTool class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.54 2008-02-06 09:32:26 cg Exp $' + ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.55 2008-02-11 14:24:42 cg Exp $' ! !