Search code examples
refactoringsmalltalkpharoautomated-refactoring

Mass rename of classes solving references in Smalltalk with the Refactoring Browser


I want to rename all classes starting with the prefix SMP to RS, including references in source code (direct ones like SMPClass1 and indirect ones like Smalltalk at: #SMPClass2) and in class and method comments. Can the current RBParseTreeRewriter do this? An equivalent without the parse tree rewriter would be:

Smalltalk allClassesDo: [ :class |
(class name beginsWith: 'SW2')
    ifTrue: [ class rename: 'PR' , (class name allButFirst: 3) ] ].

Solution

  • Yes, this can be done, but not with the RBParseTreeRewriter (this is a low-level tool to rewrite source-code internally used by refactorings).

    From OmniBrowser select in the context menu Refactor > Class Regex. Then modify and accept the template as follows:

    ORClassRegexRefactoring new
      renameClasses;
      replace: '^SW2(.*)$' with: 'PR$1' ignoreCase: false;
      yourself
    

    This will automatically rename all classes and references.