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’ ].
    do: [ :s | rewriter := RBParseTreeRewriter new.
                        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 ]]
%d bloggers like this: