diff --git a/src/Kernel/Class.class.st b/src/Kernel/Class.class.st index abd061fa678..e8b2bd671c3 100644 --- a/src/Kernel/Class.class.st +++ b/src/Kernel/Class.class.st @@ -155,6 +155,16 @@ Class >> addSharedPool: aSharedPool [ ifFalse: [self sharedPools add: aSharedPool] ] +{ #category : #'pool variables' } +Class >> addSharedPoolNamed: aSharedPoolName [ + + |poolClass| + poolClass := aSharedPoolName asClassIfAbsent: [nil]. + poolClass isPool + ifTrue: [ self addSharedPool: poolClass ] + ifFalse: [ self error: 'The specified class is not pool.' ] +] + { #category : #'accessing class hierarchy' } Class >> addSubclass: aSubclass [ "Make the argument, aSubclass, be one of the subclasses of the receiver. diff --git a/src/Refactoring-Changes/RBAddPoolVariableChange.class.st b/src/Refactoring-Changes/RBAddPoolVariableChange.class.st index d5462df42dd..a7c01fb1813 100644 --- a/src/Refactoring-Changes/RBAddPoolVariableChange.class.st +++ b/src/Refactoring-Changes/RBAddPoolVariableChange.class.st @@ -27,5 +27,5 @@ RBAddPoolVariableChange >> changeString [ { #category : #private } RBAddPoolVariableChange >> changeSymbol [ - ^ #addSharedPool: + ^ #addSharedPoolNamed: ] diff --git a/src/Refactoring-Tests-Core/RBPullUpMethodTest.class.st b/src/Refactoring-Tests-Core/RBPullUpMethodTest.class.st index 8ab1255dd44..792a2709510 100644 --- a/src/Refactoring-Tests-Core/RBPullUpMethodTest.class.st +++ b/src/Refactoring-Tests-Core/RBPullUpMethodTest.class.st @@ -16,6 +16,17 @@ RBPullUpMethodTest >> addClassHierarchy [ defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. ] +{ #category : #tests } +RBPullUpMethodTest >> addClassHierarchyForPools [ + model + defineClass: 'SharedPool subclass: #TotoSharedPool instanceVariableNames: '''' classVariableNames: ''SP'' poolDictionaries: '''' category: #''Refactory-Test data'''. + model + defineClass: 'Object subclass: #TotoSuperclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. + model + defineClass: 'TotoSuperclass subclass: #Toto instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. + (model classNamed: #Toto) compile: 'poolReference ^ SP' classified: #(#accessing). +] + { #category : #tests } RBPullUpMethodTest >> testPullUpAndCopyDown [ | class | @@ -86,6 +97,23 @@ RBPullUpMethodTest >> testPullUpMethodWithCopyOverriddenMethodsDown [ self deny: ((refactoring model classNamed: #RBCompositeLintRuleTestData) directlyDefinesMethod: #isComposite) ] +{ #category : #tests } +RBPullUpMethodTest >> testPullUpMethodWithSharedPool [ + | class superClass | + + self addClassHierarchyForPools. + class := model classNamed: #Toto. + superClass := model classNamed: #TotoSuperclass. + self executeRefactoring: (RBPullUpMethodRefactoring + model: model + pullUp: #(#poolReference) + from: class + to: superClass ). + self assert: (superClass parseTreeFor: #poolReference) + equals: (self parseMethod: 'poolReference ^ SP'). + self deny: (class directlyDefinesMethod: #poolReference). +] + { #category : #'failure tests' } RBPullUpMethodTest >> testPullUpReferencesInstVar [ self shouldFail: (RBPullUpMethodRefactoring