[Pharo-project] How to use the OmniBrowser regex refactor to transform code?

Simon Denier Simon.Denier at inria.fr
Tue Sep 22 05:33:12 EDT 2009


On 22 sept. 09, at 11:14, T.J. Richter wrote:

> I feel stupid for asking this, but I Googled and found nothing,  
> checked classes
> for comments and found nothing, then skimmed Pharo by Example and  
> also found
> nothing. Lukas mentioned helpfully in another thread that you can  
> use the regex
> refactoring tools in the OmniBrowser to transform code, but I can't  
> seem to
> figure out how to do it. I figured out how to "scope" the  
> refactoring to a
> class or class hierarchy, which results in a gold window popping up  
> with the
> selected class(es) in the left-most panel. When I right-click on the  
> class at
> the top and choose "refactor->source regex", I get a template in the  
> code
> panel that looks like this:
>
> ORSourceRegexRefactoring new
>
> 	"Example 1: Replace symbols with strings"
> 	replace: '#(\w+)' with: '''$1''' ignoreCase: false;
> 	
> 	"Example 2: Replace 4 spaces with tabs"
> 	replace: '    ' with: '	' ignoreCase: false;
>
> 	yourself
>
> I wanted to rename a method (and all senders of it in the selected  
> scope) from
> "nextValue" to "nextItem", so I edit the template to this:

Hi TJ

The quick answer:
if you want to do a standard refactoring in the scope, like renaming a  
method and update senders, you can use the standard action in the  
menu. It will do exactly what you want.
The rewrite code tool is there for more tricky situations.

The other answer:
I myself often struggle with the syntax for those refex tools. Part of  
the reason I think is that the 'regex' matches on AST nodes and not on  
text, so regex expressions do not match string but nodes.
The links I found useful are the two screencasts of Lukas in the  
following order:

http://www.lukas-renggli.ch/blog/ob-rb-3
http://www.lukas-renggli.ch/blog/ob-rb-1


>
>
> ORSourceRegexRefactoring new
> 	
> 	replace: 'nextValue' with: 'nextItem' ignoreCase: false;
>
> 	yourself
>
> I highlight it all with Alt-a, then Do It with Alt-d, but nothing  
> seems to
> happen.
>
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
  Simon







More information about the Pharo-dev mailing list