pharo
pharo copied to clipboard
[ Refactoring ] RBMoveTemporaryVariableDefinitionTransformation and RBMoveVariableDefinitionToSmallestValidScopeRefactoring should be merged
Two points
Add more tests.
In the first place I thought that the following was wrong. But since the temp value is not accessed in the second block. It is possible. Now we should get several tests to check this.
moveDefinition
| temp |
^(self collect:
[:each |
temp := each printString.
temp , temp])
select:
[:each |
temp := each size.
temp odd]
transformed into
moveDefinition
^ (self collect: [ :each |
| temp |
temp := each printString.
temp , temp ]) select: [ :each |
| temp |
temp := each size.
temp odd ]
We should remove the duplication
Now RBMoveVariableDefinitionToSmallestValidScopeRefactoring is working on interval while RBMoveTemporyVariableDefinition on names. So we should merge them.
We should write a test showing that this is wrong.
The transformation implementation looks nicer to my eyes.
buildTransformations
"ifnil... tight blocks should not be returned as errors"
blockNodes ifNil: [ self checkMethodForBlocks ].
^ (OrderedCollection
withAll: ((blockNodes
sorted: [ :a :b | a start > b start ])
collect: [ :blockNode |
RBAddTemporaryVariableTransformation
variable: variableName
inInterval: blockNode body sourceInterval
inMethod: selector
inClass: class ]))
add: (RBRemoveTemporaryVariableTransformation
variable: variableName
inMethod: selector
inClass: class);
yourself
vs.
privateTransform
definingNode removeTemporaryNamed: name.
blockNodes do: [:each | each body addTemporaryNamed: name].
class compileTree: parseTree