Skip to content

Commit 64468cc

Browse files
authored
Merge pull request #18685 from carolahp/creanup/syc-new-method-extract-command2
ReExtractMethodDriver fixes from Balsa's review
2 parents 0815575 + 16c6052 commit 64468cc

File tree

6 files changed

+87
-17
lines changed

6 files changed

+87
-17
lines changed

src/Refactoring-Core-Tests/RBSubtreeDoesNotContainReturnConditionTest.class.st

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ RBSubtreeDoesNotContainReturnConditionTest >> testFailureWhenSubtreeContainsRetu
2121
^ 'Just for test purpose' "maybe this is a bad thing to do in a test, I can change it if needed"
2222
]
2323

24+
{ #category : 'tests' }
25+
RBSubtreeDoesNotContainReturnConditionTest >> testFailureWhenSubtreeContainsReturnInBlockExpectFalse [
26+
27+
| precondition model class parseTree subtree x |
28+
model := self modelOnClasses: { self class }.
29+
class := model classObjectFor: self class.
30+
parseTree := class parseTreeForSelector: self selector.
31+
subtree := parseTree extractSubtreeWith: 'x:=[^1]'.
32+
33+
precondition := ReSubtreeDoesNotContainReturnCondition new subtree: subtree.
34+
35+
self deny: precondition check.
36+
x:=[^1] "maybe this is a bad thing to do in a test, I can change it if needed"
37+
]
38+
2439
{ #category : 'tests' }
2540
RBSubtreeDoesNotContainReturnConditionTest >> testSubtreeDoesNotContainReturnExpectTrue [
2641

@@ -34,3 +49,18 @@ RBSubtreeDoesNotContainReturnConditionTest >> testSubtreeDoesNotContainReturnExp
3449

3550
self assert: precondition check
3651
]
52+
53+
{ #category : 'tests' }
54+
RBSubtreeDoesNotContainReturnConditionTest >> testSubtreeIsAnAssignmentExpectTrue [
55+
56+
| precondition model class parseTree subtree x |
57+
model := self modelOnClasses: { self class }.
58+
class := model classObjectFor: self class.
59+
parseTree := class parseTreeForSelector: self selector.
60+
subtree := parseTree extractSubtreeWith: 'x := 42'.
61+
62+
precondition := ReSubtreeDoesNotContainReturnCondition new subtree: subtree.
63+
64+
self assert: precondition check.
65+
x := 42 "maybe this is a bad thing to do in a test, I can change it if needed"
66+
]

src/Refactoring-Core/ReHasSameExitPointAsItsMethodCondition.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ ReHasSameExitPointAsItsMethodCondition >> check [
1919
{ #category : 'displaying' }
2020
ReHasSameExitPointAsItsMethodCondition >> violationMessageOn: aStream [
2121

22-
^ aStream nextPutAll: 'Extracting guard clauses and other expressions that directly affect a method’s execution flow may result in unreachable code in the original method.'
22+
^ aStream nextPutAll: 'Extracting guard clauses and other expressions that directly affect a method’s execution flow may cause unexpected behavior in the original method.'
2323
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Class {
2+
#name : 'ReExtractAndBrowseMethodOverridesChoice',
3+
#superclass : 'ReMethodChoice',
4+
#category : 'Refactoring-UI-Choices',
5+
#package : 'Refactoring-UI',
6+
#tag : 'Choices'
7+
}
8+
9+
{ #category : 'accessing' }
10+
ReExtractAndBrowseMethodOverridesChoice >> action [
11+
12+
driver extractMethod.
13+
driver browseOverrides
14+
]
15+
16+
{ #category : 'accessing' }
17+
ReExtractAndBrowseMethodOverridesChoice >> description [
18+
19+
^ description ifNil: [ description := 'Extract method and browse existing methods that will then be overriden' ]
20+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Class {
2+
#name : 'ReExtractMethodChoice',
3+
#superclass : 'ReMethodChoice',
4+
#category : 'Refactoring-UI-Choices',
5+
#package : 'Refactoring-UI',
6+
#tag : 'Choices'
7+
}
8+
9+
{ #category : 'accessing' }
10+
ReExtractMethodChoice >> action [
11+
12+
driver extractMethod
13+
]
14+
15+
{ #category : 'accessing' }
16+
ReExtractMethodChoice >> description [
17+
18+
^ description ifNil: [ description := 'Extract method' ]
19+
]

src/Refactoring-UI/ReExtractMethodDriver.class.st

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ ReExtractMethodDriver >> breakingChoices [
2828
items := OrderedCollection new.
2929

3030
(notOverride check and: sameExitPoint check) ifFalse: [
31-
items add: (ReRenameMethodChoice new
31+
items add: (ReExtractMethodChoice new
3232
driver: self;
33-
description: 'Extract method';
3433
yourself) ].
3534

3635
notOverride check ifFalse: [ "These choices are exclusive to notOverride"
37-
items add: (ReRenameAndBrowseMethodOverridesChoice new
36+
items add: (ReExtractAndBrowseMethodOverridesChoice new
3837
driver: self;
39-
description: 'Extract method and browse existing methods that will then be overriden';
4038
yourself).
4139
items add: (ReBrowseMethodOverridesChoice new
4240
driver: self;
@@ -49,10 +47,9 @@ ReExtractMethodDriver >> breakingChoices [
4947
{ #category : 'actions' }
5048
ReExtractMethodDriver >> browseOverrides [
5149

52-
| conditions overrides |
53-
conditions := refactoring failedBreakingChangePreconditions.
54-
overrides := conditions flatCollect: [ :cond |
55-
cond violators collect: [ :cls | cls realClass methodNamed: newMessage methodName asSymbol ] ].
50+
| overrides |
51+
overrides := notOverride violators collect: [ :cls | cls realClass methodNamed: newMessage methodName asSymbol ].
52+
5653
overrides do: [ :method | method browse ]
5754
]
5855

@@ -118,6 +115,12 @@ ReExtractMethodDriver >> extract: aString from: compiledMethod in: aClass [
118115
body := aString
119116
]
120117

118+
{ #category : 'actions' }
119+
ReExtractMethodDriver >> extractMethod [
120+
121+
^ self applyChanges
122+
]
123+
121124
{ #category : 'execution' }
122125
ReExtractMethodDriver >> handleBreakingChanges [
123126

@@ -149,14 +152,6 @@ ReExtractMethodDriver >> methodNameEditorPresenterClass: aClass [
149152
methodNameEditorPresenterClass := aClass
150153
]
151154

152-
{ #category : 'actions' }
153-
ReExtractMethodDriver >> renameMethod [
154-
"Eventhough we are not renaming methods, but extracting them, we implement this action to reuse both
155-
ReRenameAndBrowseMethodOverridesChoice and ReRenameMethodChoice"
156-
157-
^ self applyChanges
158-
]
159-
160155
{ #category : 'accessing' }
161156
ReExtractMethodDriver >> requestDialogWith: methodName [
162157
"This is lazy loaded and tests expect lazy loading, because they set `requestDialog`

src/Refactoring-UI/StMethodNameEditorPresenter.class.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ StMethodNameEditorPresenter >> canRenameArgs: anObject [
228228
argumentsList items do: [ :arg | arg canBeRenamed: anObject ]
229229
]
230230

231+
{ #category : 'accessing' }
232+
StMethodNameEditorPresenter >> cancelled [
233+
234+
^ self withWindowDo: #cancelled
235+
]
236+
231237
{ #category : 'action' }
232238
StMethodNameEditorPresenter >> computePermutation [
233239

0 commit comments

Comments
 (0)