Skip to content

Commit

Permalink
Update to use new preview with Extract Method refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin777 committed May 3, 2021
1 parent 1cdb400 commit bbca019
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 38 deletions.
14 changes: 9 additions & 5 deletions src/NautilusRefactoring/NautilusRefactoring.class.st
Expand Up @@ -33,9 +33,13 @@ NautilusRefactoring >> chooseFrom: anArray title: aString lines: aCollection [
]

{ #category : #display }
NautilusRefactoring >> handleMethodNameRequest: aMethodName in: ref [
NautilusRefactoring >> handleMethodNameRequest: aMethodName [
|dialog|
dialog := SycMethodNameEditorPresenter openOn: aMethodName withRefactoring: ref.
dialog := SycMethodNameEditorPresenter
openOn: aMethodName
canRenameArgs: false
canRemoveArgs: false
canAddArgs: false.
dialog cancelled ifTrue: [ CmdCommandAborted signal ].
^ aMethodName
]
Expand All @@ -62,7 +66,7 @@ NautilusRefactoring >> refactoringOptions: aRefactoring [
setOption: #implementorToInline
toUse: [ :ref :imps | self requestImplementorToInline: imps ];
setOption: #methodName
toUse: [ :ref :name | self requestMethodNameFor: name in: ref ];
toUse: [ :name | self requestMethodNameFor: name ];
setOption: #selfArgumentName
toUse: [ :ref | self requestSelfArgumentName ];
setOption: #selectVariableToMoveTo
Expand Down Expand Up @@ -102,8 +106,8 @@ NautilusRefactoring >> requestImplementorToInline: imps [
]

{ #category : #option }
NautilusRefactoring >> requestMethodNameFor: aMethodName in: ref [
^ self handleMethodNameRequest: aMethodName in: ref
NautilusRefactoring >> requestMethodNameFor: aMethodName [
^ self handleMethodNameRequest: aMethodName
]

{ #category : #option }
Expand Down
15 changes: 8 additions & 7 deletions src/Refactoring-Core/RBExtractMethodRefactoring.class.st
Expand Up @@ -249,6 +249,7 @@ RBExtractMethodRefactoring >> getNewMethodName [
newSelector isNil]
whileTrue: [].
parameters := newMethodName arguments asOrderedCollection.
newMethodName renameMap ifNotEmpty: [parameterMap := newMethodName renameMap].
^newSelector asSymbol
]

Expand Down Expand Up @@ -313,7 +314,9 @@ RBExtractMethodRefactoring >> nameNewMethod: aSymbol [
nextPut: $ ;
nextPutAll: arg asString;
nextPut: $ ] ].
modifiedParseTree := RBParseTreeRewriter replace: self methodDelimiter with: newSend in: modifiedParseTree
modifiedParseTree := RBParseTreeRewriter replace: self methodDelimiter with: newSend in: modifiedParseTree.
self parameterMap do: [ :e |
(self parseTreeRewriterClass rename: e newName to: e name) executeTree: modifiedParseTree ]
]

{ #category : #transforming }
Expand All @@ -323,7 +326,7 @@ RBExtractMethodRefactoring >> newExtractedSelector [

{ #category : #accessing }
RBExtractMethodRefactoring >> parameterMap [
^ parameterMap
^ parameterMap ifNil: [ parameterMap := { } ]
]

{ #category : #accessing }
Expand Down Expand Up @@ -369,10 +372,8 @@ RBExtractMethodRefactoring >> remainingTemporaries [

{ #category : #transforming }
RBExtractMethodRefactoring >> renameAllParameters [
parameterMap ifNotNil: [
parameterMap keysAndValuesDo: [ :key : value |
key ~= value ifTrue: [ self renameParameterWith: key to: value ]]
]
self parameterMap do: [ :each |
self renameParameterWith: each name to: each newName ]
]

{ #category : #renaming }
Expand Down Expand Up @@ -471,7 +472,7 @@ RBExtractMethodRefactoring >> validateRenameNode: aParseTree withOldName: oldNam
block
ifNotNil: [ self refactoringError: conditions errorString with: block ]
ifNil: [ self refactoringError: conditions errorString ] ].
(parameterMap values includes: newName) ifTrue: [
(self parameterMap values includes: newName) ifTrue: [
self refactoringError: newName asString , ' is already defined as parameter' ].
(aParseTree whoDefines: newName)
ifNotNil: [ self refactoringError: newName asString , ' is already defined' ].
Expand Down
Expand Up @@ -52,8 +52,8 @@ RBExtractMethodToComponentRefactoring >> extractMethod [
in: class.
refactoring setOption: #methodName
toUse:
[:ref :methodName |
extractedMethodSelector := ref
[:methodName |
extractedMethodSelector := self
uniqueMethodNameFor: methodName arguments size.
methodName
selector: extractedMethodSelector;
Expand Down
4 changes: 2 additions & 2 deletions src/Refactoring-Core/RBRefactoring.class.st
Expand Up @@ -56,7 +56,7 @@ RBRefactoring class >> initializeRefactoringOptions [
put: [ :ref :imps | self error: #implementorToInline ];

at: #methodName
put: [ :ref :methodName | self error: #methodName ];
put: [ :methodName | self error: #methodName ];

at: #selfArgumentName
put: [ :ref | self error: #selfArgumentName ];
Expand Down Expand Up @@ -398,7 +398,7 @@ RBRefactoring >> requestImplementorToInline: implementorsCollection [

{ #category : #requests }
RBRefactoring >> requestMethodNameFor: aMethodName [
^(self options at: #methodName) value: self value: aMethodName
^(self options at: #methodName) value: aMethodName
]

{ #category : #requests }
Expand Down
4 changes: 1 addition & 3 deletions src/Refactoring-Tests-Core/RBExtractMethodTest.class.st
Expand Up @@ -162,9 +162,7 @@ RBExtractMethodTest >> testExtractWithRenamingOfParameters [
self setupMethodNameFor: refactoring toReturn: #foo:.
refactoring
parameterMap:
(Dictionary new
at: #nameStream put: #newParameter;
yourself).
(Array with: ((RBArgumentName name: #nameStream) newName: #newParameter)).
self executeRefactoring: refactoring.
class := refactoring model classNamed: #RBLintRuleTestData.

Expand Down
4 changes: 2 additions & 2 deletions src/Refactoring-Tests-Core/RBRefactoringTest.class.st
Expand Up @@ -478,7 +478,7 @@ RBRefactoringTest >> setupMethodNameFor: aRefactoring toReturn: aSelector [
options := aRefactoring options copy.
options at: #methodName
put:
[:ref :aMethodName |
[:aMethodName |
aMethodName
selector: aSelector;
yourself].
Expand All @@ -491,7 +491,7 @@ RBRefactoringTest >> setupMethodNameFor: aRefactoring toReturn: aSelector withAr
options := aRefactoring options copy.
options at: #methodName
put:
[:ref :aMethodName |
[ :aMethodName |
aMethodName
selector: aSelector;
arguments: stringCollection;
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring2-Transformations/RBTransformation.class.st
Expand Up @@ -46,7 +46,7 @@ RBTransformation class >> initializeRefactoringOptions [
put: [ :ref :imps | self error: #implementorToInline ];

at: #methodName
put: [ :ref :methodName | self error: #methodName ];
put: [ :methodName | self error: #methodName ];

at: #selfArgumentName
put: [ :ref | self error: #selfArgumentName ];
Expand Down
Expand Up @@ -62,17 +62,6 @@ SycChangeMessageSignatureCommand >> canRenameArgs [
^ true
]

{ #category : #actions }
SycChangeMessageSignatureCommand >> computeInvalidArgNames [
| invalidArgNames |
invalidArgNames := Set new.
(model allImplementorsOf: originalMessage selector) do: [ :e | | cm |
cm:=(e realClass >> originalMessage selector).
invalidArgNames addAll: cm argumentNames;
addAll: cm origin instVarNames ].
^ invalidArgNames
]

{ #category : #execution }
SycChangeMessageSignatureCommand >> createRefactoring [
self subclassResponsibility
Expand Down Expand Up @@ -109,7 +98,7 @@ SycChangeMessageSignatureCommand >> prepareFullExecutionInContext: aToolContext
{ #category : #requesting }
SycChangeMessageSignatureCommand >> requestNewMessageIn: aToolContext [
| methodName dialog invalidArgNames |
invalidArgNames := self computeInvalidArgNames.
invalidArgNames := self computeInvalidArgNamesForSelector: originalMessage selector.
methodName := RBMethodName selector: originalMessage selector arguments: originalMessage argumentNames.
dialog := SycMethodNameEditorPresenter openOn: methodName withInvalidArgs: invalidArgNames
canRenameArgs: self canRenameArgs
Expand Down
Expand Up @@ -6,6 +6,17 @@ Trait {
#category : #'SystemCommands-RefactoringSupport'
}

{ #category : #actions }
TRefactoringCommandSupport >> computeInvalidArgNamesForSelector: aSymbol [
| invalidArgNames |
invalidArgNames := Set new.
(model allImplementorsOf: aSymbol) do: [ :e | | cm |
cm:=(e realClass >> aSymbol).
invalidArgNames addAll: cm argumentNames;
addAll: cm origin instVarNames ].
^ invalidArgNames
]

{ #category : #initialization }
TRefactoringCommandSupport >> initializeDefaultOptionsOf: refactoring [

Expand Down
Expand Up @@ -4,6 +4,8 @@ I am a command to extract selected ast node into separate method
Class {
#name : #SycExtractMethodCommand,
#superclass : #SycSourceCodeCommand,
#traits : 'TRefactoringCommandSupport',
#classTraits : 'TRefactoringCommandSupport classTrait',
#instVars : [
'selectedTextInterval'
],
Expand Down Expand Up @@ -55,7 +57,7 @@ SycExtractMethodCommand >> isComplexRefactoring [
{ #category : #execution }
SycExtractMethodCommand >> readParametersFromContext: aSourceCodeContext [
super readParametersFromContext: aSourceCodeContext.

self setUpModelFromContext: aSourceCodeContext.
selectedTextInterval := aSourceCodeContext selectedTextInterval.
]

Expand All @@ -81,10 +83,14 @@ SycExtractMethodCommand >> setUpOptionToChangeExtractionClass: refactoring [
SycExtractMethodCommand >> setUpOptionToChangeMethodNameDuring: refactoring [

| dialog |
refactoring setOption: #methodName toUse: [ :ref :methodName |
refactoring setOption: #methodName toUse: [ :methodName | | invalidArgs |
invalidArgs := self computeInvalidArgNamesForSelector: method selector.
dialog := SycMethodNameEditorPresenter
openOn: methodName
withRefactoring: ref.
openOn: methodName
withInvalidArgs: invalidArgs
canRenameArgs: true
canRemoveArgs: false
canAddArgs: false.
dialog cancelled ifTrue: [ CmdCommandAborted signal ].
methodName ]
]
Expand Down

0 comments on commit bbca019

Please sign in to comment.