/
SycExtractMethodCommand.class.st
91 lines (73 loc) · 2.7 KB
/
SycExtractMethodCommand.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"
I am a command to extract selected ast node into separate method
"
Class {
#name : #SycExtractMethodCommand,
#superclass : #SycSourceCodeCommand,
#instVars : [
'selectedTextInterval'
],
#category : #'SystemCommands-SourceCodeCommands'
}
{ #category : #execution }
SycExtractMethodCommand class >> canBeExecutedInContext: aSourceCodeContext [
super canBeExecutedInContext: aSourceCodeContext.
^aSourceCodeContext isMethodSelected not
]
{ #category : #accessing }
SycExtractMethodCommand >> defaultMenuIconName [
^ #glamorousRestart
]
{ #category : #accessing }
SycExtractMethodCommand >> defaultMenuItemName [
^ 'Extract method'
]
{ #category : #execution }
SycExtractMethodCommand >> execute [
| selectedInterval refactoring |
selectedInterval := selectedTextInterval ifEmpty: [
sourceNode sourceInterval ].
refactoring := RBExtractMethodAndOccurrences
extract: selectedInterval
from: method selector
in: method origin.
self setUpOptionToUseExistingMethodDuring: refactoring.
self setUpOptionToOverrideExistingMethodDuring: refactoring.
self setUpOptionToChangeMethodNameDuring: refactoring.
self setUpOptionToSearchInHierarchyDuring: refactoring.
self executeRefactoring: refactoring
]
{ #category : #execution }
SycExtractMethodCommand >> readParametersFromContext: aSourceCodeContext [
super readParametersFromContext: aSourceCodeContext.
selectedTextInterval := aSourceCodeContext selectedTextInterval
]
{ #category : #execution }
SycExtractMethodCommand >> setUpOptionToChangeMethodNameDuring: refactoring [
| dialog |
refactoring setOption: #methodName toUse: [ :ref :methodName |
dialog := SycMethodNameEditorPresenter
openOn: methodName
withRefactoring: ref.
dialog cancelled ifTrue: [ CmdCommandAborted signal ].
methodName ]
]
{ #category : #execution }
SycExtractMethodCommand >> setUpOptionToOverrideExistingMethodDuring: aRefactoring [
aRefactoring setOption: #alreadyDefined toUse: [ :ref :class :selector |
ref refactoringWarning: 'Method ', selector printString, ' will override method in ', class name].
]
{ #category : #execution }
SycExtractMethodCommand >> setUpOptionToSearchInHierarchyDuring: refactoring [
refactoring setOption: #searchInAllHierarchy toUse: [
UIManager default
confirm: 'Do you want to search occurrences in all hierarchy?'
label: 'Warning'].
]
{ #category : #execution }
SycExtractMethodCommand >> setUpOptionToUseExistingMethodDuring: aRefactoring [
aRefactoring setOption: #useExistingMethod toUse: [ :ref :selector |
UIManager default
confirm: 'Do you want use existing method ', selector printString, '?'
label: 'Warninig'].
]