Rewriting 900 methods in a couple of lines

I got 900 methods that I wanted to rewrite so I hacked the ParseRewriter to do it for me 🙂
| rewriter node method testsels |
testsels := ReTest selectors select: [ :e | e beginsWith: ‘test’ ].
testsels
    do: [ :s | rewriter := RBParseTreeRewriter new.
                   rewriter
                        replace: ‘self shouldnt: [re compile] raise: Error’
                        with: ‘self compileIsOK’.
                   method := ReTest compiledMethodAt: s.
                   node := method parseTree.
                   (rewriter executeTree: node)
                   ifTrue: [
                       method origin
                           compile: node formattedCode
                           classified: method protocol ]]
Stef
Advertisements
%d bloggers like this: