-
-
Notifications
You must be signed in to change notification settings - Fork 408
[Refactoring] Driver improvement for temp to instance variable #18965
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
Merged
Ducasse
merged 26 commits into
pharo-project:Pharo14
from
AlexisCnockaert:Refactoring/newdriver
Nov 27, 2025
Merged
Changes from all commits
Commits
Show all changes
26 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 3f509b2
Last changes for driver implementation
AlexisCnockaert f2c41d1
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert 553b828
permission revert
AlexisCnockaert e341041
Merge branch 'refactoring/newdriver' of github.com:AlexisCnockaert/ph…
AlexisCnockaert 66b978e
remove unwanted class
AlexisCnockaert 2a425d4
Delete src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice…
AlexisCnockaert 1b216c9
Update expected size of refactoring changes to 3
AlexisCnockaert f53b5f1
Fix failing test and extra method display on driver!
7937ade
Merge 66b978ec8e15b0e99d36378705c07fd5f1c9a059
6875cf6
Merge branch 'Pharo14' into refactoring/newdriver
AlexisCnockaert 5e01f0b
Merge branch 'Pharo14' into Refactoring/newdriver
AlexisCnockaert 3f0daec
Merge 5e01f0b034a9b82d919dc6188b7735f58e8b1a6f
AlexisCnockaert e8d0d18
Renamed clas condition name and browse references action for driver
AlexisCnockaert d926372
Merge branch 'Pharo14' into Refactoring/newdriver
AlexisCnockaert b672d5c
last changes!!
AlexisCnockaert 7b516e7
Merge d9263726c9d076884cff617f86073506ba3be759
AlexisCnockaert bd969c3
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
79 changes: 79 additions & 0 deletions
79
src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarCondition.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,79 @@ | ||
| " | ||
| I check if temporary variable name is used in other methods of the class. | ||
| " | ||
| Class { | ||
| #name : 'ReMultipleMethodsDontReferToTempVarCondition', | ||
| #superclass : 'ReVariableNameCondition', | ||
| #instVars : [ | ||
| 'class', | ||
| 'selector' | ||
| ], | ||
| #category : 'Refactoring-Core-Conditions', | ||
| #package : 'Refactoring-Core', | ||
| #tag : 'Conditions' | ||
| } | ||
|
|
||
| { #category : 'instance creation' } | ||
| ReMultipleMethodsDontReferToTempVarCondition class >> name: aString class: aClass selector: aSelector [ | ||
|
|
||
| ^ (self name: aString) | ||
| class: aClass; | ||
| selector: aSelector yourself | ||
| ] | ||
|
|
||
| { #category : 'checking' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> check [ | ||
|
|
||
| ^ self violators isEmpty | ||
| ] | ||
|
|
||
| { #category : 'setter' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> class: aRBClass [ | ||
|
|
||
| class := aRBClass. | ||
|
|
||
| ] | ||
|
|
||
| { #category : 'utilities' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> 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' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> selector: aSelector [ | ||
|
|
||
| selector := aSelector | ||
| ] | ||
|
|
||
| { #category : 'displaying' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> 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' } | ||
| ReMultipleMethodsDontReferToTempVarCondition >> 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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
| Class { | ||
| #name : 'ReClassToConvertTemporaryToInstanceVariable', | ||
| #superclass : 'Object', | ||
| #instVars : [ | ||
| 'instVar' | ||
| ], | ||
| #category : 'Refactoring-DataForTesting-ForConvertingVariables', | ||
| #package : 'Refactoring-DataForTesting', | ||
| #tag : 'ForConvertingVariables' | ||
| } | ||
|
|
||
|
Member
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. We should add the scenario where a subclass has the same name as the temp that we want to convert. |
||
| { #category : 'action' } | ||
| ReClassToConvertTemporaryToInstanceVariable >> doAction1 [ | ||
|
|
||
| | temp | | ||
| temp := 35. | ||
|
|
||
| ^ temp | ||
| ] | ||
|
|
||
| { #category : 'action' } | ||
| ReClassToConvertTemporaryToInstanceVariable >> doAction2 [ | ||
|
|
||
| | instVar | | ||
| instVar := 3. | ||
| ^ instVar | ||
| ] | ||
|
|
||
| { #category : 'initialization' } | ||
| ReClassToConvertTemporaryToInstanceVariable >> initialize [ | ||
|
|
||
| <ignoreUnusedVariables: #( #instVar )> | ||
| super initialize | ||
| ] | ||
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: 2. | ||
|
|
||
| ] |
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 [ | ||
|
|
||
| ^ description ifNil: [ description := 'Browse the methods' ] | ||
| ] |
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.
I do not really undersyand what is removeTemporyOfClass: doing so it is difficult for me to get further.
Trying to understand the logic: I think that there were something we should keep.
If one of the subclass got the same instance variable that the temp we want to convert, then we remove it from that class and defines it in the root class.
So why removing this logic.
Because now if a subclass has the variable with the same name we force the guy to do a pullUp.
May be this is better this way the developer has to see it.