-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated RBRenameMethodRefactoring into Refactoring2
- Loading branch information
1 parent
2a561c5
commit 0035e33
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/Refactoring2-Transformations/RBRenameMethodTransformation.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
Class { | ||
#name : #RBRenameMethodTransformation, | ||
#superclass : #RBChangeMethodNameTransformation, | ||
#instVars : [ | ||
'hasPermutedArguments' | ||
], | ||
#category : #'Refactoring2-Transformations-Model' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
RBRenameMethodTransformation class >> model: aRBSmalltalk renameMethod: aSelector in: aClass to: newSelector permutation: aMap [ | ||
^ self new | ||
model: aRBSmalltalk; | ||
renameMethod: aSelector | ||
in: aClass | ||
to: newSelector | ||
permutation: aMap; | ||
yourself | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
RBRenameMethodTransformation class >> renameMethod: aSelector in: aClass to: newSelector permutation: aMap [ | ||
^ self new | ||
renameMethod: aSelector | ||
in: aClass | ||
to: newSelector | ||
permutation: aMap | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> hasPermutedArguments [ | ||
|
||
^ hasPermutedArguments | ||
ifNil: [ hasPermutedArguments := super hasPermutedArguments ] | ||
ifNotNil: [ hasPermutedArguments ] | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> implementorsCanBePrimitives [ | ||
^self hasPermutedArguments not | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> modifyImplementorParseTree: parseTree in: aClass [ | ||
super modifyImplementorParseTree: parseTree in: aClass. | ||
self renameArgumentsIn: parseTree. | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> myConditions [ | ||
^RBCondition withBlock: [oldSelector numArgs = newSelector numArgs] | ||
errorString: newSelector printString | ||
, ' doesn''t have the correct number of arguments.' | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> parseTreeRewriter [ | ||
| rewriteRule oldString newString | | ||
oldString := self buildSelectorString: oldSelector. | ||
newString := self buildSelectorString: newSelector | ||
withPermuteMap: permutation. | ||
rewriteRule := self hasPermutedArguments | ||
ifTrue: [self parseTreeRewriterClass new] | ||
ifFalse: [self parseTreeRewriterClass replaceLiteral: oldSelector with: newSelector]. | ||
rewriteRule replace: '``@object ' , oldString | ||
with: '``@object ' , newString. | ||
^rewriteRule | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> preconditions [ | ||
| newCondition | | ||
newCondition := (RBCondition | ||
withBlock: [ newSelector = oldSelector ] | ||
errorString: 'The selector name has <1?not:> changed <1?:to #', newSelector, '>') | ||
& (RBCondition | ||
withBlock: [permutation asArray ~= (1 to: oldSelector numArgs) asArray] | ||
errorString: 'The arguments are <1?:not >permuted'). | ||
^newCondition | super preconditions | ||
] | ||
|
||
{ #category : #accessing } | ||
RBRenameMethodTransformation >> storeOn: aStream [ | ||
aStream nextPut: $(. | ||
self class storeOn: aStream. | ||
aStream | ||
nextPutAll: ' renameMethod: #'; | ||
nextPutAll: oldSelector; | ||
nextPutAll: ' in: '. | ||
class storeOn: aStream. | ||
aStream | ||
nextPutAll: ' to: #'; | ||
nextPutAll: newSelector; | ||
nextPutAll: ' permutation: '. | ||
permutation storeOn: aStream. | ||
aStream nextPut: $) | ||
] |