<div dir="ltr"><div>Hi everyone,<br><br>I wanted to share some improvements I made to the Extract Method refactoring in Cuis. There are three main additions:<br><br><b>1. Support for assignments to temporary variables</b><br><br>Previously, if you tried to extract a fragment that assigned a temp var, the refactoring would fail with an error. Now it handles several cases automatically:<br><br>- If the variable isn't used after the fragment, it just moves inside the new method.<br>- If it's used after, the new method returns it and the call site assigns it back.<br>- If multiple variables are assigned and all used afterwards, it uses an "assignment block" pattern:<br><br><font face="monospace"><i>"Before:"</i><br>process<br>    | subtotal tax |<br>    subtotal := self price.<br>    tax := subtotal * self taxRate.<br>    ^ subtotal + tax<br><br><i>"After extracting 'subtotal := self price. tax := subtotal * self taxRate.':"</i><br>process<br>    | subtotal tax |<br>    self computeAssigningWith: [ :newSubtotal :newTax |<br>        subtotal := newSubtotal. tax := newTax. ].<br>    ^ subtotal + tax<br><br>computeAssigningWith: anAssignmentBlock<br>    | subtotal tax |<br>    subtotal := self price.<br>    tax := subtotal * self taxRate.<br>    ^ anAssignmentBlock value: subtotal value: tax</font><br><br><b>2. Support for non-local returns</b><br><br>Extracting fragments with a `^` also used to fail. Now:<br><br>- A plain `^` in the fragment becomes the return of the new method.<br>- A `^` inside a block uses a "returning block" pattern so the non-local return still works correctly:<br><br><font face="monospace"><i>"Before:"</i><br>findFirst<br>    self do: [:each | each isValid ifTrue: [^each]].<br>    ^ nil<br><br><i>"After extracting 'self do: [...]':"</i><br>findFirst<br>    self findValidElementReturningWith: [:res | ^ res].<br>    ^ nil<br><br>findValidElementReturningWith: aReturningBlock<br>    self do: [:each | each isValid ifTrue: [^ aReturningBlock value: each]].</font><br><br><br><b>3. Parameterizable code detection</b><br><br>Extract Method now detects occurrences that are structurally similar to the selected fragment but differ in some arguments — just like it already does for equivalent code, it searches across the whole class hierarchy. When found, a new window appears letting you decide whether to parametrize them:<br><br><font face="monospace"><i>"Before:"</i><br>process<br>    self foo: 10 bar: 'hello'.<br>    self foo: 20 bar: 'hello'.<br>    self foo: 10 bar: 'world'.<br><br><i>"After selecting 'self foo: 10 bar: ''hello''' and accepting parametrization:"</i><br>process<br>    self m: 10 with: 'hello'.<br>    self m: 20 with: 'hello'.<br>    self m: 10 with: 'world'.<br><br>m: aFoo with: aBar<br>    self foo: aFoo bar: aBar</font><br><br>All three improvements are already integrated into Cuis. Thanks Juan for merging them!<br><br>Happy to answer any questions!</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br></div><a href="https://10pines.com/" style="font-family:Roboto,Helvetica,Arial,sans-serif;font-size:medium" target="_blank"><img width="108" src="https://10pines.github.io/email-signature/10pines-firma@2x.png" style="margin-bottom:0.5em"></a><h1 style="margin:0px;font-size:14px"><font color="#999999">Joel Cámera</font></h1><h2 style="color:rgb(100,100,100);margin:0px 0px 1em;font-size:14px">Agile Software Development</h2><h1 style="margin:0px;font-size:14px"><font style="font-weight:normal" color="#666666"><p style="margin:0px;font-size:12px">Alem 896, Floor 6, Buenos Aires, Argentina</p><p style="margin:0px;font-size:12px">+54 9 011 6091 3125</p></font></h1></div></div></div></div>