Skip to content

Commit

Permalink
- move #originalName from RPackage to kernel
Browse files Browse the repository at this point in the history
- implement #nonObsoleteClass in terms of #originalName
- add a test

- implement obsoleteClasses to use #isObsolete

fixes #10144
  • Loading branch information
MarcusDenker committed Oct 11, 2021
1 parent 26d2a35 commit d5fd32a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/Kernel-Tests/BehaviorTest.class.st
Expand Up @@ -209,6 +209,12 @@ BehaviorTest >> testMethodsWritingSlot [
self assert: numberViaSlot equals: numberViaIVar
]

{ #category : #tests }
BehaviorTest >> testNonObsoleteClass [
"Does it work on not-obsolete classes?"
self assert: Object nonObsoleteClass equals: Object
]

{ #category : #'tests - properties' }
BehaviorTest >> testPropertyValueAtPut [
| testValue |
Expand Down
13 changes: 8 additions & 5 deletions src/Kernel/Behavior.class.st
Expand Up @@ -1268,11 +1268,7 @@ Behavior >> new: sizeRequested [
Behavior >> nonObsoleteClass [
"Attempt to find and return the current version of this obsolete class"

| obsName |
obsName := self name.
[obsName beginsWith: 'AnObsolete']
whileTrue: [obsName := obsName copyFrom: 'AnObsolete' size + 1 to: obsName size].
^ self environment at: obsName asSymbol
^ self environment at: self originalName
]

{ #category : #initialization }
Expand All @@ -1288,6 +1284,13 @@ Behavior >> obsoleteSubclasses [
^ obs copyWithout: nil
]

{ #category : #initialization }
Behavior >> originalName [
^ ((self isObsolete and: [ self name beginsWith: 'AnObsolete' ])
ifTrue: [ (self name copyFrom: 'AnObsolete' size + 1 to: self name size ) ]
ifFalse: [ self name ]) asSymbol
]

{ #category : #copying }
Behavior >> postCopy [
super postCopy.
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Metaclass.class.st
Expand Up @@ -191,7 +191,7 @@ Metaclass >> isMetaclassOfClassOrNil [
{ #category : #testing }
Metaclass >> isObsolete [
"Return true if the receiver is obsolete"
^self soleInstance == nil "Either no thisClass"
^self soleInstance isNil "Either no thisClass"
or:[self soleInstance classSide ~~ self "or I am not the class of thisClass"
or:[self soleInstance isObsolete]] "or my instance is obsolete"
]
Expand Down
8 changes: 0 additions & 8 deletions src/RPackage-Core/Behavior.extension.st

This file was deleted.

8 changes: 4 additions & 4 deletions src/System-Support/SystemNavigation.class.st
Expand Up @@ -368,22 +368,22 @@ SystemNavigation >> obsoleteClasses [
allInstancesDo: [ :m |
| c |
c := m soleInstance.
(c notNil and: [ 'AnOb*' match: c name asString ])
(c notNil and: [ c isObsolete ])
ifTrue: [ obs add: c ] ].
^ obs asArray

"Likely in a ClassDict or Pool...
(Association allInstances select: [:a | (a value isKindOf: Class) and: ['AnOb*' match: a value name]]) asArray
(Association allInstances select: [:a | (a value isKindOf: Class) and: [a value isObsolete]]) asArray
"

"Obsolete class refs or super pointer in last lit of a method...
| n l found |
Smalltalk browseAllSelect:
SystemNavigation new browseAllSelect:
[:m | found := false.
1 to: m numLiterals do:
[:i | (((l := m literalAt: i) isMemberOf: Association)
and: [(l value isKindOf: Behavior)
and: ['AnOb*' match: l value name]])
and: [l value isObsolete]])
ifTrue: [found := true]].
found]
"
Expand Down

0 comments on commit d5fd32a

Please sign in to comment.