From 9554734e06a642c32c3351b7ca457a7e16694092 Mon Sep 17 00:00:00 2001 From: CyrilFerlicot Date: Mon, 25 Mar 2024 12:16:41 +0100 Subject: [PATCH] Clean #numberOfComments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the implementation more coherant and adapt tests. It's weird for only classes to count children comments in the number of comments and I also removed some duplication. Fixes #735 --- src/Famix-Java-Entities/FamixJavaClass.class.st | 11 ----------- src/Famix-Java-Entities/FamixJavaMethod.class.st | 8 -------- src/Famix-Java-Tests/FamixJavaCommentsTest.class.st | 2 +- .../FamixStClass.class.st | 11 ----------- .../FamixStMethod.class.st | 8 -------- src/Famix-Traits/FamixTWithComments.trait.st | 8 +++----- .../LANFamixPropertiesTest.class.st | 13 +++++++++++-- 7 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/Famix-Java-Entities/FamixJavaClass.class.st b/src/Famix-Java-Entities/FamixJavaClass.class.st index 91137d94..491039d0 100644 --- a/src/Famix-Java-Entities/FamixJavaClass.class.st +++ b/src/Famix-Java-Entities/FamixJavaClass.class.st @@ -173,17 +173,6 @@ FamixJavaClass >> methodsWithoutSutbsAndConstructors [ each isStub not and: [each isConstructor not]]) asSet ] -{ #category : #accessing } -FamixJavaClass >> numberOfComments [ - "Overrides to include method comments in the numberOfComments of the class" - - ^ self lookUpPropertyNamed: #numberOfComments computedAs: [ - self children asArray inject: self comments size into: [ :sum :child | - (child class includesTrait: FamixTWithComments) - ifTrue: [ child numberOfComments + sum ] - ifFalse: [ sum ] ] ] -] - { #category : #'Famix-Extensions' } FamixJavaClass >> structuralChildren [ ^ (OrderedCollection withAll: self methods), self attributes diff --git a/src/Famix-Java-Entities/FamixJavaMethod.class.st b/src/Famix-Java-Entities/FamixJavaMethod.class.st index bc738a25..7e0dc403 100644 --- a/src/Famix-Java-Entities/FamixJavaMethod.class.st +++ b/src/Famix-Java-Entities/FamixJavaMethod.class.st @@ -280,14 +280,6 @@ FamixJavaMethod >> numberOfAccesses [ computedAs: [ self accesses size ] ] -{ #category : #accessing } -FamixJavaMethod >> numberOfComments [ - - - - ^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ] -] - { #category : #'Famix-Extensions-private' } FamixJavaMethod >> numberOfConditionals [ diff --git a/src/Famix-Java-Tests/FamixJavaCommentsTest.class.st b/src/Famix-Java-Tests/FamixJavaCommentsTest.class.st index 3fa7a48b..9d6469d6 100644 --- a/src/Famix-Java-Tests/FamixJavaCommentsTest.class.st +++ b/src/Famix-Java-Tests/FamixJavaCommentsTest.class.st @@ -25,5 +25,5 @@ FamixJavaCommentsTest >> testClassWithCommentAndMethodsWithComments [ FamixJavaComment new commentedEntity: (FamixJavaMethod new parentType: javaClass; yourself). - self assert: javaClass numberOfComments equals: 3 "one in the class, one on each of the 2 methods" + self assert: javaClass numberOfComments equals: 1 "Comments of children are not taken into account." ] diff --git a/src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st b/src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st index 3f55d0ba..9208260a 100644 --- a/src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st +++ b/src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st @@ -173,17 +173,6 @@ FamixStClass >> methodsWithoutSutbsAndConstructors [ ^ (self methods select: [ :each | each isStub not and: [ each isConstructor not ] ]) asSet ] -{ #category : #accessing } -FamixStClass >> numberOfComments [ - "Overrides to include method comments in the numberOfComments of the class" - - ^ self lookUpPropertyNamed: #numberOfComments computedAs: [ - self children asArray inject: self comments size into: [ :sum :child | - (child class includesTrait: FamixTWithComments) - ifTrue: [ child numberOfComments + sum ] - ifFalse: [ sum ] ] ] -] - { #category : #metrics } FamixStClass >> numberOfMessageSends [ diff --git a/src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st b/src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st index 9e0f152e..435a53f0 100644 --- a/src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st +++ b/src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st @@ -244,14 +244,6 @@ FamixStMethod >> numberOfAccesses [ computedAs: [ self accesses size ] ] -{ #category : #'Famix-Extensions-private' } -FamixStMethod >> numberOfComments [ - - - - ^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ] -] - { #category : #'Famix-Extensions-private' } FamixStMethod >> numberOfConditionals [ diff --git a/src/Famix-Traits/FamixTWithComments.trait.st b/src/Famix-Traits/FamixTWithComments.trait.st index 10c77ab9..25699cdf 100644 --- a/src/Famix-Traits/FamixTWithComments.trait.st +++ b/src/Famix-Traits/FamixTWithComments.trait.st @@ -61,13 +61,11 @@ FamixTWithComments >> hasComments [ { #category : #accessing } FamixTWithComments >> numberOfComments [ + - - ^ self - lookUpPropertyNamed: #numberOfComments - computedAs: [ self comments size ] - + + ^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ] ] { #category : #accessing } diff --git a/src/Moose-SmalltalkImporter-LAN-Tests/LANFamixPropertiesTest.class.st b/src/Moose-SmalltalkImporter-LAN-Tests/LANFamixPropertiesTest.class.st index b6c496fd..6a6446c1 100644 --- a/src/Moose-SmalltalkImporter-LAN-Tests/LANFamixPropertiesTest.class.st +++ b/src/Moose-SmalltalkImporter-LAN-Tests/LANFamixPropertiesTest.class.st @@ -78,9 +78,10 @@ LANFamixPropertiesTest >> testClassCategories [ { #category : #testing } LANFamixPropertiesTest >> testClassComments [ + self model allClasses do: [ :each | self assert: each numberOfComments >= 0 ]. - self assert: (self nodeClass propertyNamed: #numberOfComments) equals: 11. - self assert: self nodeClass numberOfComments equals: 11 + self assert: (self nodeClass propertyNamed: #numberOfComments) equals: 0. + self assert: self nodeClass numberOfComments equals: 0 ] { #category : #testing } @@ -158,6 +159,14 @@ LANFamixPropertiesTest >> testMethodAccesses [ self assert: (self model entityNamed: #'Smalltalk::LANInterface.originator()') numberOfAccesses equals: 3 ] +{ #category : #testing } +LANFamixPropertiesTest >> testMethodComments [ + + self model allMethods do: [ :each | self assert: each numberOfComments >= 0 ]. + self assert: (self lanInterfaceOriginateMethod propertyNamed: #numberOfComments) equals: 6. + self assert: self lanInterfaceOriginateMethod numberOfComments equals: 6 +] + { #category : #testing } LANFamixPropertiesTest >> testMethodHierarchyNesting [ self assert: (self lanInterfaceOriginateMethod propertyNamed: #hierarchyNestingLevel) equals: 1.