Skip to content

Commit

Permalink
Cleanup: deprecation rewrites of whoDefinesMethod: -> `whichClassIn…
Browse files Browse the repository at this point in the history
…cludesSelector:`
  • Loading branch information
balsa-sarenac committed Apr 26, 2024
1 parent bd73834 commit 9a1c8bd
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 168 deletions.
8 changes: 3 additions & 5 deletions src/Refactoring-Core/RBAbstractClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ RBAbstractClass >> parseTreeFor: aSymbol [
RBAbstractClass >> parseTreeForSelector: aSelector [

| class method |

class := self whoDefinesMethod: aSelector.
class := self whichClassIncludesSelector: aSelector.
class ifNil: [ ^ nil ].
method := class methodFor: aSelector.
method ifNil: [ ^ nil ].
Expand Down Expand Up @@ -735,10 +734,9 @@ RBAbstractClass >> soleInstance [
RBAbstractClass >> sourceCodeFor: aSelector [

| class |

class := self whoDefinesMethod: aSelector.
class := self whichClassIncludesSelector: aSelector.
class ifNil: [ ^ nil ].
^ ( class methodFor: aSelector ) source
^ (class methodFor: aSelector) source
]

{ #category : 'storing' }
Expand Down
25 changes: 13 additions & 12 deletions src/Refactoring-Core/RBExtractMethodRefactoring.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,22 @@ RBExtractMethodRefactoring >> isMethodEquivalentTo: aSelector [

{ #category : 'transforming' }
RBExtractMethodRefactoring >> isParseTreeEquivalentTo: aSelector [

| tree definingClass |
definingClass := class whoDefinesMethod: aSelector.
definingClass := class whichClassIncludesSelector: aSelector.
tree := definingClass parseTreeForSelector: aSelector.
tree ifNil: [^false].
tree isPrimitive ifTrue: [^false].
tree ifNil: [ ^ false ].
tree isPrimitive ifTrue: [ ^ false ].
needsReturn ifFalse: [ tree := self removeReturnsOf: tree ].
(tree body equalTo: extractedParseTree body
exceptForVariables: (tree arguments collect: [:each | each name]))
ifFalse: [^false].
(definingClass = class or:
[(tree superMessages anySatisfy:
[:each |
(class superclass whichClassIncludesSelector: aSelector)
~= (definingClass superclass whichClassIncludesSelector: each)]) not])
ifFalse: [^false].
(tree body
equalTo: extractedParseTree body
exceptForVariables: (tree arguments collect: [ :each | each name ]))
ifFalse: [ ^ false ].
(definingClass = class or: [
(tree superMessages anySatisfy: [ :each |
(class superclass whichClassIncludesSelector: aSelector)
~= (definingClass superclass whichClassIncludesSelector: each) ])
not ]) ifFalse: [ ^ false ].
^ true
]

Expand Down
13 changes: 8 additions & 5 deletions src/Refactoring-Core/RBInlineMethodRefactoring.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ RBInlineMethodRefactoring >> checkSuperMessages [
RBInlineMethodRefactoring >> classOfTheMethodToInline [

^ classOfTheMethodToInline
ifNil: [ classOfTheMethodToInline := ( sourceMessage receiver name = 'super'
ifTrue: [ class superclass ]
ifFalse: [ class ] ) whoDefinesMethod: self inlineSelector
]
ifNotNil: [ classOfTheMethodToInline ]
ifNil: [
classOfTheMethodToInline := (sourceMessage receiver name
= 'super'
ifTrue: [ class superclass ]
ifFalse: [ class ])
whichClassIncludesSelector:
self inlineSelector ]
ifNotNil: [ classOfTheMethodToInline ]
]

{ #category : 'transforming' }
Expand Down
132 changes: 66 additions & 66 deletions src/Refactoring-Core/RBPullUpMethodRefactoring.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,26 @@ RBPullUpMethodRefactoring >> checkBackReferencesTo: aSelector [
in `targetSuperclass` "

| definingClass pushUpParseTree |
definingClass := targetSuperclass whoDefinesMethod: aSelector.
definingClass ifNil: [^self].
definingClass := targetSuperclass whichClassIncludesSelector:
aSelector.
definingClass ifNil: [ ^ self ].
pushUpParseTree := class parseTreeForSelector: aSelector.
targetSuperclass allSubclasses do:
[:each |
each selectors do:
[:sel |
| parseTree |
parseTree := each parseTreeForSelector: sel.
(parseTree isNotNil and:
[(parseTree superMessages includes: aSelector)
and: [definingClass == (each whoDefinesMethod: aSelector)]])
ifTrue:
[removeDuplicates := true.
(aSelector == sel
and: [parseTree equalTo: pushUpParseTree exceptForVariables: #()])
ifFalse:
[self
refactoringError: ('Cannot pull up <1s> since it would override the method defined in <2p>'
expandMacrosWith: aSelector
with: definingClass)]]]]
targetSuperclass allSubclasses do: [ :each |
each selectors do: [ :sel |
| parseTree |
parseTree := each parseTreeForSelector: sel.
(parseTree isNotNil and: [
(parseTree superMessages includes: aSelector) and: [
definingClass == (each whoDefinesMethod: aSelector) ] ])
ifTrue: [
removeDuplicates := true.
(aSelector == sel and: [
parseTree equalTo: pushUpParseTree exceptForVariables: #( ) ])
ifFalse: [
self refactoringError:
('Cannot pull up <1s> since it would override the method defined in <2p>'
expandMacrosWith: aSelector
with: definingClass) ] ] ] ]
]

{ #category : 'preconditions' }
Expand Down Expand Up @@ -152,25 +151,23 @@ RBPullUpMethodRefactoring >> checkSiblingSuperSendsFrom: aRBClass [
warn the user.
Repeat the process for all subclasses of `aRBClass`"

aRBClass selectors do:
[:each |
| tree |
tree := aRBClass parseTreeForSelector: each.
tree ifNotNil:
[tree superMessages do:
[:aSelector |
(selectors includes: aSelector)
ifTrue:
[| definer |
definer := aRBClass superclass whoDefinesMethod: aSelector.
(definer isNotNil and: [class includesClass: definer])
ifTrue:
[self
refactoringError: ('Cannot pull up <1s> since <2p>>><3s> sends a super message to it.'
expandMacrosWith: aSelector
with: aRBClass
with: each)]]]]].
aRBClass allSubclasses do: [:each | self checkSiblingSuperSendsFrom: each]
aRBClass selectors do: [ :each |
| tree |
tree := aRBClass parseTreeForSelector: each.
tree ifNotNil: [
tree superMessages do: [ :aSelector |
(selectors includes: aSelector) ifTrue: [
| definer |
definer := aRBClass superclass whichClassIncludesSelector:
aSelector.
(definer isNotNil and: [ class includesClass: definer ]) ifTrue: [
self refactoringError:
('Cannot pull up <1s> since <2p>>><3s> sends a super message to it.'
expandMacrosWith: aSelector
with: aRBClass
with: each) ] ] ] ] ].
aRBClass allSubclasses do: [ :each |
self checkSiblingSuperSendsFrom: each ]
]

{ #category : 'preconditions' }
Expand Down Expand Up @@ -233,39 +230,42 @@ RBPullUpMethodRefactoring >> checkSuperclass [

{ #category : 'private' }
RBPullUpMethodRefactoring >> copyDownMethod: aSelector [

| oldProtocol oldSource superclassDefiner subclasses refactoring |
superclassDefiner := targetSuperclass whoDefinesMethod: aSelector.
superclassDefiner ifNil: [^ self ].
superclassDefiner := targetSuperclass whichClassIncludesSelector:
aSelector.
superclassDefiner ifNil: [ ^ self ].
oldSource := superclassDefiner sourceCodeFor: aSelector.
oldSource ifNil:
[ self
refactoringError: ('Source code for <1s> superclass method not available'
expandMacrosWith: aSelector)].
oldSource ifNil: [
self refactoringError:
('Source code for <1s> superclass method not available'
expandMacrosWith: aSelector) ].
oldProtocol := superclassDefiner protocolsFor: aSelector.
subclasses := targetSuperclass subclasses
reject: [:each | each directlyDefinesMethod: aSelector].
subclasses ifEmpty: [^ self ].
subclasses := targetSuperclass subclasses reject: [ :each |
each directlyDefinesMethod: aSelector ].
subclasses ifEmpty: [ ^ self ].
(superclassDefiner parseTreeForSelector: aSelector) superMessages
detect: [:each | superclassDefiner directlyDefinesMethod: each]
ifFound:
[self
refactoringError: ('Cannot pull up <1s> since we must copy down the superclass method in <2p><n>to the other subclasses, and the superclass method sends a super message which is overriden.'
expandMacrosWith: aSelector
with: superclassDefiner)].
self
refactoringWarning: 'Do you want to copy down the superclass method to the classes that don''t define '
, aSelector, '?'.
detect: [ :each | superclassDefiner directlyDefinesMethod: each ]
ifFound: [
self refactoringError:
('Cannot pull up <1s> since we must copy down the superclass method in <2p><n>to the other subclasses, and the superclass method sends a super message which is overriden.'
expandMacrosWith: aSelector
with: superclassDefiner) ].
self refactoringWarning:
'Do you want to copy down the superclass method to the classes that don''t define '
, aSelector , '?'.
refactoring := RBExpandReferencedPoolsRefactoring
model: self model
forMethod: (superclassDefiner parseTreeForSelector: aSelector)
fromClass: superclassDefiner
toClasses: subclasses.
model: self model
forMethod:
(superclassDefiner parseTreeForSelector: aSelector)
fromClass: superclassDefiner
toClasses: subclasses.
self generateChangesFor: refactoring.
subclasses do: [:each | self generateChangesFor:
(RBAddMethodTransformation
sourceCode: oldSource
in: each
withProtocol: oldProtocol)]
subclasses do: [ :each |
self generateChangesFor: (RBAddMethodTransformation
sourceCode: oldSource
in: each
withProtocol: oldProtocol) ]
]

{ #category : 'transforming' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ RBInlineMethodTransformation >> checkSuperMessages [
RBInlineMethodTransformation >> classOfTheMethodToInline [

^ classOfTheMethodToInline
ifNil: [ classOfTheMethodToInline := ( sourceMessage receiver name = 'super'
ifTrue: [ class superclass ]
ifFalse: [ class ] ) whoDefinesMethod: self inlineSelector
]
ifNotNil: [ classOfTheMethodToInline ]
ifNil: [
classOfTheMethodToInline := (sourceMessage receiver name
= 'super'
ifTrue: [ class superclass ]
ifFalse: [ class ])
whichClassIncludesSelector:
self inlineSelector ]
ifNotNil: [ classOfTheMethodToInline ]
]

{ #category : 'adding' }
Expand Down

0 comments on commit 9a1c8bd

Please sign in to comment.