From 7f93db9895a92f293a70a4f0f8a615a031a2204f Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Fri, 31 Oct 2025 16:01:48 +0100 Subject: [PATCH 1/8] Driver improvement for temp to instance variable --- src/Refactoring-Core/RBCondition.class.st | 38 ---------- ...raryToInstanceVariableRefactoring.class.st | 43 +++++++---- ...thodsDontReferToTempVarsCondition.class.st | 76 +++++++++++++++++++ src/Refactoring-Core/ReRefactoring.class.st | 3 +- ...blesNotReadBeforeWrittenCondition.class.st | 1 + ...TemporaryToInstanceVariableDriver.class.st | 73 +++++++++++++++++- ...stanceVariableAndRemoveTempChoice.class.st | 19 +++++ 7 files changed, 195 insertions(+), 58 deletions(-) create mode 100644 src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st create mode 100644 src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st diff --git a/src/Refactoring-Core/RBCondition.class.st b/src/Refactoring-Core/RBCondition.class.st index 909afcea0a4..f2a0354e28e 100644 --- a/src/Refactoring-Core/RBCondition.class.st +++ b/src/Refactoring-Core/RBCondition.class.st @@ -56,25 +56,6 @@ RBCondition class >> checkInstanceVariableName: aName in: aClass [ ^ OCScanner isVariable: string ] -{ #category : 'instance creation' } -RBCondition class >> checkNotMultipleTemporaryDefinitionsOf: aString in: aClass [ - - | condition | - condition := self new. - condition - block: [ - | methods | - methods := self multipleMethodsDefiningTemporary: aString in: aClass ignore: [ :class :selector | false ]. - methods size > 1 - ifTrue: [ - condition errorMacro: - 'More than one method defines temporary variable ' , aString , ': ' , (methods collect: [ :m | m selector ]) asString. - false ] - ifFalse: [ true ] ] - errorString: aClass printString , ' <1?:does not >define<1?s:> temporary variable ' , aString. - ^ condition -] - { #category : 'instance creation' } RBCondition class >> definesClassVariable: aString in: aClass [ ^self new @@ -374,25 +355,6 @@ RBCondition class >> methodDefiningTemporary: aString in: aClass ignore: aBlock ^ nil ] -{ #category : 'utilities' } -RBCondition class >> 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: [ :class | - class selectors do: [ :each | - (aBlock value: class value: each) ifFalse: [ - | parseTree | - method := class methodFor: each. - parseTree := class parseTreeForSelector: each. - parseTree ifNotNil: [ searcher executeTree: parseTree ] ] ] ]. - ^ methods -] - { #category : 'instance creation' } RBCondition class >> referencesClassVariable: aString in: aClass [ diff --git a/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st b/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st index b3f3a7dad17..1ffbac12d31 100644 --- a/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st +++ b/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st @@ -114,17 +114,9 @@ RBTemporaryToInstanceVariableRefactoring >> applicabilityPreconditions [ RBTemporaryToInstanceVariableRefactoring >> breakingChangePreconditions [ ^ { - (RBCondition withBlock: [ - (class allSubclasses anySatisfy: [ :cls | cls definesInstanceVariable: temporaryVariableName asString ]) ifTrue: [ - self refactoringWarning: - ('One or more subclasses of <1p> already defines aninstance variable with the same name. Proceed anyway?' - expandMacrosWith: class name) ]. - true ]). - (RBCondition checkNotMultipleTemporaryDefinitionsOf: temporaryVariableName in: class). - (ReVariablesNotReadBeforeWrittenCondition new - subtree: parseTree; - variables: temporaryVariableName; - checkForTemporaryVariables: true) } + self preconditionNoSubclassDefinesVar. + self preconditionNoMultipleTempOccurences. + self preconditionNoReadBeforeWritten } ] { #category : 'initialization' } @@ -143,6 +135,31 @@ RBTemporaryToInstanceVariableRefactoring >> isTemporaryVariableNameValid [ self refactoringError: temporaryVariableName , ' is a block parameter' ] ] +{ #category : 'as yet unclassified' } +RBTemporaryToInstanceVariableRefactoring >> preconditionNoMultipleTempOccurences [ + + ^ ReMultipleMethodsDontReferToTempVarsCondition name: temporaryVariableName class: class selector: selector +] + +{ #category : 'as yet unclassified' } +RBTemporaryToInstanceVariableRefactoring >> preconditionNoReadBeforeWritten [ + + ^ ReVariablesNotReadBeforeWrittenCondition new + subtree: parseTree; + variables: temporaryVariableName; + checkForTemporaryVariables: true +] + +{ #category : 'as yet unclassified' } +RBTemporaryToInstanceVariableRefactoring >> preconditionNoSubclassDefinesVar [ + + ^ RBCondition + withBlock: [ (class allSubclasses anySatisfy: [ :cls | cls definesInstanceVariable: temporaryVariableName asString ]) not ] + errorString: + ('One or more subclasses of <1p> already defines aninstance variable with the same name. Proceed anyway?' + expandMacrosWith: class name) +] + { #category : 'preconditions' } RBTemporaryToInstanceVariableRefactoring >> preconditions [ @@ -159,10 +176,6 @@ RBTemporaryToInstanceVariableRefactoring >> prepareForExecution [ RBTemporaryToInstanceVariableRefactoring >> privateTransform [ self removeTemporaryOfClass: class. - class allSubclasses do: [ :cls | - (cls definesInstanceVariable: temporaryVariableName) - ifTrue: [ cls removeInstanceVariable: temporaryVariableName ] - ifFalse: [ self removeTemporaryOfClass: cls ] ]. class addInstanceVariable: temporaryVariableName ] diff --git a/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st b/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st new file mode 100644 index 00000000000..185d6865e83 --- /dev/null +++ b/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st @@ -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 : 'as yet unclassified' } +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 ] +] diff --git a/src/Refactoring-Core/ReRefactoring.class.st b/src/Refactoring-Core/ReRefactoring.class.st index ab1d647b276..9b73fdf1ce5 100644 --- a/src/Refactoring-Core/ReRefactoring.class.st +++ b/src/Refactoring-Core/ReRefactoring.class.st @@ -66,10 +66,11 @@ ReRefactoring >> canReferenceVariable: aString in: aClass [ { #category : 'scripting api - conditions' } ReRefactoring >> checkBreakingChangePreconditions [ "Check a preconditions and raise an error on violations. This method is part of the scripting API since it raises an error." - + | failedPreconditions | failedPreconditions := self failedBreakingChangePreconditions. failedPreconditions ifEmpty: [ ^ self ]. + RBRefactoringWarning signalFor: failedPreconditions ] diff --git a/src/Refactoring-Core/ReVariablesNotReadBeforeWrittenCondition.class.st b/src/Refactoring-Core/ReVariablesNotReadBeforeWrittenCondition.class.st index 479a0ea8939..3b6fc0da6c5 100644 --- a/src/Refactoring-Core/ReVariablesNotReadBeforeWrittenCondition.class.st +++ b/src/Refactoring-Core/ReVariablesNotReadBeforeWrittenCondition.class.st @@ -48,6 +48,7 @@ ReVariablesNotReadBeforeWrittenCondition >> variables: aCollection [ { #category : 'displaying' } ReVariablesNotReadBeforeWrittenCondition >> violationMessageOn: aStream [ + self check ifTrue: [ ^ self ]. aStream nextPutAll: 'Cannot extract selected code because variables: '; nextPutAll: variables asString; diff --git a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st index b93c8bd83d6..cfd7a37d959 100644 --- a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st +++ b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st @@ -4,13 +4,25 @@ Class { #instVars : [ 'class', 'variable', - 'selector' + 'selector', + 'subclassesNotDefiningVar', + 'notMultipleTempOccurences', + 'noReadBeforeWritten' ], #category : 'Refactoring-UI-Drivers', #package : 'Refactoring-UI', #tag : 'Drivers' } +{ #category : 'execution' } +ReConvertTemporaryToInstanceVariableDriver >> breakingChoices [ + + | items | + items := OrderedCollection new. + subclassesNotDefiningVar check ifFalse: [ items add: (ReBrowseClassReferencesChoice new driver: self) ]. + ^ items +] + { #category : 'instance creation' } ReConvertTemporaryToInstanceVariableDriver >> class: aClass selector: aSelector variable: aVariable [ @@ -22,16 +34,61 @@ ReConvertTemporaryToInstanceVariableDriver >> class: aClass selector: aSelector { #category : 'resources' } ReConvertTemporaryToInstanceVariableDriver >> configureRefactoring [ - refactoring := RBTemporaryToInstanceVariableTransformation class: class selector: selector variable: variable. + refactoring := RBTemporaryToInstanceVariableRefactoring class: class selector: selector variable: variable. refactoring prepareForExecution ] +{ #category : 'configuration' } +ReConvertTemporaryToInstanceVariableDriver >> defaultSelectDialog [ + + ^ super defaultSelectDialog + extent: 400@1200; + title: 'There are potential breaking changes!'; + label: self labelBasedOnBreakingChanges; + items: self breakingChoices; + display: [ :each | each description ]; + displayIcon: [ :each | self iconNamed: each systemIconName ]; + openModal +] + +{ #category : 'execution' } +ReConvertTemporaryToInstanceVariableDriver >> handleBreakingChanges [ + + | select | + select := self selectDialog. + select ifNotNil: [ select action ] +] + +{ #category : 'ui - dialogs' } +ReConvertTemporaryToInstanceVariableDriver >> labelBasedOnBreakingChanges [ + + ^ String streamContents: [ :stream | + subclassesNotDefiningVar violationMessageOn: stream. + stream cr. + notMultipleTempOccurences violationMessageOn: stream. + stream cr. + noReadBeforeWritten violationMessageOn: stream. + stream cr. + stream nextPutAll: 'Select a strategy' ] +] + +{ #category : 'as yet unclassified' } +ReConvertTemporaryToInstanceVariableDriver >> pushUpInstanceVariableAndRemoveTemp [ + + +] + { #category : 'execution' } ReConvertTemporaryToInstanceVariableDriver >> runRefactoring [ self configureRefactoring. - "TODO" - self applyChanges + refactoring failedApplicabilityPreconditions ifNotEmpty: [ :conditions | + self informConditions: conditions. + ^ false ]. + self setBreakingChangesPreconditions. + subclassesNotDefiningVar check & notMultipleTempOccurences check & noReadBeforeWritten check + ifTrue: [ self applyChanges ] + ifFalse: [ self handleBreakingChanges ] ] { #category : 'instance creation' } @@ -42,3 +99,11 @@ ReConvertTemporaryToInstanceVariableDriver >> scopes: aScope class: aClass selec selector := aSelector. class := aClass ] + +{ #category : 'initialization' } +ReConvertTemporaryToInstanceVariableDriver >> setBreakingChangesPreconditions [ + + subclassesNotDefiningVar := refactoring preconditionNoSubclassDefinesVar. + notMultipleTempOccurences := refactoring preconditionNoMultipleTempOccurences. + noReadBeforeWritten := refactoring preconditionNoReadBeforeWritten +] diff --git a/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st b/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st new file mode 100644 index 00000000000..4c9900036d9 --- /dev/null +++ b/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st @@ -0,0 +1,19 @@ +Class { + #name : 'RePushUpInstanceVariableAndRemoveTempChoice', + #superclass : 'ReVariableChoice', + #category : 'Refactoring-UI-Choices', + #package : 'Refactoring-UI', + #tag : 'Choices' +} + +{ #category : 'accessing' } +RePushUpInstanceVariableAndRemoveTempChoice >> action [ + + driver pushUpInstanceVariableAndRemoveTemp +] + +{ #category : 'accessing' } +RePushUpInstanceVariableAndRemoveTempChoice >> description [ + + ^ 'Push up instance variable from subclass and remove temporary variable' +] From 5396e183e7d49ef70c0441782efd72cc300d87fd Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Thu, 13 Nov 2025 17:00:06 +0100 Subject: [PATCH 2/8] Almost done, missing 1 single action --- ...raryToInstanceVariableRefactoring.class.st | 6 +-- ...thodsDontReferToTempVarsCondition.class.st | 2 +- ...onvertTemporaryToInstanceVariable.class.st | 27 ++++++++++ ...oraryToInstanceVariableDriverTest.class.st | 50 +++++++++++++++++++ .../ReBrowseMethodChoice.class.st | 2 +- .../ReBrowseMethodsChoice.class.st | 19 +++++++ ...TemporaryToInstanceVariableDriver.class.st | 11 +++- 7 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 src/Refactoring-DataForTesting/ReClassToConvertTemporaryToInstanceVariable.class.st create mode 100644 src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st create mode 100644 src/Refactoring-UI/ReBrowseMethodsChoice.class.st diff --git a/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st b/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st index 1ffbac12d31..6b8d34e93a6 100644 --- a/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st +++ b/src/Refactoring-Core/RBTemporaryToInstanceVariableRefactoring.class.st @@ -135,13 +135,13 @@ RBTemporaryToInstanceVariableRefactoring >> isTemporaryVariableNameValid [ self refactoringError: temporaryVariableName , ' is a block parameter' ] ] -{ #category : 'as yet unclassified' } +{ #category : 'preconditions' } RBTemporaryToInstanceVariableRefactoring >> preconditionNoMultipleTempOccurences [ ^ ReMultipleMethodsDontReferToTempVarsCondition name: temporaryVariableName class: class selector: selector ] -{ #category : 'as yet unclassified' } +{ #category : 'preconditions' } RBTemporaryToInstanceVariableRefactoring >> preconditionNoReadBeforeWritten [ ^ ReVariablesNotReadBeforeWrittenCondition new @@ -150,7 +150,7 @@ RBTemporaryToInstanceVariableRefactoring >> preconditionNoReadBeforeWritten [ checkForTemporaryVariables: true ] -{ #category : 'as yet unclassified' } +{ #category : 'preconditions' } RBTemporaryToInstanceVariableRefactoring >> preconditionNoSubclassDefinesVar [ ^ RBCondition diff --git a/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st b/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st index 185d6865e83..500de68734e 100644 --- a/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st +++ b/src/Refactoring-Core/ReMultipleMethodsDontReferToTempVarsCondition.class.st @@ -24,7 +24,7 @@ ReMultipleMethodsDontReferToTempVarsCondition >> check [ ^ self violators isEmpty ] -{ #category : 'as yet unclassified' } +{ #category : 'setter' } ReMultipleMethodsDontReferToTempVarsCondition >> class: aRBClass [ class := aRBClass. diff --git a/src/Refactoring-DataForTesting/ReClassToConvertTemporaryToInstanceVariable.class.st b/src/Refactoring-DataForTesting/ReClassToConvertTemporaryToInstanceVariable.class.st new file mode 100644 index 00000000000..62506e631a0 --- /dev/null +++ b/src/Refactoring-DataForTesting/ReClassToConvertTemporaryToInstanceVariable.class.st @@ -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 +] diff --git a/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st b/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st new file mode 100644 index 00000000000..2e63c7e6e82 --- /dev/null +++ b/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st @@ -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. + +] diff --git a/src/Refactoring-UI/ReBrowseMethodChoice.class.st b/src/Refactoring-UI/ReBrowseMethodChoice.class.st index 00516fe1034..c9b40a5574e 100644 --- a/src/Refactoring-UI/ReBrowseMethodChoice.class.st +++ b/src/Refactoring-UI/ReBrowseMethodChoice.class.st @@ -17,5 +17,5 @@ ReBrowseMethodChoice >> action [ { #category : 'accessing' } ReBrowseMethodChoice >> description [ - ^ 'Browse the method(s)' + ^ 'Browse the method' ] diff --git a/src/Refactoring-UI/ReBrowseMethodsChoice.class.st b/src/Refactoring-UI/ReBrowseMethodsChoice.class.st new file mode 100644 index 00000000000..d78ad7853d3 --- /dev/null +++ b/src/Refactoring-UI/ReBrowseMethodsChoice.class.st @@ -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' +] diff --git a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st index cfd7a37d959..10d94b8b997 100644 --- a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st +++ b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st @@ -20,9 +20,18 @@ ReConvertTemporaryToInstanceVariableDriver >> breakingChoices [ | items | items := OrderedCollection new. subclassesNotDefiningVar check ifFalse: [ items add: (ReBrowseClassReferencesChoice new driver: self) ]. + noReadBeforeWritten check ifFalse: [ items add: (ReBrowseMethodChoice new driver: self) ]. + notMultipleTempOccurences check ifFalse: [ items add: (ReBrowseMethodsChoice new driver: self) ]. ^ items ] +{ #category : 'actions' } +ReConvertTemporaryToInstanceVariableDriver >> browseReferences [ + + (class allSubclasses select:[ :cls | cls hasInstVarNamed: variable ]) do: [ :violator | "we should pass the application! " + violator browse ] +] + { #category : 'instance creation' } ReConvertTemporaryToInstanceVariableDriver >> class: aClass selector: aSelector variable: aVariable [ @@ -72,7 +81,7 @@ ReConvertTemporaryToInstanceVariableDriver >> labelBasedOnBreakingChanges [ stream nextPutAll: 'Select a strategy' ] ] -{ #category : 'as yet unclassified' } +{ #category : 'actions' } ReConvertTemporaryToInstanceVariableDriver >> pushUpInstanceVariableAndRemoveTemp [ From 7e2d58c191db19b49c7525ab4eea7a154bb815df Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Thu, 20 Nov 2025 10:08:12 +0100 Subject: [PATCH 3/8] --- ...ertTemporaryToInstanceVariableDriver.class.st | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st index 10d94b8b997..02688f57b31 100644 --- a/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st +++ b/src/Refactoring-UI/ReConvertTemporaryToInstanceVariableDriver.class.st @@ -25,6 +25,22 @@ ReConvertTemporaryToInstanceVariableDriver >> breakingChoices [ ^ items ] +{ #category : 'execution' } +ReConvertTemporaryToInstanceVariableDriver >> browseMethod [ + + (class realClass methodDict at: selector) browse +] + +{ #category : 'actions' } +ReConvertTemporaryToInstanceVariableDriver >> browseMethods [ + + | violators | + violators := notMultipleTempOccurences violators. + StMessageBrowser + browse: (violators collect: [ :each | each value methodClass realClass >> each value selector ]) + asSendersOf: (violators collect: [ :v | v selector ]) +] + { #category : 'actions' } ReConvertTemporaryToInstanceVariableDriver >> browseReferences [ From be757cd13ec3ed11a7d932581fad89db27118818 Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Thu, 20 Nov 2025 10:17:12 +0100 Subject: [PATCH 4/8] remove accidental file --- bootstrap/scripts/runKernelTests.sh | 78 ----------------------------- 1 file changed, 78 deletions(-) delete mode 100644 bootstrap/scripts/runKernelTests.sh diff --git a/bootstrap/scripts/runKernelTests.sh b/bootstrap/scripts/runKernelTests.sh deleted file mode 100644 index d11031d8bce..00000000000 --- a/bootstrap/scripts/runKernelTests.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash -# Bash3 Boilerplate. Copyright (c) 2014, kvz.io - -# -# This script loads packages for a minimal image and run tests on it to ensure it is working fine! -# - -set -o errexit -set -o pipefail -set -o nounset -set -o xtrace - -# The first parameter is the architecture -# The second parameter is the stage name - -SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" -. ${SCRIPTS}/envvars.sh - -CACHE="${BOOTSTRAP_CACHE}" - - -find ${CACHE} - -# I will use the name of the image to determine the vm version (because file name is in the format Pharo7.0.0-rc1) -# -# WARNING: I'm assuming CACHE=bootstrap-cache -# WARNING: If you change this, you will need to change "runTests.sh" too -# -TEST_NAME_PREFIX=$(basename `find ${CACHE} -name "Pharo*.zip" | head -n 1` | cut -d'-' -f 1-2) - -# Extract the VM version from the image file version, avoiding going to git to extract the tags -# This is handy in later stages of the build process when no repository is available, e.g., to run the tests -# Input: Pharo11.0-PR-64bit-7264e14.zip -# Output: 110 -# Works by -# - taking the entire name, -# - removing the suffix after the first dot -# - removing the prefix "Pharo" -TEST_VM_VERSION=`echo ${TEST_NAME_PREFIX} | cut -d'.' -f 1 | cut -d'-' -f 1 | cut -c6-`0 - -TEST_VM_KIND="vm" - -${BOOTSTRAP_REPOSITORY:-.}/bootstrap/scripts/getPharoVM.sh ${TEST_VM_VERSION} ${TEST_VM_KIND} ${1} - -IMAGE_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-bootstrap-${1}bit-*.zip) -unzip $IMAGE_ARCHIVE -IMAGE_FILE=$(find . -name ${TEST_NAME_PREFIX}-bootstrap-${1}bit-*.image) - -HERMES_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-hermesPackages-${1}bit-*.zip) -unzip $HERMES_ARCHIVE - -RPACKAGE_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-rpackage-${1}bit-*.zip) -unzip $RPACKAGE_ARCHIVE - -mv $IMAGE_FILE bootstrap.image - -export PHARO_CI_TESTING_ENVIRONMENT=1 - -#Initializing the Image -./pharo bootstrap.image -#Adding packages removed from the bootstrap -./pharo bootstrap.image perform --save BasicHermesTool load: --as-array Clap-Core.hermes Clap-Commands-Pharo.hermes Hermes-Extensions.hermes -./pharo bootstrap.image perform --save Pragma buildCache -./pharo bootstrap.image loadHermes UIManager.hermes Math-Operations-Extensions.hermes System-Time.hermes NumberParser.hermes AST-Core.hermes Random-Core.hermes System-NumberPrinting.hermes --save --no-fail-on-undeclared --on-duplication ignore - -#Initializing the package manager -./pharo bootstrap.image perform --save PharoBootstrapFixMethodsTool fixExtensionMethods -./pharo bootstrap.image perform --save PharoBootstrapFixMethodsTool fixMethodsIn: protocolsKernel.txt - -#Load traits -./pharo bootstrap.image loadHermes Traits.hermes --save - -#Loading Tests -./pharo bootstrap.image loadHermes Debugging-Utils.hermes Deprecation.hermes SUnit-Core.hermes SUnit-Basic-CLI.hermes SUnit-Tests.hermes --save --no-fail-on-undeclared --on-duplication ignore -./pharo bootstrap.image perform --save Pragma buildCache - -#Running tests -./pharo bootstrap.image test --junit-xml-output --stage-name ${2} SUnit-Core SUnit-Tests From c5fd2f3d4acfcf02ea240c4a28f4276f4518f841 Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Thu, 20 Nov 2025 10:20:57 +0100 Subject: [PATCH 5/8] ? --- bootstrap/scripts/runKernelTests.sh | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 bootstrap/scripts/runKernelTests.sh diff --git a/bootstrap/scripts/runKernelTests.sh b/bootstrap/scripts/runKernelTests.sh new file mode 100644 index 00000000000..d11031d8bce --- /dev/null +++ b/bootstrap/scripts/runKernelTests.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# Bash3 Boilerplate. Copyright (c) 2014, kvz.io + +# +# This script loads packages for a minimal image and run tests on it to ensure it is working fine! +# + +set -o errexit +set -o pipefail +set -o nounset +set -o xtrace + +# The first parameter is the architecture +# The second parameter is the stage name + +SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" +. ${SCRIPTS}/envvars.sh + +CACHE="${BOOTSTRAP_CACHE}" + + +find ${CACHE} + +# I will use the name of the image to determine the vm version (because file name is in the format Pharo7.0.0-rc1) +# +# WARNING: I'm assuming CACHE=bootstrap-cache +# WARNING: If you change this, you will need to change "runTests.sh" too +# +TEST_NAME_PREFIX=$(basename `find ${CACHE} -name "Pharo*.zip" | head -n 1` | cut -d'-' -f 1-2) + +# Extract the VM version from the image file version, avoiding going to git to extract the tags +# This is handy in later stages of the build process when no repository is available, e.g., to run the tests +# Input: Pharo11.0-PR-64bit-7264e14.zip +# Output: 110 +# Works by +# - taking the entire name, +# - removing the suffix after the first dot +# - removing the prefix "Pharo" +TEST_VM_VERSION=`echo ${TEST_NAME_PREFIX} | cut -d'.' -f 1 | cut -d'-' -f 1 | cut -c6-`0 + +TEST_VM_KIND="vm" + +${BOOTSTRAP_REPOSITORY:-.}/bootstrap/scripts/getPharoVM.sh ${TEST_VM_VERSION} ${TEST_VM_KIND} ${1} + +IMAGE_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-bootstrap-${1}bit-*.zip) +unzip $IMAGE_ARCHIVE +IMAGE_FILE=$(find . -name ${TEST_NAME_PREFIX}-bootstrap-${1}bit-*.image) + +HERMES_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-hermesPackages-${1}bit-*.zip) +unzip $HERMES_ARCHIVE + +RPACKAGE_ARCHIVE=$(find ${CACHE} -name ${TEST_NAME_PREFIX}-rpackage-${1}bit-*.zip) +unzip $RPACKAGE_ARCHIVE + +mv $IMAGE_FILE bootstrap.image + +export PHARO_CI_TESTING_ENVIRONMENT=1 + +#Initializing the Image +./pharo bootstrap.image +#Adding packages removed from the bootstrap +./pharo bootstrap.image perform --save BasicHermesTool load: --as-array Clap-Core.hermes Clap-Commands-Pharo.hermes Hermes-Extensions.hermes +./pharo bootstrap.image perform --save Pragma buildCache +./pharo bootstrap.image loadHermes UIManager.hermes Math-Operations-Extensions.hermes System-Time.hermes NumberParser.hermes AST-Core.hermes Random-Core.hermes System-NumberPrinting.hermes --save --no-fail-on-undeclared --on-duplication ignore + +#Initializing the package manager +./pharo bootstrap.image perform --save PharoBootstrapFixMethodsTool fixExtensionMethods +./pharo bootstrap.image perform --save PharoBootstrapFixMethodsTool fixMethodsIn: protocolsKernel.txt + +#Load traits +./pharo bootstrap.image loadHermes Traits.hermes --save + +#Loading Tests +./pharo bootstrap.image loadHermes Debugging-Utils.hermes Deprecation.hermes SUnit-Core.hermes SUnit-Basic-CLI.hermes SUnit-Tests.hermes --save --no-fail-on-undeclared --on-duplication ignore +./pharo bootstrap.image perform --save Pragma buildCache + +#Running tests +./pharo bootstrap.image test --junit-xml-output --stage-name ${2} SUnit-Core SUnit-Tests From 553b828d04e038068731d7009d7780206f3cd1c2 Mon Sep 17 00:00:00 2001 From: AlexisCnockaert Date: Thu, 20 Nov 2025 15:18:51 +0100 Subject: [PATCH 6/8] permission revert --- bootstrap/scripts/runKernelTests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bootstrap/scripts/runKernelTests.sh diff --git a/bootstrap/scripts/runKernelTests.sh b/bootstrap/scripts/runKernelTests.sh old mode 100644 new mode 100755 From 2a425d4a5143b61ad87a2799d9d837c859d6fd9e Mon Sep 17 00:00:00 2001 From: Alexis Cnockaert <156106880+AlexisCnockaert@users.noreply.github.com> Date: Thu, 20 Nov 2025 15:26:55 +0100 Subject: [PATCH 7/8] Delete src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st --- ...stanceVariableAndRemoveTempChoice.class.st | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st diff --git a/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st b/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st deleted file mode 100644 index 4c9900036d9..00000000000 --- a/src/Refactoring-UI/RePushUpInstanceVariableAndRemoveTempChoice.class.st +++ /dev/null @@ -1,19 +0,0 @@ -Class { - #name : 'RePushUpInstanceVariableAndRemoveTempChoice', - #superclass : 'ReVariableChoice', - #category : 'Refactoring-UI-Choices', - #package : 'Refactoring-UI', - #tag : 'Choices' -} - -{ #category : 'accessing' } -RePushUpInstanceVariableAndRemoveTempChoice >> action [ - - driver pushUpInstanceVariableAndRemoveTemp -] - -{ #category : 'accessing' } -RePushUpInstanceVariableAndRemoveTempChoice >> description [ - - ^ 'Push up instance variable from subclass and remove temporary variable' -] From 1b216c9d6787b44fe3473ab5e862b0c98d9424bb Mon Sep 17 00:00:00 2001 From: Alexis Cnockaert <156106880+AlexisCnockaert@users.noreply.github.com> Date: Thu, 20 Nov 2025 16:55:22 +0100 Subject: [PATCH 8/8] Update expected size of refactoring changes to 3 --- .../ReConvertTemporaryToInstanceVariableDriverTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st b/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st index 2e63c7e6e82..19479825675 100644 --- a/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st +++ b/src/Refactoring-UI-Tests/ReConvertTemporaryToInstanceVariableDriverTest.class.st @@ -45,6 +45,6 @@ ReConvertTemporaryToInstanceVariableDriverTest >> testConvertTempSuccessfully [ driver runRefactoring. - self assert: driver refactoring changes changes size equals: 2. + self assert: driver refactoring changes changes size equals: 3. ]