Skip to content

Commit

Permalink
Fixes: #8332.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Jan 10, 2021
1 parent 15f7c48 commit 11304e7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Kernel-Tests/CommonClassDefinitionPrinterTest.class.st
Expand Up @@ -6,21 +6,24 @@ Class {
#name : #CommonClassDefinitionPrinterTest,
#superclass : #TestCase,
#instVars : [
'slotuse'
'slotDisplay',
'slotUse'
],
#category : #'Kernel-Tests-Fluid'
}

{ #category : #running }
CommonClassDefinitionPrinterTest >> setUp [
super setUp.
slotuse := ClassDefinitionPrinter showFluidClassDefinition.
slotUse := ClassDefinitionPrinter showFluidClassDefinition.
slotDisplay := ClassDefinitionPrinter displayEmptySlots.

]

{ #category : #running }
CommonClassDefinitionPrinterTest >> tearDown [

ClassDefinitionPrinter showFluidClassDefinition: slotuse.
ClassDefinitionPrinter showFluidClassDefinition: slotUse.
ClassDefinitionPrinter displayEmptySlots: slotDisplay.
super tearDown
]
30 changes: 30 additions & 0 deletions src/Kernel-Tests/FluidClassDefinitionPrinterTest.class.st
Expand Up @@ -99,6 +99,36 @@ FluidClassDefinitionPrinterTest >> testDefinitionWithComplexSlot [
package: ''Kernel-Tests'''
]

{ #category : #'tests - unnecessary values' }
FluidClassDefinitionPrinterTest >> testDisplayEmptySlots [
"I would like to be able to test if I provide too many empty values that
the default empty values are just ignored."
| class |
ClassDefinitionPrinter displayEmptySlots: true.
class := (Object << #CDFluidMock
slots: {};
tag: 'BasicObjects';
package: 'Kernel') build.
self assert: (self forClass: class) equals: 'Object << #CDFluidMock
slots: {};
package: ''_UnpackagedPackage'''

]

{ #category : #'tests - unnecessary values' }
FluidClassDefinitionPrinterTest >> testDoesNotDisplayEmptySlots [

| class |
ClassDefinitionPrinter displayEmptySlots: false.
class := (Object << #CDFluidMock
slots: {};
tag: 'BasicObjects';
package: 'Kernel') build.
self assert: (self forClass: class) equals: 'Object << #CDFluidMock
package: ''_UnpackagedPackage'''

]

{ #category : #'tests - expanded' }
FluidClassDefinitionPrinterTest >> testExpandedEmptyLayoutClass [

Expand Down
28 changes: 27 additions & 1 deletion src/Kernel/ClassDefinitionPrinter.class.st
Expand Up @@ -59,11 +59,24 @@ Class {
'forClass'
],
#classVars : [
'DisplayEmptySlots',
'ShowFluidClassDefinition'
],
#category : #'Kernel-ClassDefinitionPrinter'
}

{ #category : #configure }
ClassDefinitionPrinter class >> displayEmptySlots [

^ DisplayEmptySlots ifNil: [ DisplayEmptySlots := false ]
]

{ #category : #configure }
ClassDefinitionPrinter class >> displayEmptySlots: aBoolean [

DisplayEmptySlots := aBoolean
]

{ #category : #'instance creation' }
ClassDefinitionPrinter class >> fluid [
^ FluidClassDefinitionPrinter basicNew initialize
Expand Down Expand Up @@ -125,7 +138,20 @@ Object << #Point
We suggest to use it because it will become the default syntax for Pharo. This new class definition has been designed to control the parameter explosion of the old one.
In addition, as soon as you will use slots such as ObservableSlot and more this fluid class definition will be used because the old one is not handling well the slots.';
target: self
target: self.

(aBuilder setting: #displayEmptySlots)
parent: #codeBrowsing;
default: false;
label: 'Display empty slots';
description: 'If true, the system will display the slots even if they are empty e.g.,
Object << #Faked
slots: { };
tag: ''BasicObjects'';
package: ''Kernel''
';
target: self.
]

{ #category : #configure }
Expand Down
5 changes: 3 additions & 2 deletions src/Kernel/FluidClassDefinitionPrinter.class.st
Expand Up @@ -46,8 +46,9 @@ FluidClassDefinitionPrinter >> classDefinitionString [
ifFalse: [ self layoutOn: s ].

self traitsOn: s.

forClass slots ifNotEmpty: [ self slotsOn: s ].
self class displayEmptySlots
ifTrue: [ self slotsOn: s ]
ifFalse: [forClass slots ifNotEmpty: [ self slotsOn: s ]].
forClass classVariables ifNotEmpty: [ self sharedVariablesOn: s ].
forClass sharedPools ifNotEmpty: [ self sharedPoolsOn: s ].

Expand Down

0 comments on commit 11304e7

Please sign in to comment.