Skip to content
Open
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
34 changes: 34 additions & 0 deletions src/Stash-Serialization-Tests/StashSetterGetterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ StashSetterGetterTest >> testObject1 [
self assert: newObject name equals: 'test1'
]

{ #category : #tests }
StashSetterGetterTest >> testObject10 [

| object source newObject |
object := StashTestSetterGetter4 new
name: 'test1';
yourself.
source := Stash new serialize: object.
self assert: source equals: 'StashTestSetterGetter4 new
name: ''test1'';
yourself'.

newObject := self class compiler
source: source;
evaluate.
self assert: newObject name equals: 'test1'
]

{ #category : #tests }
StashSetterGetterTest >> testObject11 [

| object source newObject |
object := StashTestSetterGetter5 new
name: 'test1';
yourself.
source := Stash new serialize: object.
self assert: source equals: 'StashTestSetterGetter5 new'.

newObject := self class compiler
source: source;
evaluate.
self assert: newObject name equals: nil
]

{ #category : #tests }
StashSetterGetterTest >> testObject2 [

Expand Down
5 changes: 5 additions & 0 deletions src/Stash-Serialization-Tests/StashTestSetterGetter4.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #StashTestSetterGetter4,
#superclass : #StashTestSetterGetter1,
#category : #'Stash-Serialization-Tests'
}
12 changes: 12 additions & 0 deletions src/Stash-Serialization-Tests/StashTestSetterGetter5.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Class {
#name : #StashTestSetterGetter5,
#superclass : #StashTestSetterGetter1,
#category : #'Stash-Serialization-Tests'
}

{ #category : #'as yet unclassified' }
StashTestSetterGetter5 >> stashAccessors [

<stashAccessors>
^ { }
]
24 changes: 21 additions & 3 deletions src/Stash-Serialization/Object.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,27 @@ Object class >> allGettersForMyStash [
{ #category : #'*Stash-Serialization' }
Object >> allSetterAndGettersForMyStash [

| pragmas |
pragmas := Pragma allNamed: #stashAccessors from: self class to: Object.
^ pragmas flatCollect: [ :p | p method receiver: self withArguments: #( ) executeMethod: p method ].
| pragmas methods methodDict |
pragmas := Pragma
allNamed: #stashAccessors
from: self class
to: Object.
methods := pragmas collect: #method.
methodDict := Dictionary new.
methods do: [ :currentMethod |
methodDict
at: currentMethod selector
ifPresent: [ :previousMethod |
(currentMethod methodClass inheritsFrom: previousMethod)
ifTrue: [
methodDict at: currentMethod selector put: currentMethod ] ]
ifAbsentPut: [ currentMethod ] ].

^ methodDict values flatCollect: [ :method |
method
receiver: self
withArguments: #( )
executeMethod: method ]
]

{ #category : #'*Stash-Serialization' }
Expand Down