[squeak-dev] extract method refactoring with assignment

Eliot Miranda eliot.miranda at gmail.com
Fri Jan 5 17:10:37 UTC 2018


Hi All,

    I tried an extract to method refactoring yesterday that failed.  The method looked like

    | ... v1 v2 v3 |
    ....
    v1 := self m1.
    v2 := self m2.
    v3 := v3 collect: [:e| ...].
    ....

such that v1 and v2 were only used in the block, and the block was complex enough and did something useful e Pugh that I wanted to refactor as


| ... v1 v2 v3 |
    ....
    v3 := self complexCollect: v3.
    ....

complexCollect: a
    | v1 v2 |
    v1 := self m1.
    v2 := self m2.
    ^a collect: [:e| ...]

So I was forced by the fact that assignment is written with the variable on the LHS to include "v3 := " in the selection to extract to method, even though my intent was for it not to be included.  And of course the refactoring attempt fails precisely because the assignment /is/ included :-)

Shouldn't this case be specially handled do that and trailing assignment is left behind in the refactored original method?  Ifso, how would one go about it?

Note that part of the prerequisite checks should also check that the variables v1 & v2 are not used elsewhere in the origins nail method and whether the refactoring is smart enough to remove them from the refactored origins nap is optional but definitely preferred.

_,,,^..^,,,_ (phone)


More information about the Squeak-dev mailing list