Skip to content

Commit

Permalink
Add a custom class builder that signals class changes once [feenkcom/…
Browse files Browse the repository at this point in the history
  • Loading branch information
chisandrei committed Oct 30, 2023
1 parent 4a527c9 commit a4cb489
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 28 deletions.
9 changes: 9 additions & 0 deletions src/GToolkit-Pharo-Extensions/FluidBuilder.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Extension { #name : #FluidBuilder }

{ #category : #'*GToolkit-Pharo-Extensions' }
FluidBuilder >> install [
<gtPharoPatch: #Pharo>
"Install the class in the system environment"

^ GtShiftClassInstaller new makeWithBuilder: self shiftClassBuilder
]
9 changes: 9 additions & 0 deletions src/GToolkit-Pharo-Extensions/SmalltalkImage.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Extension { #name : #SmalltalkImage }

{ #category : #'*GToolkit-Pharo-Extensions' }
SmalltalkImage >> classInstaller [
<gtPharoPatch: #Pharo>
"Answer the class responsible of creating classes in the system."

^ GtShiftClassInstaller
]
18 changes: 18 additions & 0 deletions src/GToolkit-Pharo-Index/GtClassRecompiled.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : #GtClassRecompiled,
#superclass : #ClassAnnouncement,
#instVars : [
'classAffected'
],
#category : #'GToolkit-Pharo-Index'
}

{ #category : #accessing }
GtClassRecompiled >> classAffected [
^ classAffected
]

{ #category : #accessing }
GtClassRecompiled >> classAffected: aClass [
classAffected := aClass
]
33 changes: 5 additions & 28 deletions src/GToolkit-Pharo-Index/GtPharoIndex.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,8 @@ GtPharoIndex >> basicSubscribe [
when: ClassRenamed
send: #classRenamed:
to: self;
when: ClassModifiedClassDefinition
send: #classModifiedClassDefinition:
to: self;
when: ClassModificationApplied
send: #classModified:
when: GtClassRecompiled
send: #classRecompiled:
to: self
]

Expand Down Expand Up @@ -234,27 +231,8 @@ GtPharoIndex >> classAdded: anAnnouncement [
]

{ #category : #private }
GtPharoIndex >> classModified: anAnnouncement [
| class |
class := anAnnouncement classAffected.
shouldRecomputeSubclasses
ifTrue: [ class withAllSubclassesDo: [ :each | self recompileMethodsIn: each ] ]
ifFalse: [ self recompileMethodsIn: class ]
]

{ #category : #accessing }
GtPharoIndex >> classModifiedClassDefinition: anAnnouncement [
"Adding class variables or pool variables only announce the class as being changed,
but the subclasses are recompiled, so we need to know if we should also recache the
subclasses when we get the modified event."

| oldClass newClass |
oldClass := anAnnouncement oldClassDefinition.
newClass := anAnnouncement newClassDefinition.
shouldRecomputeSubclasses := newClass isClassSide not
and: [ oldClass instVarNames = newClass instVarNames
and: [ oldClass classVarNames ~= newClass classVarNames
or: [ oldClass sharedPools ~= newClass sharedPools ] ] ]
GtPharoIndex >> classRecompiled: anAnnouncement [
self recompileMethodsIn: anAnnouncement classAffected
]

{ #category : #private }
Expand Down Expand Up @@ -372,8 +350,7 @@ GtPharoIndex >> initialize [
selectorCache := GtReferencesAndImplementersPrefixTree new.
globalCache := GtReferencesPrefixTree new.
selectorWordCache := GtNamesPrefixTree new.
classWordCache := GtNamesPrefixTree new.
shouldRecomputeSubclasses := false
classWordCache := GtNamesPrefixTree new
]

{ #category : #testing }
Expand Down
46 changes: 46 additions & 0 deletions src/GToolkit-Pharo-Index/GtShiftClassInstaller.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Class {
#name : #GtShiftClassInstaller,
#superclass : #ShiftClassInstaller,
#category : #'GToolkit-Pharo-Index'
}

{ #category : #accessing }
GtShiftClassInstaller >> make [
| newClass |

self lookupOldClass.

[
builder oldClass: oldClass.
self copyClassSlotsFromExistingClass.
newClass := builder build.

self installInEnvironment: newClass.

self installSubclassInSuperclass: newClass.

builder builderEnhancer beforeMigratingClass: builder installer: self.

builder builderEnhancer migrateToClass: newClass installer: self.

builder builderEnhancer afterMigratingClass: builder installer: self.

builder builderEnhancer propagateChangesToRelatedClasses: newClass installer: self.
"Add this to the superclass implementation"
SystemAnnouncer uniqueInstance
announce: (GtClassRecompiled new classAffected: newClass) .
] on: ShNoChangesInClass do:[
"If there are no changes in the building, I am not building or replacing nothing"
newClass := oldClass.
].

self fixSlotScope: newClass.
self fixSlotScope: newClass class.

self recategorize: newClass to: builder category.
self comment: newClass.

self notifyChanges.

^ newClass
]

0 comments on commit a4cb489

Please sign in to comment.