-
-
Notifications
You must be signed in to change notification settings - Fork 420
[Refactoring] Driver improvement for temp to instance variable #18821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
AlexisCnockaert
wants to merge
15
commits into
pharo-project:Pharo14
from
AlexisCnockaert:refactoring/newdriver
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7f93db9
Driver improvement for temp to instance variable
AlexisCnockaert 497bf9a
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert 3fa60b3
Merge branch 'Pharo14' into refactoring/newdriver
Ducasse 5396e18
Almost done, missing 1 single action
AlexisCnockaert 901503a
Merge 3fa60b3b000d6cf5ba6a0f388c51aa2268745d8c
AlexisCnockaert 7e2d58c
be757cd
remove accidental file
AlexisCnockaert c5fd2f3
?
AlexisCnockaert 3c78684
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert f2c41d1
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert 553b828
permission revert
AlexisCnockaert e341041
Merge branch 'refactoring/newdriver' of github.com:AlexisCnockaert/ph…
AlexisCnockaert 2a425d4
Delete src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice…
AlexisCnockaert 1b216c9
Update expected size of refactoring changes to 3
AlexisCnockaert 6875cf6
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st
This file contains hidden or 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,76 @@ | ||
| Class { | ||
| #name : 'ReMultipleMethodsDontReferToTempVarsCondition', | ||
| #superclass : 'ReVariableNameCondition', | ||
| #instVars : [ | ||
| 'class', | ||
| 'selector' | ||
| ], | ||
| #category : 'Refactoring-Core-Conditions', | ||
| #package : 'Refactoring-Core', | ||
| #tag : 'Conditions' | ||
| } | ||
|
|
||
| { #category : 'instance creation' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition class >> name: aString class: aClass selector: aSelector [ | ||
|
|
||
| ^ (self name: aString) | ||
| class: aClass; | ||
| selector: aSelector yourself | ||
| ] | ||
|
|
||
| { #category : 'checking' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> check [ | ||
|
|
||
| ^ self violators isEmpty | ||
| ] | ||
|
|
||
| { #category : 'setter' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> class: aRBClass [ | ||
|
|
||
| class := aRBClass. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'utilities' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> multipleMethodsDefiningTemporary: aString in: aClass ignore: aBlock [ | ||
|
|
||
| | searcher methods method | | ||
| searcher := OCParseTreeSearcher new. | ||
| methods := Set new. | ||
| method := nil. | ||
|
|
||
| searcher matches: aString do: [ :aNode :answer | methods add: method ]. | ||
| aClass withAllSubclasses do: [ :cls | | ||
| cls selectors do: [ :each | | ||
| (aBlock value: cls value: each) ifFalse: [ | ||
| | parseTree | | ||
| method := cls methodFor: each. | ||
| parseTree := cls parseTreeForSelector: each. | ||
| parseTree ifNotNil: [ searcher executeTree: parseTree ] ] ] ]. | ||
| ^ methods | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> selector: aSelector [ | ||
|
|
||
| selector := aSelector | ||
| ] | ||
|
|
||
| { #category : 'displaying' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> violationMessageOn: aStream [ | ||
|
|
||
| self violators ifEmpty: [ ^ self ]. | ||
| ^ aStream | ||
| nextPutAll: 'More than one method defines temporary variable '; | ||
| nextPutAll: name; | ||
| nextPutAll: ': '; | ||
| nextPutAll: (self violators collect: [ :m | m selector ]) asArray asString | ||
| ] | ||
|
|
||
| { #category : 'checking' } | ||
| ReMultipleMethodsDontReferToTempVarsCondition >> violators [ | ||
|
|
||
| | methods | | ||
| methods := self multipleMethodsDefiningTemporary: name in: class ignore: [ :cls :selectors | false ]. | ||
| ^ methods reject: [ :m | m selector = selector ] | ||
| ] |
This file contains hidden or 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
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
src/Refactoring-DataForTesting/ReClassToConvertTemporaryToInstanceVariable.class.st
This file contains hidden or 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,27 @@ | ||
| Class { | ||
| #name : 'ReClassToConvertTemporaryToInstanceVariable', | ||
| #superclass : 'Object', | ||
| #instVars : [ | ||
| 'instVar' | ||
| ], | ||
| #category : 'Refactoring-DataForTesting-ForConvertingVariables', | ||
| #package : 'Refactoring-DataForTesting', | ||
| #tag : 'ForConvertingVariables' | ||
| } | ||
|
|
||
| { #category : 'action' } | ||
| ReClassToConvertTemporaryToInstanceVariable >> doAction1 [ | ||
|
|
||
| | temp | | ||
| temp := 35. | ||
|
|
||
| ^ temp | ||
| ] | ||
|
|
||
| { #category : 'action' } | ||
| ReClassToConvertTemporaryToInstanceVariable >> doAction2 [ | ||
|
|
||
| | instVar | | ||
| instVar := 3. | ||
| ^ instVar | ||
| ] |
50 changes: 50 additions & 0 deletions
50
src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st
This file contains hidden or 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,50 @@ | ||
| Class { | ||
| #name : 'ReConvertTemporaryToInstanceVariableDriverTest', | ||
| #superclass : 'ReDriverTest', | ||
| #instVars : [ | ||
| 'testingEnvironment' | ||
| ], | ||
| #category : 'Refactoring-UI-Tests-Driver', | ||
| #package : 'Refactoring-UI-Tests', | ||
| #tag : 'Driver' | ||
| } | ||
|
|
||
| { #category : 'getter' } | ||
| ReConvertTemporaryToInstanceVariableDriverTest >> classToConvertTemporaryToInstanceVariable [ | ||
|
|
||
| ^ ReClassToConvertTemporaryToInstanceVariable | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| ReConvertTemporaryToInstanceVariableDriverTest >> setUp [ | ||
|
|
||
| super setUp. | ||
| testingEnvironment := RBClassEnvironment classes: self classToConvertTemporaryToInstanceVariable withAllSubclasses | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| ReConvertTemporaryToInstanceVariableDriverTest >> testConvertTempFailure [ | ||
|
|
||
| | driver | | ||
| driver := ReConvertTemporaryToInstanceVariableDriver new. | ||
| self setUpDriver: driver. | ||
| driver class: self classToConvertTemporaryToInstanceVariable selector: #doAction2 variable: 'instVar'. | ||
|
|
||
| driver runRefactoring. | ||
|
|
||
| self assert: driver refactoring changes changes size equals: 0 | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| ReConvertTemporaryToInstanceVariableDriverTest >> testConvertTempSuccessfully [ | ||
|
|
||
| | driver | | ||
| driver := ReConvertTemporaryToInstanceVariableDriver new. | ||
| self setUpDriver: driver. | ||
| driver class: self classToConvertTemporaryToInstanceVariable selector: #doAction1 variable: 'temp'. | ||
|
|
||
| driver runRefactoring. | ||
|
|
||
| self assert: driver refactoring changes changes size equals: 3. | ||
|
|
||
| ] |
This file contains hidden or 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
This file contains hidden or 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,19 @@ | ||
| Class { | ||
| #name : 'ReBrowseMethodsChoice', | ||
| #superclass : 'ReMethodChoice', | ||
| #category : 'Refactoring-UI-Choices', | ||
| #package : 'Refactoring-UI', | ||
| #tag : 'Choices' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| ReBrowseMethodsChoice >> action [ | ||
|
|
||
| driver browseMethods | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| ReBrowseMethodsChoice >> description [ | ||
|
|
||
| ^ 'Browse the methods' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This description is almost the same as |
||
| ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a second PR we should remove this pop up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I suggested Alexis to leave it like this for the moment.
After merging this PR refactoring the method will be way easier