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:
Object subclass: #SomeClass
instanceVariableNames: 'stringVar'
classVariableNames: ''
package: 'Example'
(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:
TestCase subclass: #SomeTest
instanceVariableNames: ''
classVariableNames: ''
package: 'Example'
SomeTest >>testFoo
self x.
self assert: true
SomeTest >> self x
self doSomething
(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:
ClassX >> annotatedBlockMarkup
^ '@@'
(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.
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.
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
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.
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:
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.
This refactoring create accessors for variables with lazy initialization, for example:
Object subclass: #SomeClass
instanceVariableNames: 'stringVar'
classVariableNames: ''
package: 'Example'
(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
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:
TestCase subclass: #SomeTest
instanceVariableNames: ''
classVariableNames: ''
package: 'Example'
SomeTest >>testFoo
self x.
self assert: true
SomeTest >> self x
self doSomething
(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
This refactoring move a method to class side.
For example:
ClassX >> annotatedBlockMarkup
^ '@@'
(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