user869097
user869097

Reputation: 1362

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) ] ].

Upvotes: 1

Views: 249

Answers (2)

Francisco Ary Martins
Francisco Ary Martins

Reputation: 61

An alternative is to rename the classes in a single package to make the following code:

(SystemOrganizer default classesInCategory: 'my pakage name') do: [ :class |
    "Adding the prefix PRE classes"
    (class name beginsWith: 'PRE') ifFalse: [ class rename: 'PRE' , class name ] 
]

Upvotes: 0

Lukas Renggli
Lukas Renggli

Reputation: 8947

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.

Upvotes: 3

Related Questions