Programming with Castalia : Refactoring : Split Temorary Variable
|
Previous
Top
Next
|
You have a local variable that is assigned more than once, and is not a loop variable nor collecting variable, and may be getting in the way of other refactorings.
Add a separate local variable for each assignment.
| procedure TForm1.UpdateCoordinates;
|
| StatusBar1.Panels[0].Text := IntToStr(Temp);
|
| StatusBar1.Panels[1].Text := IntToStr(Temp);
|
| procedure TForm1.UpdateCoordinates;
|
| Temp, ShapeLeft: Integer;
|
| StatusBar1.Panels[0].Text := IntToStr(Temp);
|
| ShapeLeft := Shape1.Left;
|
| StatusBar1.Panels[1].Text := IntToStr(ShapeLeft);
|
To split a variable into two variables, place the cursor in the name of the variable to be split, and invoke the Split Temporary Variable refactoring. Castalia will add the new variable to the method, changing instances of the variable to the new variable as appropriate. It will then allow you to change the name of the new variable.
To finish, press Enter.
Note: Castalia will assume that the first assignment to the existing temporary variable is correct, and that the next assignment should be reassigned to the new variable. If this is not your intention, you will need to rename the variables to correctly reflect your situation.
See also: Refactoring Overview, Rename Local Variable Refactoring, Inline Temporary Variable Refactoring