Skip to content

Commit

Permalink
Merge pull request #738 from moosetechnology/number-of-comments
Browse files Browse the repository at this point in the history
Clean #numberOfComments
  • Loading branch information
jecisc authored Mar 25, 2024
2 parents 18e6794 + 9554734 commit 555efc6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 46 deletions.
11 changes: 0 additions & 11 deletions src/Famix-Java-Entities/FamixJavaClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/Famix-Java-Entities/FamixJavaMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,6 @@ FamixJavaMethod >> numberOfAccesses [
computedAs: [ self accesses size ]
]

{ #category : #accessing }
FamixJavaMethod >> numberOfComments [
<FMProperty: #numberOfComments type: #Number>
<FMComment: 'The number of comment fragments'>
<derived>
^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ]
]

{ #category : #'Famix-Extensions-private' }
FamixJavaMethod >> numberOfConditionals [
<FMProperty: #numberOfConditionals type: #Number>
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Java-Tests/FamixJavaCommentsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
11 changes: 0 additions & 11 deletions src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
<FMProperty: #numberOfMessageSends type: #Number>
Expand Down
8 changes: 0 additions & 8 deletions src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,6 @@ FamixStMethod >> numberOfAccesses [
computedAs: [ self accesses size ]
]

{ #category : #'Famix-Extensions-private' }
FamixStMethod >> numberOfComments [
<FMProperty: #numberOfComments type: #Number>
<FMComment: 'The number of comment fragments'>
<derived>
^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ]
]

{ #category : #'Famix-Extensions-private' }
FamixStMethod >> numberOfConditionals [
<FMProperty: #numberOfConditionals type: #Number>
Expand Down
8 changes: 3 additions & 5 deletions src/Famix-Traits/FamixTWithComments.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ FamixTWithComments >> hasComments [

{ #category : #accessing }
FamixTWithComments >> numberOfComments [

<FMProperty: #numberOfComments type: #Number>
<derived>
<FMComment: 'The number of comments in the entity'>
^ self
lookUpPropertyNamed: #numberOfComments
computedAs: [ self comments size ]

<FMComment: 'The number of comments in the entity. Does not count comments of children entities (for example, for a class, I will count the comments associated to the class and not the methods or arguments.'>
^ self lookUpPropertyNamed: #numberOfComments computedAs: [ self comments size ]
]

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 555efc6

Please sign in to comment.