Skip to content
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

21763-TraitedMetaclass-should-empty-the-localMethods-and-baseLocalMethods-when-becoming-obsolete #1244

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions src/TraitsV2-Tests/T2ObsoleteClassTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
Class {
#name : #T2ObsoleteClassTest,
#superclass : #T2AbstractTest,
#category : #'TraitsV2-Tests'
}

{ #category : #tests }
T2ObsoleteClassTest >> testObsoleteClassIsRemovedFromUsers [
| t1 t2 c1 |
t1 := self newTrait: #T1 with: #() uses: {}.
t2 := self newTrait: #T2 with: #() uses: {}.

c1 := self newClass: #C1 with: #() uses: t1 + t2.

self assert: (t1 users includes: c1).
self assert: (t2 users includes: c1).

c1 removeFromSystem.
createdClasses remove: c1.

self deny: (t1 users includes: c1).
self deny: (t2 users includes: c1).

]

{ #category : #tests }
T2ObsoleteClassTest >> testObsoleteClassIsRemovedFromUsersClassSide [
| t1 t2 c1 |
t1 := self newTrait: #T1 with: #() uses: {}.
t2 := self newTrait: #T2 with: #() uses: {}.

c1 := self newClass: #C1 with: #() uses: {}.
c1 class setTraitComposition: t1 + t2.

self assert: (t1 users includes: c1 class).
self assert: (t2 users includes: c1 class).

c1 removeFromSystem.
createdClasses remove: c1.

self deny: (t1 users includes: c1 class).
self deny: (t2 users includes: c1 class).

]

{ #category : #tests }
T2ObsoleteClassTest >> testObsoleteClassRemovesMethods [
| t1 t2 c1 |
t1 := self newTrait: #T1 with: #() uses: {}.
t1 compile: 'm1 ^ 1'.

t2 := self newTrait: #T2 with: #() uses: {}.
t2 compile: 'm2 ^ 1'.

c1 := self newClass: #C1 with: #() uses: t1 + t2.

c1 compile: 'localM1 ^ 1'.

self assert: (c1 methodDict includesKey: #m1).
self assert: (c1 methodDict includesKey: #m2).
self deny: (c1 localMethodDict includesKey: #m1).
self deny: (c1 localMethodDict includesKey: #m2).
self assert: (c1 localMethodDict includesKey: #localM1).

c1 removeFromSystem.
createdClasses remove: c1.

self deny: (c1 methodDict includesKey: #m1).
self deny: (c1 methodDict includesKey: #m2).

"Accessing directly because there is no more accesor method"
self assert: (c1 class instVarNamed: #baseLocalMethods) isEmpty.
self deny: ((c1 class instVarNamed: #baseLocalMethods) includesKey: #m1).
self deny: ((c1 class instVarNamed: #baseLocalMethods) includesKey: #m2).
self deny: ((c1 class instVarNamed: #baseLocalMethods) includesKey: #localM1).

]

{ #category : #tests }
T2ObsoleteClassTest >> testObsoleteClassRemovesMethodsClassSide [
| t1 t2 c1 |
t1 := self newTrait: #T1 with: #() uses: {}.
t1 compile: 'm1 ^ 1'.

t2 := self newTrait: #T2 with: #() uses: {}.
t2 compile: 'm2 ^ 1'.

c1 := self newClass: #C1 with: #() uses: {}.
c1 class setTraitComposition: t1 + t2.

c1 class compile: 'localM1 ^ 1'.

self assert: (c1 class methodDict includesKey: #m1).
self assert: (c1 class methodDict includesKey: #m2).
self deny: (c1 class localMethodDict includesKey: #m1).
self deny: (c1 class localMethodDict includesKey: #m2).
self assert: (c1 class localMethodDict includesKey: #localM1).

c1 removeFromSystem.
createdClasses remove: c1.

self deny: (c1 class methodDict includesKey: #m1).
self deny: (c1 class methodDict includesKey: #m2).
self deny: (c1 class localMethodDict includesKey: #m1).
self deny: (c1 class localMethodDict includesKey: #m2).
self deny: (c1 class localMethodDict includesKey: #localM1).

]

{ #category : #tests }
T2ObsoleteClassTest >> testObsoleteTraitIsRemovedFromUsers [
| t1 t2 t3 |
t1 := self newTrait: #T1 with: #() uses: {}.
t2 := self newTrait: #T2 with: #() uses: {}.

t3 := self newTrait: #T3 with: #() uses: t1 + t2.

self assert: (t1 users includes: t3).
self assert: (t2 users includes: t3).

t3 removeFromSystem.
createdClasses remove: t3.

self deny: (t1 users includes: t3).
self deny: (t2 users includes: t3).

]
12 changes: 12 additions & 0 deletions src/TraitsV2/TraitedMetaclass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ TraitedMetaclass >> localSelectors [
^ localMethods keys
]

{ #category : #'initialize-release' }
TraitedMetaclass >> obsolete [

super obsolete.
self canZapMethodDictionary
ifTrue: [
localMethods := self emptyMethodDictionary.
baseLocalMethods := self emptyMethodDictionary].


]

{ #category : #initialization }
TraitedMetaclass >> rebuildMethodDictionary [
| selectors removedSelectors modified |
Expand Down