[prev] [up] [next]

Refactorings

Abstract Variable
Creates getter/setters for an instance/class variable, and then changes all direct references to the variables to go through the getter/setter methods. If getter/setter methods exist it will use the existing methods. However, they must be pure getter/setter methods (i.e., no lazy initialization getters). If no getter/setter methods exist it will create them based on the variable's name (see Create Accessors). If the class already defines a method with the variable name's then it will simply add an integer to the name.

The abstract instance variable refactoring is available from the "selection" menu when you have selected an instance variable. It is also available from the "variables" menu in the class definition when you have selected an instance variable. Finally, it is available from the "Class"->"Instance variables" menu

Similarly, the abstract class variable refactoring is available from the "selection" menu when you have selected a class variable. It is also available from the "variables" menu in the class definition view when you have selected a class variable. Finally, it is available from the "Class"->"Class variables" menu.

Safety: The abstract variable refactorings are safe under normal circumstances.

Add Parameter
Adds a parameter to all senders of a method and adds the argument to all implementors of the method. This makes it easy to quickly add a needed object to a method.

The add parameter refactoring is available from the "Selector"->"Other"->"Add parameter..." menu item.

Safety: The add parameter is relatively safe assuming that the code that is added as a parameter is safe (i.e., the code doesn't have side-effects). One area where it would be unsafe is to add a parameter to a method that is #perform:ed since we can't determine where the method is performed from.

Children To Sibling
onverts a concrete superclass to be a sibling of its subclasses. This is accomplished by adding a new class that is a superclass of the superclass and its subclasses. This new class will contain all the common methods between the superclass and its subclasses. Those methods that have been redefined in the subclasses will be defined as #subclassResponsibility methods in the new class.

This refactoring is available from "Class"->"Class"->"Other"->"Convert to sibling"

Safety: This refactoring could fail if you check the class hierarchy of the superclass, since the class hierarchy is change for the new class.

Extract Method
Extract method is an easy refactoring to perform with the Refactoring Browser. When you are viewing a method, simply select the statements that you want to extract, and perform "extract method" from the method's pop-up menu. The browser will determine if it is legal to extract the method by checking for return statements and temporary variable assignments. If everything is OK, it will prompt you for a method name. From this dialog, you can enter the new selector with the appropriate number of arguments (listed in the list box below the selector). You can also reorder the parameters from this dialog. Simply select a parameter and then use the arrow buttons beside the list to move the parameter up or down in the list.

Extract to Temporary
Extract the selected expression into a temporary of the method (Intention revealing temporary variable).

This refactoring is available when you have selected an expression that is used as part of another expression. After you have selected the expresion, the "Selection" menu will contain the "Extract to temporary" menu choice.

Safety: Since this refactoring can change the evaluation order of the overall expression, it is not safe if there are side effects between those expression that are evaluated before the selected expression and the selected expression itself.

Inline Method
Inlines the selected message send into the method. If the method is defined on another class, it may need to create accessors for the variables referenced in the method to be inlined.

This refactoring is available from the "Selection"->"Inline method" menu when you select a message send in the code.

Safety: This refactoring is fairly safe. If the refactoring finds something that it considers unsafe, it will warn you before performing the refactoring. If you proceed through the warning it will still inline the method.

Inline Parameter
Moves a constant literal parameter of a message send into the method that is sent.

This refactoring is available from the "Selection"->"Inline parameter" when you select an argument to the method.

Safety: This refactoring is safe except when performing methods, since we can't convert the symbols that are performed.

Inline Temporary
Replaces all references to a temporary variable with its definition.

This refactoring is available from the "Selection"->"Inline temporary" when you have an assignment statement selected.

Safety: This refactoring can be unsafe if the code you are inlining has side-effect or if any code between the assignment statement and the references have side effects on the inlined expression.

Move Method
Moves a method from one class to another. The original method will be replace with a forwarder method. The method will be moved into an argument of the method or a variable of the original method's class.

This refactoring is available from "Selector"->"Move"->"To component".

Safety: This refactoring is safe assuming you select the correct class(es) of the variable that should contain the new method.

Move To Inner Scope
Move a temporary variable's definition to the inner most block that completely defines its.

This refactoring is available from "Selection"->"Move to inner scope" when you have selected a temporary variable in a method.

Safety: This refactoring is safe unless someone is looking at the source code.

Protect Instance Variable
Removes indirect references through getter/setter methods to use direct variable referencing. If the getter/setter methods are no longer used, then they will be removed.

This refactoring is available from "Class"->"Instance variables"->"Protect/Concrete".

Safety: This refactoring is essentially an Inline All Self Sends, so it contains all the safe restrictions as Inline All Self Sends has.

Pull Up Variable
Moves an instance/class variable up the hierarchy.

The pull up instance variable refactoring is available from the "Class"->"Instance Variables"->"Pull up" menu choice. It is also available as "Push up" when you have selected the variable in either the class definition or a method under the "Variables" and "Selection" menus.

Similarly, the pull up class variable is available from the "Class"->"Class variables"->"Pull up" menu choice. It is also available as "Push up" when you have selected the variable in either the class definition or a method under the "Variables" and "Selection" menus.

Safety: This refactoring is not safe if you code that depends on the exact layout of the class. Such code normally uses the #instVarAt:{put:} methods.

Push Down Variable
Moves a variable into the subclasses that use the variable.

The push down instance/class variable refactoring is available from "Class"->"Instance/Class variables"->"Push down" and also from "Variables"->"Push down" when the variable is selected in the class definition.

Safety: This refactoring is safe unless one is accessing the variable using the #instVarAt:{put:} methods.

Push Down Method
Moves a method into the subclasss that do not define the method. The method can only be moved, if the class that defines the method is an abstract class.

The push down method refactoring is available from "Selector"->"Other"->"Push down".

Safety: This refactoring is safe assuming that every class that sends #subclassResponsibility is abstract.

Push Up Method
Move a method into the superclass. If the superclass already defines the method, then the superclass must be abstract. In this case, the superclass' definition is copied down to the subclasses that do not define the method.

The push up method refactoring is available from "Selector"->"Other"->"Push up".

Safety: This refactoring is safe assuming that every class that sends #subclassResponsibility is abstract.

Remove Class
Removes a class if it is not referenced. If the class contains subclasses, then the subclasses will be move under the class' superclass.

The remove class refactoring is available from the "Class"->"Class"->"Safe remove" menu choice.

Safety: This refactoring is safe if they are no indirect references to the class. Such references maybe from the #subclasses method or from performing "Smalltalk at: ...".

Remove Method
Remove a method if there are no references to the selector.

This refactoring is available from "Selector"->"Safe remove".

Safety: This refactoring is not safe if you have constructed selectors that perform the method (e.g., "self perform: 'foo' asSymbol). However, if you have code such as "self perform: #foo" then it will consider the #foo method referenced.

Remove Parameter
Removes a parameter from a method if that parameter is not referenced in any implementation of that method.

This refactoring is available from the "Selection"->"Remove parameter" menu when you have selected a parameter of a method.

Safety: This refactoring is not safe when you are perform:ing the method. Also, it is not safe if the parameter that is removed, has side-effects at one of its call sites.

Remove Variable
Removes an instance/class variable from a class if it is not referenced.

The remove instance variable refactoring is available from the "Class"->"Instance variable"->"Remove..." menu as well as the "Variables" menu in the class definition when a variable is selected.

Similarly, the remove class variable refactoring is available from the "Class"->"Class variable"->"Remove..." menu as well as the "Variables" menu in the class definition when a class variable is selected.

Safety: This refactoring is safe under normal circumstances. However, if you have code that depends on the layout of the classes, then it may not be safe.

Rename Class
Renames a class and all references to the class. Symbols are also renamed.

This refactoring is available from "Class"->"Class"->"Rename".

Safety: This refactoring is safe except when you have indirect class references (e.g., "Smalltalk at: 'Foo' asSymbol").

Rename Variable
Renames an instance/class variable and all references to the variable. It does not rename the getter/setter methods.

The rename instance variable refactoring is available from "Class"->"Instance variables"->"Rename". It can also be found under the "Variables" menu in the class definition view and the "Selection" menu in the method when the variable is selected.

Similarly, the rename class variable refactoring is available from "Class"->"Class variables"->"Rename". It can also be found under the "Variables" menu in the class definition view and the "Selection" menu in the method view when the variable is selected.

Safety: This refactoring is safe except for classes that depend on the class layout since the positions of the variables may change.

Rename Method
Renames all implementors of the method and all references to the method. Symbols with the same name are also renamed.

This refactoring is available from "Selector"->"Rename".

Safety: This refactoring is not safe for constructed selectors that are perform:ed. Also, if you reorder the parameters, this refactoring will not be safe if the parameters have side-effects on each other.

Rename Temporary
Renames a temporary variable and all references to the temporary.

This refactoring is available from the "Selection"->"Rename" menu when you have a temporary or argument selected.

Safety: This refactoring is completely safe, unless someone is looking at the source code for the method.

Temporary to Instance Variable
This refactoring converts a temporary variable into an instance variable.

This refactoring is available from the "Selection"->"Convert to instance variable" menu when you have a temporary variable selected.

Safety: This refactoring is not safe if the method that defines the temporary is a recursive method.


Doc $Revision: 1.1 $ $Date: 2001/09/08 20:31:37 $