pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

RB - New introduced refactorings

EC
Evelyn Cusi Lopez
Mon, Feb 8, 2021 8:40 AM

Hello all,

These weeks I added new refactorings, following I will give some examples
of them.

1. Create accessors with lazy initialization

This refactoring create accessors for variables with lazy initialization,
for example:

  • we have a class

Object subclass: #SomeClass
instanceVariableNames: 'stringVar'
classVariableNames: ''
package: 'Example'

  • we can create accessors with lazy initialization executing this script:

(RBCreateAccessorsWithLazyInitializationForVariableRefactoring
variable: #stringVar
class: SomeClass
classVariable: false
defaultValue: '''example''') execute

the result of this refactoring is:

SomeClass >> stringVar
^ stringVar ifNil: [ stringVar := '' ]

SomeClass >> stringVar: anObject
stringVar := anObject

2. Extract setUp refactoring (is the first version by the moment, it need
to be improved)

This refactoring create a setUp method from a code fragment.
You can select an interval of some code in a test method and call this
refactoring to create a setUp method implementing that code and replace the
code by nothing. The selected class need to be a subclass of TestCase.

For example:

  • given  a class

TestCase subclass: #SomeTest
instanceVariableNames: ''
classVariableNames: ''
package: 'Example'

SomeTest >>testFoo
self x.
self assert: true

SomeTest >>  self x
self doSomething

  • To extract setUp method you can execute this script:

(RBExtractSetUpMethodRefactoring extract: (10 to: 16)
from: #testFoo
in: SomeTest) execute

the result of this refactoring is:

SomeTest >> setUp
super setUp.
self x.

SomeTest >> testFoo
self assert: true

3. Move method to class side refactoring (This refactoring is still
awaiting review)

This refactoring move a method to class side.
For example:

  • given a method

ClassX >> annotatedBlockMarkup
^ '@@'

  • we can execute the refactoring with this script:

(RBMoveMethodToClassSideRefactoring
method: (ClassX >> #annotatedBlockMarkup)
class: ClassX) execute.

the result of this refactoring is:

ClassX >> annotatedBlockMarkup
^ self class annotatedBlockMarkup

ClassX class >> annotatedBlockMarkup
^ '@@'

Any suggestions or comment of these refactorings are welcome. I hope these
new refactorings are useful to you .

Regards,
Evelyn C.

Hello all, These weeks I added new refactorings, following I will give some examples of them. *1. Create accessors with lazy initialization* This refactoring create accessors for variables with lazy initialization, for example: - we have a class Object subclass: #SomeClass instanceVariableNames: 'stringVar' classVariableNames: '' package: 'Example' - we can create accessors with lazy initialization executing this script: (RBCreateAccessorsWithLazyInitializationForVariableRefactoring variable: #stringVar class: SomeClass classVariable: false defaultValue: '''example''') execute the result of this refactoring is: SomeClass >> stringVar ^ stringVar ifNil: [ stringVar := '' ] SomeClass >> stringVar: anObject stringVar := anObject *2. Extract setUp refactoring* (is the first version by the moment, it need to be improved) This refactoring create a setUp method from a code fragment. You can select an interval of some code in a test method and call this refactoring to create a setUp method implementing that code and replace the code by nothing. The selected class need to be a subclass of TestCase. For example: - given a class TestCase subclass: #SomeTest instanceVariableNames: '' classVariableNames: '' package: 'Example' SomeTest >>testFoo self x. self assert: true SomeTest >> self x self doSomething - To extract setUp method you can execute this script: (RBExtractSetUpMethodRefactoring extract: (10 to: 16) from: #testFoo in: SomeTest) execute the result of this refactoring is: SomeTest >> setUp super setUp. self x. SomeTest >> testFoo self assert: true *3. Move method to class side refactoring* (This refactoring is still awaiting review) This refactoring move a method to class side. For example: - given a method ClassX >> annotatedBlockMarkup ^ '@@' - we can execute the refactoring with this script: (RBMoveMethodToClassSideRefactoring method: (ClassX >> #annotatedBlockMarkup) class: ClassX) execute. the result of this refactoring is: ClassX >> annotatedBlockMarkup ^ self class annotatedBlockMarkup ClassX class >> annotatedBlockMarkup ^ '@@' Any suggestions or comment of these refactorings are welcome. I hope these new refactorings are useful to you . Regards, Evelyn C.
KO
Kasper Osterbye
Mon, Feb 8, 2021 6:57 PM

Hi

How does your "move method to class side" differ from the one already there?

[image: image.png]

Best,

Kasper

Hi How does your "move method to class side" differ from the one already there? [image: image.png] Best, Kasper
EC
Evelyn Cusi Lopez
Mon, Feb 8, 2021 7:20 PM

Hi,

The current move method to class side refactoring, doesn't correct the
senders of this method, neither checks correctly references to instance
variables or method calls (on instance side). At the moment this
improvement only covers that method's senders won't break, creating a
method on instance side with the same name referring to the method on side
class, as shown in the example.

  • given a method

ClassX >> annotatedBlockMarkup
^ '@@'

the result of this refactoring is:

ClassX >> annotatedBlockMarkup
^ self class annotatedBlockMarkup

ClassX class >> annotatedBlockMarkup
^ '@@'

I still need to improve, but it's a small advance that I wanted to show you
to get feedback.

Regards,

Evelyn C.

El lun, 8 feb 2021 a las 14:57, Kasper Osterbye (kasper.osterbye@gmail.com)
escribió:

Hi

How does your "move method to class side" differ from the one already
there?

[image: image.png]

Best,

Kasper

Hi, The current move method to class side refactoring, doesn't correct the senders of this method, neither checks correctly references to instance variables or method calls (on instance side). At the moment this improvement only covers that method's senders won't break, creating a method on instance side with the same name referring to the method on side class, as shown in the example. - given a method ClassX >> annotatedBlockMarkup ^ '@@' the result of this refactoring is: ClassX >> annotatedBlockMarkup ^ self class annotatedBlockMarkup ClassX class >> annotatedBlockMarkup ^ '@@' I still need to improve, but it's a small advance that I wanted to show you to get feedback. Regards, Evelyn C. El lun, 8 feb 2021 a las 14:57, Kasper Osterbye (<kasper.osterbye@gmail.com>) escribió: > Hi > > How does your "move method to class side" differ from the one already > there? > > [image: image.png] > > Best, > > Kasper >
TM
Tim Mackinnon
Tue, Feb 9, 2021 11:24 AM

Evelyn - this is brillian stuff, I appreciate the work going into this to make it all better. Keep pushing on it.

Tim

On Mon, 8 Feb 2021, at 7:20 PM, Evelyn Cusi Lopez wrote:

Hi,

The current move method to class side refactoring, doesn't correct the senders of this method, neither checks correctly references to instance variables or method calls (on instance side). At the moment this improvement only covers that method's senders won't break, creating a method on instance side with the same name referring to the method on side class, as shown in the example.

  • given a method

ClassX >> annotatedBlockMarkup
^ '@@'

the result of this refactoring is:

ClassX >> annotatedBlockMarkup
^ self class annotatedBlockMarkup

ClassX class >> annotatedBlockMarkup
^ '@@'

I still need to improve, but it's a small advance that I wanted to show you to get feedback.

Regards,

Evelyn C.

El lun, 8 feb 2021 a las 14:57, Kasper Osterbye (kasper.osterbye@gmail.com) escribió:

Hi

How does your "move method to class side" differ from the one already there?

image.png

Best,

Kasper

Attachments:

  • image.png
Evelyn - this is brillian stuff, I appreciate the work going into this to make it all better. Keep pushing on it. Tim On Mon, 8 Feb 2021, at 7:20 PM, Evelyn Cusi Lopez wrote: > Hi, > > The current move method to class side refactoring, doesn't correct the senders of this method, neither checks correctly references to instance variables or method calls (on instance side). At the moment this improvement only covers that method's senders won't break, creating a method on instance side with the same name referring to the method on side class, as shown in the example. > > - given a method > > ClassX >> annotatedBlockMarkup > ^ '@@' > > > the result of this refactoring is: > > ClassX >> annotatedBlockMarkup > ^ self class annotatedBlockMarkup > > ClassX class >> annotatedBlockMarkup > ^ '@@' > > I still need to improve, but it's a small advance that I wanted to show you to get feedback. > > Regards, > > Evelyn C. > > El lun, 8 feb 2021 a las 14:57, Kasper Osterbye (<kasper.osterbye@gmail.com>) escribió: >> Hi >> >> How does your "move method to class side" differ from the one already there? >> >> image.png >> >> Best, >> >> Kasper > > *Attachments:* > * image.png
SD
Stéphane Ducasse
Tue, Feb 9, 2021 12:38 PM

Thanks evelyn for the announce.
I will use it for the blog :)

On 8 Feb 2021, at 09:40, Evelyn Cusi Lopez cusi.evelyn@gmail.com wrote:

Hello all,

These weeks I added new refactorings, following I will give some examples of them.

  1. Create accessors with lazy initialization

This refactoring create accessors for variables with lazy initialization, for example:

  • we have a class

Object subclass: #SomeClass
instanceVariableNames: 'stringVar'
classVariableNames: ''
package: 'Example'

  • we can create accessors with lazy initialization executing this script:

(RBCreateAccessorsWithLazyInitializationForVariableRefactoring
variable: #stringVar
class: SomeClass
classVariable: false
defaultValue: '''example''') execute

the result of this refactoring is:

SomeClass >> stringVar
^ stringVar ifNil: [ stringVar := '' ]

SomeClass >> stringVar: anObject
stringVar := anObject

  1. Extract setUp refactoring (is the first version by the moment, it need to be improved)

This refactoring create a setUp method from a code fragment.
You can select an interval of some code in a test method and call this refactoring to create a setUp method implementing that code and replace the code by nothing. The selected class need to be a subclass of TestCase.

For example:

  • given  a class

TestCase subclass: #SomeTest
instanceVariableNames: ''
classVariableNames: ''
package: 'Example'

SomeTest >>testFoo
self x.
self assert: true

SomeTest >>  self x
self doSomething

  • To extract setUp method you can execute this script:

(RBExtractSetUpMethodRefactoring extract: (10 to: 16)
from: #testFoo
in: SomeTest) execute

the result of this refactoring is:

SomeTest >> setUp
super setUp.
self x.

SomeTest >> testFoo
self assert: true

  1. Move method to class side refactoring (This refactoring is still awaiting review)

This refactoring move a method to class side.
For example:

  • given a method

ClassX >> annotatedBlockMarkup
^ '@@'

  • we can execute the refactoring with this script:

(RBMoveMethodToClassSideRefactoring
method: (ClassX >> #annotatedBlockMarkup)
class: ClassX) execute.

the result of this refactoring is:

ClassX >> annotatedBlockMarkup
^ self class annotatedBlockMarkup

ClassX class >> annotatedBlockMarkup
^ '@@'

Any suggestions or comment of these refactorings are welcome. I hope these new refactorings are useful to you .

Regards,
Evelyn C.


Stéphane Ducasse
http://stephane.ducasse.free.fr / http://www.pharo.org
03 59 35 87 52
Assistant: Aurore Dalle
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley,
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France

Thanks evelyn for the announce. I will use it for the blog :) > On 8 Feb 2021, at 09:40, Evelyn Cusi Lopez <cusi.evelyn@gmail.com> wrote: > > Hello all, > > These weeks I added new refactorings, following I will give some examples of them. > > 1. Create accessors with lazy initialization > > This refactoring create accessors for variables with lazy initialization, for example: > - we have a class > > Object subclass: #SomeClass > instanceVariableNames: 'stringVar' > classVariableNames: '' > package: 'Example' > > - we can create accessors with lazy initialization executing this script: > > (RBCreateAccessorsWithLazyInitializationForVariableRefactoring > variable: #stringVar > class: SomeClass > classVariable: false > defaultValue: '''example''') execute > > the result of this refactoring is: > > SomeClass >> stringVar > ^ stringVar ifNil: [ stringVar := '' ] > > SomeClass >> stringVar: anObject > stringVar := anObject > > 2. Extract setUp refactoring (is the first version by the moment, it need to be improved) > > This refactoring create a setUp method from a code fragment. > You can select an interval of some code in a test method and call this refactoring to create a setUp method implementing that code and replace the code by nothing. The selected class need to be a subclass of TestCase. > > For example: > > - given a class > > TestCase subclass: #SomeTest > instanceVariableNames: '' > classVariableNames: '' > package: 'Example' > > SomeTest >>testFoo > self x. > self assert: true > > SomeTest >> self x > self doSomething > > - To extract setUp method you can execute this script: > > (RBExtractSetUpMethodRefactoring extract: (10 to: 16) > from: #testFoo > in: SomeTest) execute > > the result of this refactoring is: > > SomeTest >> setUp > super setUp. > self x. > > SomeTest >> testFoo > self assert: true > > 3. Move method to class side refactoring (This refactoring is still awaiting review) > > This refactoring move a method to class side. > For example: > - given a method > > ClassX >> annotatedBlockMarkup > ^ '@@' > > - we can execute the refactoring with this script: > > (RBMoveMethodToClassSideRefactoring > method: (ClassX >> #annotatedBlockMarkup) > class: ClassX) execute. > > the result of this refactoring is: > > ClassX >> annotatedBlockMarkup > ^ self class annotatedBlockMarkup > > ClassX class >> annotatedBlockMarkup > ^ '@@' > > Any suggestions or comment of these refactorings are welcome. I hope these new refactorings are useful to you . > > Regards, > Evelyn C. -------------------------------------------- Stéphane Ducasse http://stephane.ducasse.free.fr / http://www.pharo.org 03 59 35 87 52 Assistant: Aurore Dalle FAX 03 59 57 78 50 TEL 03 59 35 86 16 S. Ducasse - Inria 40, avenue Halley, Parc Scientifique de la Haute Borne, Bât.A, Park Plaza Villeneuve d'Ascq 59650 France