Skip to content

Commit

Permalink
[feenkcom/gtoolkit#4120] handle slots from superclasses, add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
syrel committed Oct 28, 2024
1 parent 80072d7 commit 51f8710
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/GT-PackageWithSubclasses/GtCoderDummySubclass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ Class {
#name : #GtCoderDummySubclass,
#superclass : #GtCoderDummySuperclass,
#instVars : [
'varB'
'slotB'
],
#classVars : [
'classVarB'
],
#classInstVars : [
'classSlotB'
],
#category : #'GT-PackageWithSubclasses-Classes'
}
28 changes: 19 additions & 9 deletions src/GT-PackageWithSuperclasses/GtCoderDummySuperclass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,49 @@ Class {
#name : #GtCoderDummySuperclass,
#superclass : #Object,
#instVars : [
'varA'
'slotA'
],
#classVars : [
'staticVarA'
'classVarA'
],
#classInstVars : [
'classVarA'
'classSlotA'
],
#category : #'GT-PackageWithSuperclasses-Classes'
}

{ #category : #initialization }
GtCoderDummySuperclass class >> initialize [
"Class side initialization"
]

{ #category : #'instance creation' }
GtCoderDummySuperclass class >> instanceCreationMethod [
^ self new
]

{ #category : #'methods reading slots' }
GtCoderDummySuperclass class >> methodReadingClassVarA [
^ classVarA
GtCoderDummySuperclass class >> methodReadingClassSlotA [
^ classSlotA
]

{ #category : #initialization }
GtCoderDummySuperclass >> initialize [
"Instance side initialization"
]

{ #category : #api }
GtCoderDummySuperclass >> methodInApiProtocol [
]

{ #category : #'methods reading slots' }
GtCoderDummySuperclass >> methodReadingStaticVarA [
^ staticVarA
GtCoderDummySuperclass >> methodReadingClassVarA [
^ classVarA
]

{ #category : #'methods reading slots' }
GtCoderDummySuperclass >> methodReadingVarA [
^ varA
GtCoderDummySuperclass >> methodReadingSlotA [
^ slotA
]

{ #category : #api }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ GtCoderNavigationPackagesTagsClassesModelExamples >> defaultModel [
^ aModel
]

{ #category : #utilities }
GtCoderNavigationPackagesTagsClassesModelExamples >> dummySubclass [
^ GtCoderDummySubclass
]

{ #category : #utilities }
GtCoderNavigationPackagesTagsClassesModelExamples >> dummySuperclass [
^ GtCoderDummySuperclass
Expand Down Expand Up @@ -209,9 +214,9 @@ GtCoderNavigationPackagesTagsClassesModelExamples >> navigateToClass_03_selectCl
self assert: (methodsToShow includes: aClassToSelect class >> #instanceCreationMethod).

slotsToShow := aModel slotsToShow.
self assert: (slotsToShow detect: [ :each| each name = #varA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #slotA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classSlotA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classVarA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #staticVarA ]) isNotNil.

^ aModel
]
Expand All @@ -221,10 +226,9 @@ GtCoderNavigationPackagesTagsClassesModelExamples >> navigateToClass_04_selectSl
<gtExample>
| aModel aSlotToSelect |


aModel := self navigateToClass_03_selectClass.

aSlotToSelect := aModel slotsToShow detect: [ :each | each name = #varA ].
aSlotToSelect := aModel slotsToShow detect: [ :each | each name = #slotA ].
aModel selectSlot: aSlotToSelect.

self assert: aModel hasSelectedProtocol not.
Expand Down Expand Up @@ -320,3 +324,24 @@ GtCoderNavigationPackagesTagsClassesModelExamples >> recordAnnouncementsOf: aMod

^ announcements
]

{ #category : #'examples - slots' }
GtCoderNavigationPackagesTagsClassesModelExamples >> slotsToShowShouldIncludeSuperclasses [
<gtExample>
| aModel slotsToShow |

aModel := self defaultModel.
aModel selectClass: self dummySubclass.

slotsToShow := aModel slotsToShow.
"from selected class"
self assert: (slotsToShow detect: [ :each| each name = #slotB ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classSlotB ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classVarB ]) isNotNil.
"from superclass"
self assert: (slotsToShow detect: [ :each| each name = #slotA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classSlotA ]) isNotNil.
self assert: (slotsToShow detect: [ :each| each name = #classVarA ]) isNotNil.

^ aModel
]
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ GtCoderNavigationPackagesTagsClassesModel >> methodsToShow [
streamContents: [ :aStream |
aStream nextPutAll: (anInstanceSideClass methodsAccessingSlot: aSlot).
aStream nextPutAll: (aClassSideClass methodsAccessingSlot: aSlot) ] ].

^ self selectedProtocol allMethods

^ self selectedProtocol
ifNil: [ #() ]
ifNotNil: [ :aProtocol | aProtocol allMethods ]
]

{ #category : #'private - notifying' }
Expand Down Expand Up @@ -500,6 +502,38 @@ GtCoderNavigationPackagesTagsClassesModel >> packagesToShow [
^ RPackageOrganizer default gtSortedPackages
]

{ #category : #'private - accessing' }
GtCoderNavigationPackagesTagsClassesModel >> privateAllClassSlotsOf: aBehavior [
| allSlots |

allSlots := OrderedCollection new.

aBehavior withAllSuperclassesDo: [ :eachClass |
eachClass = Object class
ifTrue: [ ^ allSlots ].
allSlots addAll: eachClass slots ].
]

{ #category : #'private - accessing' }
GtCoderNavigationPackagesTagsClassesModel >> privateAllClassVariablesOf: aBehavior [
^ Array streamContents: [ :aStream |
aBehavior withAllSuperclassesDo: [ :eachClass |
eachClass ~= Object
ifTrue: [ aStream nextPutAll: eachClass classVariables ] ] ]
]

{ #category : #'private - accessing' }
GtCoderNavigationPackagesTagsClassesModel >> privateAllSlotsOf: aBehavior [
| allSlots |

allSlots := OrderedCollection new.

aBehavior withAllSuperclassesDo: [ :eachClass |
eachClass = Object
ifTrue: [ ^ allSlots ].
allSlots addAll: eachClass slots ].
]

{ #category : #'private - accessing' }
GtCoderNavigationPackagesTagsClassesModel >> privateClassesInPackage: aPackage [
| allClasses |
Expand Down Expand Up @@ -1008,18 +1042,18 @@ GtCoderNavigationPackagesTagsClassesModel >> showPackage: anRPackage [
{ #category : #'api - accessing' }
GtCoderNavigationPackagesTagsClassesModel >> slotsToShow [
<return: #Collection of: #GtPharoProtocol>
| currentClass instanceSideSlots classSideSlots staticSlots |
| currentClass instanceSideSlots classSideSlots classVars |

self hasSelectedClass
ifFalse: [ ^ #() ].

currentClass := self selectedClass.

instanceSideSlots := currentClass instanceSide instanceVariables.
classSideSlots := currentClass classSide instanceVariables.
staticSlots := currentClass classVariables.
instanceSideSlots := self privateAllSlotsOf: currentClass instanceSide.
classSideSlots := self privateAllClassSlotsOf: currentClass classSide.
classVars := self privateAllClassVariablesOf:currentClass.

^ instanceSideSlots, classSideSlots, staticSlots
^ instanceSideSlots, classSideSlots, classVars
]

{ #category : #'api - subscriptions' }
Expand Down

0 comments on commit 51f8710

Please sign in to comment.