formatting code utility

Sam Adams ssadams at us.ibm.com
Fri Feb 13 14:58:37 UTC 1998


Don't forget the metaclass methods!  I can't tell you how many times I forget
this when I write code generators.

" formats and accepts all methods in a class and its metaclass "
| ssClass rawCode fmtCode aComp ssMetaClass |
aComp _ Object compilerClass new.
" specify your class names in the array "
#(ClassSection Student Assignment) do:
    [:ssClassName |
    ssClass := Smalltalk classNamed: ssClassName.
    ssClass selectors do:
 [:each |
 rawCode := (ssClass sourceCodeAt: each).
 fmtCode := aComp format: rawCode in: ssClass notifying: nil.
 ssClass compile: fmtCode.
     " this leaves the method in the same category "
 ].

"ADDED to do the same for metaclass methods"
    ssMetaClass := ssClass class.
    ssMetaClass selectors do:
 [:each |
 rawCode := (ssMetaClass sourceCodeAt: each).
 fmtCode := aComp format: rawCode in: ssMetaClass notifying: nil.
 ssMetaClass compile: fmtCode.
     " this leaves the method in the same category "
 ].

    ]

Sam S. Adams, Distinguished Engineer, IBM Network Computing Software Division
tie line 444-0736, outside 919-254-0736, email: ssadams at us.ibm.com
<<Hebrews 11:6, Proverbs 3:5-6, Romans 1:16-17, I Corinthians 1:10>>




bolot at cc.gatech.edu on 02/13/98 01:21:07 AM
Please respond to squeak at cs.uiuc.edu @ internet
To: squeak at cs.uiuc.edu @ internet
cc:
Subject: formatting code utility


All of you might be using something like this already, but some may find
it useful (it was quicker to write this code than to format each method
individually!). The code below formats all methods in classes specified.


--
Bolot


" formats and accepts all methods "
| ssClass rawCode fmtCode aComp |
aComp _ Object compilerClass new.
" specify your class names in the array "
#(ClassSection Student Assignment) do:
    [:ssClassName |
    ssClass := Smalltalk classNamed: ssClassName.
    ssClass selectors do:
 [:each |
 rawCode := (ssClass sourceCodeAt: each).
 fmtCode := aComp format: rawCode in: ssClass notifying: nil.
 ssClass compile: fmtCode.
     " this leaves the method in the same category "
 ].
    ]





More information about the Squeak-dev mailing list