Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/FamixReplication/FamixTSourceEntity.extension.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Extension { #name : 'FamixTSourceEntity' }

{ #category : '*FamixReplication' }
FamixTSourceEntity >> addReplica: anObject [
self replicas add: anObject
FamixTSourceEntity >> addReplica: anObject [
"If we do not have replicats but need to add one, we now save the collection in the cache in contrary of #replicas."

(self cacheAt: #replicas ifAbsentPut: [ OrderedCollection new ]) add: anObject
]

{ #category : '*FamixReplication' }
FamixTSourceEntity >> clearReplicationCache [

self cacheAt: #replicas put: OrderedCollection new
self removeCache: #replicas
]

{ #category : '*FamixReplication' }
Expand All @@ -24,9 +26,14 @@ FamixTSourceEntity >> containsReplicas [
<FMProperty: #containsReplicas type: #Boolean>
<derived>
<FMComment: 'Flag true if the entity contains duplication.'>
self replicas ifNotEmpty: [ ^ true ].

^ self containedEntities anySatisfy: #containsReplicas

"If the cache is present, then there should be at least one replica"
self cacheAt: #replicas ifPresent: [ ^ true ].

"Iterating over the children for speed reason instead of using an #anySatisfy:"
self containedEntitiesDo: [ :child | child containsReplicas ifTrue: [ ^ true ] ].

^ false
]

{ #category : '*FamixReplication' }
Expand Down Expand Up @@ -75,14 +82,16 @@ FamixTSourceEntity >> mergePossibleDuplications [

{ #category : '*FamixReplication' }
FamixTSourceEntity >> removeReplica: aReplica [
self containsReplicas ifTrue: [ self replicas remove: aReplica ]

self cacheAt: #replicas ifPresent: [ :collection | collection remove: aReplica ]
]

{ #category : '*FamixReplication' }
FamixTSourceEntity >> replicas [
"If the entity does not have replicats, return en empty collection that we will not save to not add overhead to the memory"

<FMProperty: #replicas type: #FamixReplica>
<FMComment: 'A collection of fragments of cloned code found in this program'>
<derived>
^ self cacheAt: #replicas ifAbsentPut: [ OrderedCollection new ]
^ self cacheAt: #replicas ifAbsent: [ OrderedCollection new ]
]
25 changes: 13 additions & 12 deletions src/FamixReplication/MooseModel.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ MooseModel >> allBehaviouralsWithDuplicatedCode [
<navigation: 'All executables with duplicated code'>
^ self cacheAt: #allBehaviouralsWithDuplicatedCode ifAbsent: [
'Compute allBehaviouralsWithDuplicatedCode' record. "Ensure the replication detection was run."
self replicationManager ifNil: [ MooseUnavailableMetric ].

self allModelBehaviourals select: #containsReplicas ]
self replicationManager
ifNotNil: [ self allModelBehaviourals select: #containsReplicas ]
ifNil: [ MooseUnavailableMetric ] ]
]

{ #category : '*FamixReplication' }
Expand All @@ -17,9 +17,9 @@ MooseModel >> allContainersWithDuplicatedCode [
<navigation: 'All containers with duplicated code'>
^ self cacheAt: #allContainersWithDuplicatedCode ifAbsent: [
'Compute allContainersWithDuplicatedCode' record. "Ensure the replication detection was run."
self replicationManager ifNil: [ MooseUnavailableMetric ].

self allModelContainers select: #containsReplicas ]
self replicationManager
ifNotNil: [ self allModelContainers select: #containsReplicas ]
ifNil: [ MooseUnavailableMetric ] ]
]

{ #category : '*FamixReplication' }
Expand Down Expand Up @@ -84,14 +84,15 @@ MooseModel >> importReplicationFrom: file [

{ #category : '*FamixReplication' }
MooseModel >> initializeReplicationManager [
self clearReplicationManager.

^ self replicationDetectionConfiguration
ifNil: [ 'No duplication configuration detected. Skip detection.' record.
nil ]
ifNotNil: [ :config |
'Initialize replication detector' record.
(FamixRepDetector runOn: self entitiesForReplicationDetection with: config) in: [ :manager | self replicationManager: manager ] ]
ifNil: [
'No duplication configuration detected. Skip detection.' record.
nil ]
ifNotNil: [ :config |
'Initialize replication detector' record.
self clearReplicationManager.
(FamixRepDetector runOn: self entitiesForReplicationDetection with: config) in: [ :manager | self replicationManager: manager ] ]
]

{ #category : '*FamixReplication' }
Expand Down