From 11304e715895c16974583296576a836b74cee4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Sun, 10 Jan 2021 18:01:10 +0100 Subject: [PATCH] Fixes: #8332. --- .../CommonClassDefinitionPrinterTest.class.st | 9 ++++-- .../FluidClassDefinitionPrinterTest.class.st | 30 +++++++++++++++++++ src/Kernel/ClassDefinitionPrinter.class.st | 28 ++++++++++++++++- .../FluidClassDefinitionPrinter.class.st | 5 ++-- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Kernel-Tests/CommonClassDefinitionPrinterTest.class.st b/src/Kernel-Tests/CommonClassDefinitionPrinterTest.class.st index 4875417d60b..25a99713057 100644 --- a/src/Kernel-Tests/CommonClassDefinitionPrinterTest.class.st +++ b/src/Kernel-Tests/CommonClassDefinitionPrinterTest.class.st @@ -6,7 +6,8 @@ Class { #name : #CommonClassDefinitionPrinterTest, #superclass : #TestCase, #instVars : [ - 'slotuse' + 'slotDisplay', + 'slotUse' ], #category : #'Kernel-Tests-Fluid' } @@ -14,13 +15,15 @@ Class { { #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 ] diff --git a/src/Kernel-Tests/FluidClassDefinitionPrinterTest.class.st b/src/Kernel-Tests/FluidClassDefinitionPrinterTest.class.st index ec5184d10df..17e28af81e3 100644 --- a/src/Kernel-Tests/FluidClassDefinitionPrinterTest.class.st +++ b/src/Kernel-Tests/FluidClassDefinitionPrinterTest.class.st @@ -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 [ diff --git a/src/Kernel/ClassDefinitionPrinter.class.st b/src/Kernel/ClassDefinitionPrinter.class.st index e83d9e8a05e..a189f38f427 100644 --- a/src/Kernel/ClassDefinitionPrinter.class.st +++ b/src/Kernel/ClassDefinitionPrinter.class.st @@ -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 @@ -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 } diff --git a/src/Kernel/FluidClassDefinitionPrinter.class.st b/src/Kernel/FluidClassDefinitionPrinter.class.st index 8a1d03a81a9..b30d6e7aab4 100644 --- a/src/Kernel/FluidClassDefinitionPrinter.class.st +++ b/src/Kernel/FluidClassDefinitionPrinter.class.st @@ -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 ].