Hi all, How do you replace all 'expression1' in source code by 'expression2'? I can find them with Finder but don't see any easy way to replace them. My problem is i want to change parameter names in many methods. Best, Laura
Hi Laura, you can use this method: replaceAll: aString with: anotherString
"replaces aString in source code in the whole image in all methods with anotherString" ((self systemNavigation allMethodsWithSourceString: aString matchCase: false) collect: #compiledMethod) do: [ :each | each methodClass compile: (each sourceCode copyReplaceAll: aString with: anotherString) classified: each category ]
It will replace all 'expression1' by 'expression2' globally in the whole image. Will take some time Cheers, Alex On Thu, Mar 19, 2015 at 5:51 PM, Laura Risani <laura.risani@gmail.com> wrote:
Hi all,
How do you replace all 'expression1' in source code by 'expression2'? I can find them with Finder but don't see any easy way to replace them. My problem is i want to change parameter names in many methods.
Best, Laura
Hi Laura, you can use the parse tree rewriter of the Refactoring Browser set. Like that, you can have a degree of control about what you do replace and on what. For example, I'd try something like: | rewrite | rewrite := RBParseTreeRewriter new replace: 'expression1' with: 'expression2'. myClass methods do: [ :e | (rewrite executeTree: (RBParser parseMethod: e sourceCode)) ifTrue: [ myClass compile: rewrite tree newSource ] ] I'm not entirely sure it will do what I expect, but I'm trying to learn to use it more than I usually do, because it's very powerfull. Another example where the rewriter execute some smalltalk code during the search replace: https://gist.github.com/ThierryGoubier/54ba2fcf3cd2e7db9b1e Thierry Le 19/03/2015 17:51, Laura Risani a écrit :
Hi all,
How do you replace all 'expression1' in source code by 'expression2'? I can find them with Finder but don't see any easy way to replace them. My problem is i want to change parameter names in many methods.
Best, Laura
Thierry Goubier wrote
you can use the parse tree rewriter of the Refactoring Browser set
Didn't someone demo a cool rewrite tool GUI recently? I don't remember where exactly... ----- Cheers, Sean -- View this message in context: http://forum.world.st/Search-and-replace-source-code-tp4813295p4813314.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Le 19/03/2015 19:05, Sean P. DeNigris a écrit :
Thierry Goubier wrote
you can use the parse tree rewriter of the Refactoring Browser set
Didn't someone demo a cool rewrite tool GUI recently? I don't remember where exactly...
Yes! Mark Rizun rewrite tool (http://myfuncoding.blogspot.fr/). Recommended! But you can't have fun and use smalltalk scripts inside your search and rewrite terms with it ;) Thierry
Thank you all, your answers allowed me to solve my problem. Also very interesting tools! On Thu, Mar 19, 2015 at 3:19 PM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Le 19/03/2015 19:05, Sean P. DeNigris a écrit :
Thierry Goubier wrote
you can use the parse tree rewriter of the Refactoring Browser set
Didn't someone demo a cool rewrite tool GUI recently? I don't remember where exactly...
Yes! Mark Rizun rewrite tool (http://myfuncoding.blogspot.fr/). Recommended!
But you can't have fun and use smalltalk scripts inside your search and rewrite terms with it ;)
Thierry
participants (4)
-
Aliaksei Syrel -
Laura Risani -
Sean P. DeNigris -
Thierry Goubier