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

20758-Slot-should-have-explicit-property-definingClass2 #543

Merged
merged 1 commit into from Nov 27, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/Kernel/ClassDescription.class.st
Expand Up @@ -587,20 +587,6 @@ ClassDescription >> copyMethodDictionaryFrom: donorClass [
self organization: donorClass organization deepCopy.
]

{ #category : #slots }
ClassDescription >> definesSlot: aSlot [
"Return true whether the receiver defines an instance variable named aString"

^ self slots identityIncludes: aSlot
]

{ #category : #slots }
ClassDescription >> definesSlotNamed: aString [
"Return true whether the receiver defines an instance variable named aString."

^ self slotNames includes: aString
]

{ #category : #'filein/out' }
ClassDescription >> definition [
"Answer a String that defines the receiver."
Expand Down
15 changes: 15 additions & 0 deletions src/Slot-Tests/SlotIntegrationTest.class.st
Expand Up @@ -415,6 +415,21 @@ SlotIntegrationTest >> testSlotScopeParallelism [
self assert: classWithWrongSlotScope asArray equals: #()
]

{ #category : #tests }
SlotIntegrationTest >> testSlotsAreInitializedWithDefiningAnonimousClass [
"All slots should include reference to defining class"
aClass := self make: [ :builder |
builder
name: self aClassName;
slots: #(x)
].
self assert: aClass slots first definingClass equals: aClass.

aClass addInstVarNamed: 'y'.
self assert: aClass slots size equals: 2.
self assert: (aClass slots collect: #definingClass as: Set) equals: {aClass} asSet
]

{ #category : #tests }
SlotIntegrationTest >> testSmallIntegerLayout [
self assert: (SmallInteger classLayout isKindOf: ImmediateLayout).
Expand Down
14 changes: 14 additions & 0 deletions src/Slot/Behavior.extension.st
Expand Up @@ -14,3 +14,17 @@ Behavior >> classLayout [
Behavior >> classLayout: aClassLayout [
layout := aClassLayout
]

{ #category : #'*Slot' }
Behavior >> definesSlot: aSlot [
"Return true whether the receiver defines an instance variable named aString"

^ self slots identityIncludes: aSlot
]

{ #category : #'*Slot' }
Behavior >> definesSlotNamed: aString [
"Return true whether the receiver defines an instance variable named aString."

^ self slotNames includes: aString
]
1 change: 1 addition & 0 deletions src/Slot/ClassDescription.extension.st
Expand Up @@ -3,6 +3,7 @@ Extension { #name : #ClassDescription }
{ #category : #'*Slot' }
ClassDescription >> superclass: aSuperclass layout: aLayout [
layout := aLayout.
layout slots do: [ :each | each definingClass: self ].

self
superclass: aSuperclass
Expand Down
12 changes: 8 additions & 4 deletions src/Slot/Slot.class.st
Expand Up @@ -14,7 +14,8 @@ Class {
#name : #Slot,
#superclass : #Object,
#instVars : [
'name'
'name',
'definingClass'
],
#classVars : [
'Properties'
Expand Down Expand Up @@ -113,9 +114,12 @@ Slot >> changingIn: aClass [

{ #category : #queries }
Slot >> definingClass [
^(Smalltalk globals allClasses flatCollect: [:each | {each . each classSide} ])
detect: [ :class | class classLayout definesSlot: self]
ifNone: [ nil ]
^definingClass
]

{ #category : #queries }
Slot >> definingClass: aClass [
definingClass := aClass
]

{ #category : #printing }
Expand Down