@@ -21,41 +21,47 @@ FamixSimpleDiff >> compareEntity: aFamixEntity to: otherFamixEntity [
2121
2222 | properties relations diff isEquals |
2323 isEquals := true .
24-
24+
2525 " we compare the type of the entities. If we have not the same type, we add the difference in the list"
26- aFamixEntity class = otherFamixEntity class ifFalse: [
27- diff := FamixSimpleDifference createEntityChanged: otherFamixEntity expectedValue: aFamixEntity class name actualValue: otherFamixEntity class name.
28- self addDifference: diff.
29- ^ self fail
30- ].
26+ aFamixEntity class = otherFamixEntity class ifFalse: [
27+ diff := FamixSimpleDifference
28+ createEntityChanged: otherFamixEntity
29+ expectedValue: aFamixEntity class name
30+ actualValue: otherFamixEntity class name.
31+ self addDifference: diff.
32+ ^ self fail ].
3133
3234 " Comparing properties (slots with non-famix values)"
3335 properties := aFamixEntity class allSlots select: [ :slot |
3436 slot class = FMProperty ].
37+
3538 properties do: [ :p |
3639 (p read: aFamixEntity) = (p read: otherFamixEntity) ifFalse: [
37- | prop1 prop2 |
38- prop1 := p read: aFamixEntity.
39- prop2 := p read: otherFamixEntity.
40-
41- diff := FamixSimpleDifference createPropertyChanged: otherFamixEntity expectedValue: prop1 actualValue: prop2.
42- self addDifference: diff.
43- isEquals := false
44- ]
45- ].
40+ | prop1 prop2 |
41+ prop1 := p read: aFamixEntity.
42+ prop2 := p read: otherFamixEntity.
43+
44+ diff := FamixSimpleDifference
45+ createPropertyChanged: otherFamixEntity
46+ expectedValue: prop1
47+ actualValue: prop2.
48+ self addDifference: diff.
49+ isEquals := false ] ].
4650
4751 " Comparing relations (slots with famix values)"
4852 " We exclude source anchors because they are not relevant to model comparison"
49- relations := aFamixEntity class allSlots select: [ :slot | slot isFMRelationSlot and : [ slot name ~= ' sourceAnchor' ] ].
53+ relations := aFamixEntity class allSlots select: [ :slot |
54+ slot isFMRelationSlot and : [
55+ slot name ~= ' sourceAnchor' ] ].
56+
5057 relations do: [ :r |
51- " self haltIf: [ r name = #methods ]."
5258 (self compareRelation: r from: aFamixEntity to: otherFamixEntity)
5359 ifFalse: [ isEquals := false ] ].
5460
5561 " we stop the execution here if models are differents"
5662 isEquals ifFalse: [ ^ self fail ].
57-
58- " Every slot value is equal, the entities are identical"
63+
64+ " Every slot value are equal, the entities are identical"
5965 ^ true
6066]
6167
@@ -75,16 +81,16 @@ FamixSimpleDiff >> compareModel: aFamixJavaModel to: aFamixJavaModel2 [
7581
7682{ #category : ' comparing' }
7783FamixSimpleDiff >> compareRelation: aFMRelationSlot from: aFamixEntity to: otherFamixEntity [
78- | val1 val2 sortBlock |
79-
84+
85+ | val1 val2 sortBlock |
8086 aFMRelationSlot isToOne
8187 ifTrue: [
8288 val1 := aFMRelationSlot read: aFamixEntity.
8389 val2 := aFMRelationSlot read: otherFamixEntity ]
8490 ifFalse: [
8591 | rejectBlock |
8692 val1 := (aFMRelationSlot read: aFamixEntity) asOrderedCollection.
87- val2 := (aFMRelationSlot read: otherFamixEntity)asOrderedCollection.
93+ val2 := (aFMRelationSlot read: otherFamixEntity) asOrderedCollection.
8894
8995 sortBlock := val1
9096 ifEmpty: [ self sortBlock ]
@@ -103,8 +109,16 @@ FamixSimpleDiff >> compareRelation: aFMRelationSlot from: aFamixEntity to: other
103109 val1 == val2 ifTrue: [ ^ true ].
104110
105111 ^ aFMRelationSlot isToOne
106- ifTrue: [ self compareToOneRelation: val1 actual: val2 target: otherFamixEntity ]
107- ifFalse: [ self compareToManyRelation: val1 actual: val2 target: otherFamixEntity ]
112+ ifTrue: [
113+ self
114+ compareToOneRelation: val1
115+ actual: val2
116+ target: otherFamixEntity ]
117+ ifFalse: [
118+ self
119+ compareToManyRelation: val1
120+ actual: val2
121+ target: otherFamixEntity ]
108122]
109123
110124{ #category : ' comparing' }
@@ -117,70 +131,67 @@ FamixSimpleDiff >> compareToManyRelation: val1 actual: val2 target: anEntity [
117131 Return true if models are equals, false otherwise.
118132 "
119133
120- | stream1 stream2 isEquals diff |
134+ | stream1 stream2 isEquals diff |
121135 isEquals := true .
122-
136+
123137 stream1 := val1 readStream.
124138 stream2 := val2 readStream.
125-
139+
126140 " looking the streams"
127- [ stream1 atEnd or : [ stream2 atEnd ] ] whileFalse: [
128- | elt1 elt2 name1 name2 |
129-
130- " setup name"
131- elt1 := stream1 peek.
132- elt2 := stream2 peek.
133-
134- name1 := elt1 mooseName.
135- name2 := elt2 mooseName.
136-
137- name1 = name2
138- " move forward both ptr if identicals"
139- ifTrue: [
140- stream1 next.
141- stream2 next.
142- ]
143-
144- ifFalse: [
145- " deletion case"
146- name1 < name2
147- ifTrue: [
148- diff := FamixSimpleDifference createEntityDeletion: anEntity expectedValue: elt1.
149- self addDifference: diff.
150- isEquals := false .
151- stream1 next. " ptr1++"
152- ]
153-
154- " addition case"
155- ifFalse: [
156- diff := FamixSimpleDifference createEntityAdded: anEntity actualValue: elt2.
157- self addDifference: diff.
158- isEquals := false .
159- stream2 next." ptr2++"
160- ]
161- ].
162- ].
141+ [ stream1 atEnd or : [ stream2 atEnd ] ] whileFalse: [
142+ | element1 element2 name1 name2 |
143+
144+ " setup name"
145+ element1 := stream1 peek.
146+ element2 := stream2 peek.
147+
148+ name1 := element1 mooseName.
149+ name2 := element2 mooseName.
150+
151+ name1 = name2
152+ ifTrue: [" move forward both ptr if identicals"
153+ stream1 next.
154+ stream2 next ]
155+ ifFalse: [
156+ name1 < name2
157+ ifTrue: [" deletion case"
158+ diff := FamixSimpleDifference
159+ createEntityDeletion: anEntity
160+ expectedValue: element1.
161+ self addDifference: diff.
162+ isEquals := false .
163+ stream1 next " ptr1++" ]
164+
165+ ifFalse: [" addition case"
166+ diff := FamixSimpleDifference
167+ createEntityAdded: anEntity
168+ actualValue: element2.
169+ self addDifference: diff.
170+ isEquals := false .
171+ stream2 next " ptr2++" ] ] ].
163172
164173 " cleaning end of pointers, checking if they have clean something"
165174 " if they have deleted/added something, so the models are not equals"
166- (self finishRemainingDeletionOf: stream1 target: anEntity ) ifTrue: [ isEquals := false ].
167- (self finishRemainingAdditionOf: stream2 target: anEntity ) ifTrue: [ isEquals := false ].
168-
169- ^ isEquals
175+ (self finishRemainingDeletionOf: stream1 target: anEntity) ifTrue: [isEquals := false ].
176+ (self finishRemainingAdditionOf: stream2 target: anEntity) ifTrue: [isEquals := false ].
177+
178+ ^ isEquals
170179]
171180
172181{ #category : ' comparing' }
173182FamixSimpleDiff >> compareToOneRelation: val1 actual: val2 target: anEntity [
174- | areSame diff |
175183
184+ | areEquals diff |
176185 " if we dont have the same relations, so it changed, we have to record it"
177- areSame := (self pathesForMaybeMultiRelation: val1) = (self pathesForMaybeMultiRelation: val2).
178- areSame ifFalse: [
179- diff := FamixSimpleDifference createRelationChanged: anEntity expectedValue: val1 actualValue: val2.
180- self addDifference: diff.
181- ].
182-
183- ^ areSame " if they are not the same, so they are not equals"
186+ areEquals := (self pathesForMaybeMultiRelation: val1) = (self pathesForMaybeMultiRelation: val2).
187+ areEquals ifFalse: [
188+ diff := FamixSimpleDifference
189+ createRelationChanged: anEntity
190+ expectedValue: val1
191+ actualValue: val2.
192+ self addDifference: diff ].
193+
194+ ^ areEquals
184195]
185196
186197{ #category : ' path-computing' }
@@ -206,7 +217,6 @@ FamixSimpleDiff >> correspondingEntityTo: entity in: model [
206217 | path |
207218 path := self pathOfEntity: entity.
208219 ^ self entityAtPath: path inModel: model
209-
210220]
211221
212222{ #category : ' debug' }
@@ -217,6 +227,7 @@ FamixSimpleDiff >> debugOn [
217227
218228{ #category : ' accessing' }
219229FamixSimpleDiff >> differences [
230+
220231 ^ differences
221232]
222233
@@ -234,7 +245,6 @@ FamixSimpleDiff >> entityAtPath: indexPath fromEntity: entity [
234245FamixSimpleDiff >> entityAtPath: indexPath inModel: model [
235246
236247 | rootEntity |
237-
238248 rootEntity := (self entityRoots: model) at: indexPath first.
239249 ^ self entityAtPath: indexPath allButFirst fromEntity: rootEntity
240250]
@@ -268,17 +278,16 @@ FamixSimpleDiff >> fail [
268278
269279{ #category : ' accessing' }
270280FamixSimpleDiff >> finishRemaining: aStream diffCreation: aDifferenceCreation [
271- | modelsAreDifferents diff |
281+
282+ | modelsAreDifferents diff |
272283 modelsAreDifferents := false .
273-
274- [ aStream atEnd ]
275- whileFalse: [
276- diff := aDifferenceCreation value: aStream next.
277- self addDifference: diff.
278- modelsAreDifferents := true .
279- ].
280-
281- ^ modelsAreDifferents.
284+
285+ [ aStream atEnd ] whileFalse: [
286+ diff := aDifferenceCreation value: aStream next.
287+ self addDifference: diff.
288+ modelsAreDifferents := true ].
289+
290+ ^ modelsAreDifferents
282291]
283292
284293{ #category : ' accessing' }
@@ -292,16 +301,16 @@ FamixSimpleDiff >> finishRemainingAdditionOf: aStream target: anEntity [
292301FamixSimpleDiff >> finishRemainingDeletionOf: aStream target: anEntity [
293302
294303 ^ self finishRemaining: aStream diffCreation: [ :val |
295- FamixSimpleDifference createEntityDeletion: anEntity expectedValue: val ]
304+ FamixSimpleDifference createEntityDeletion: anEntity expectedValue: val ]
296305]
297306
298307{ #category : ' initialization' }
299308FamixSimpleDiff >> initialize [
300-
309+
301310 super initialize.
302311 debug := false .
303312 childrenCache := LRUCache new maximumWeight: 100 .
304- differences := OrderedCollection new .
313+ differences := OrderedCollection new
305314]
306315
307316{ #category : ' path-computing' }
@@ -390,7 +399,7 @@ FamixSimpleDiff >> sortedChildren: entity [
390399 ifNotNil: [ " case for two entities with identical printing string but different source anchor (several inner classes in the same parent for example)"
391400 a sourceAnchor endPos < b sourceAnchor endPos ]
392401 ifNil: [ valA < valB ] ]
393- ifNil: [ valA < valB] ]
402+ ifNil: [ valA < valB ] ]
394403 ifFalse: [ valA < valB ] ] ].
395404
396405
0 commit comments