On 12/7/2015 5:27 PM, Hernán Morales Durand wrote:
but now I am failing to see how to replace #collect: with #collect:thenDo: using the rewriter:
You don't need to first search using the RBParseTreeSearcher. The RBParseTreeRewriter works with search patterns. What your code is really doing is searching for the literal pattern that it found from the RBParseTreeSearcher in the FooClass>>foo: method: aString asFileReference entries collect: [ : fileEntry | self openOnFileNamed: fileEntry fullName ] It then tries to replace it with the pattern: `@collection collect: `@arg1 thenDo: [ : fileEntry | index := index + 1. JobProgress progress: (0.1 * index); title: 'Procesing...', index asString ] However, since neither `@collection nor `@arg1 appear in your search pattern, you get an error. Here's a version that works: | cm rewriteRule replacement | cm := FooClass >> #foo:. replacement := '`@collection collect: `@arg1 thenDo: [ : fileEntry | index := index + 1. JobProgress progress: (0.1 * index); title: ''Procesing...'', index asString ]'. rewriteRule := RBParseTreeRewriter new replace: '`@collection collect: `@arg1' with: replacement. rewriteRule executeTree: cm parseTree. rewriteRule tree newSource Essentially, I used the same search pattern you used, but I used it for the RBParseTreeRewriter and removed all of the RBParseTreeSearcher code. If you want to change all #collect: sends in a method, then you should probably change `@aCollection and `@arg1 to ``@aCollection and ``@arg1. John Brant