Refactoring Tools

The first automated refactoring tool (John Brant and Don Roberts, University of Illinois, 1990s) was built for Smalltalk; Pharo integrates it everywhere.

27.1 The Refactoring Browser

The first automated refactoring tool (John Brant and Don Roberts, University of Illinois, 1990s) was built for Smalltalk; Pharo integrates it everywhere. Right-click classes, methods, variables, or selected code:

Rename class / method / variable Updates all references and senders

Selected code → new method, with arguments inferred Extract temporary / inline temporary Expressions ↔ variables Replace a send with the method body Add / remove / reorder parameter Updates all senders Push up / push down method or variable Move along the hierarchy Move method to another class Via an instance variable or argument Getters and setters for slots Abstract instance variable Replace direct access with accessors Extract superclass / split class Remove method / class Warns if there are senders/references

Adds a deprecation with automatic rewrite Every refactoring shows a preview of the changes and can be undone.

27.2 Deprecation with automatic rewriting

When old code calls credit:, Pharo logs the deprecation and rewrites the calling method's source automatically.

BankAccount >> credit: anAmount
    self
        deprecated: 'Use #deposit: instead'
        transformWith: '`@receiver credit: `@arg' -> '`@receiver deposit: `@arg'.
    ^ self deposit: anAmount

27.3 The Rewrite Engine

Pattern-based source transformations across the whole code base (*Tools → Rewrite Tool* in recent Pharo). Patterns use backquote meta-variables (as in §27.2) to match any receiver, argument, or statement list. Typical uses: API migrations, removing deprecated idioms, enforcing conventions.

27.4 Code critics

The Quality Assistant shows critiques as you write (e.g., "Uses detect: without ifNone:", "Sends = to true", "Temporary variable not read"). The Critic Browser runs rules over packages. Rules are written as Smalltalk objects — you can add your own.

27.5 Navigation for safe change

Before changing a method, check its senders (Ctrl+N), implementors (Ctrl+M), and class references (Ctrl+Shift+N in many Pharo versions, or via the context menu). Polymorphism means a selector may be sent to many kinds of receivers — look before renaming.