pharo
pharo copied to clipboard
RBInlineMethodRefacotring has behavior preserving preconditions checked during execution
Right now Inline method refactoring has warning that pops-up during execution (transformation) phase. It should be moved to behavior preserving preconditions. It is here:
"transforming"
inlineSourceReplacing: aParseTree
| statements nodeUnderSequence |
statements := inlineParseTree body statements.
(statements size > 1 and: [ aParseTree isEvaluatedFirst not ]) ifTrue: [
self refactoringWarning: "<<---- THIS ONE"
'To inline this method, we need to move some of its statements before the original message send.<n>This could change the order of execution, which can change the behavior.<n>Do you want to proceed?'
expandMacros ].
nodeUnderSequence := aParseTree.
[ nodeUnderSequence parent isSequence ] whileFalse: [ nodeUnderSequence := nodeUnderSequence parent ].
nodeUnderSequence parent
addNodes: (statements copyFrom: 1 to: (statements size - 1 max: 0)) before: nodeUnderSequence;
addTemporariesNamed: inlineParseTree body temporaryNames.
aParseTree parent replaceNode: aParseTree withNode: (statements isEmpty
ifTrue: [ OCVariableNode selfNode ]
ifFalse: [ statements last ])
proposed fix:
"preconditions"
RBInlineMethodRefactoring >> breakingChangePreconditions
^ { (RBCondition withBlock: [
self checkOverridden ifTrue: [
self isOverridden ifTrue: [
self refactoringWarning:
('<1p>>><2s> is overriden. Do you want to inline it anyway?'
, String cr , 'You can break you hooks with this inline.'
expandMacrosWith: self classOfTheMethodToInline
with: self inlineSelector) ] ].
true ]).
(RBCondition withBlock: [
| statements |
statements := inlineParseTree body statements.
(statements size > 1 and: [ sourceMessage isEvaluatedFirst not ]) ifTrue: [
self refactoringWarning:
'To inline this method, we need to move some of its statements before the original message send.<n>This could change the order of execution, which can change the behavior.<n>Do you want to proceed?'
expandMacros
]])
}
RBInlineMethodRefactoring >> inlineSourceReplacing: aParseTree
| statements nodeUnderSequence |
statements := inlineParseTree body statements.
nodeUnderSequence := aParseTree.
[ nodeUnderSequence parent isSequence ] whileFalse: [ nodeUnderSequence := nodeUnderSequence parent ].
nodeUnderSequence parent
addNodes: (statements copyFrom: 1 to: (statements size - 1 max: 0)) before: nodeUnderSequence;
addTemporariesNamed: inlineParseTree body temporaryNames.
aParseTree parent replaceNode: aParseTree withNode: (statements isEmpty
ifTrue: [ OCVariableNode selfNode ]
ifFalse: [ statements last ])