Skip to content

Commit 3001348

Browse files
authored
Merge pull request #725 from moosetechnology/724-overridingMethods-on-Java-class-methods-does-not-work-properly
Fix #724
2 parents 3bbdb33 + fea7087 commit 3001348

File tree

8 files changed

+129
-99
lines changed

8 files changed

+129
-99
lines changed

src/Famix-Java-Entities/FamixJavaClass.class.st

-10
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ FamixJavaClass >> accessedAttributes [
7777
^ self methodsWithoutSutbsAndConstructors asOrderedCollection flatCollect: [ :method | method accessedAttributes ]
7878
]
7979

80-
{ #category : #private }
81-
FamixJavaClass >> addMethodOverriding: aMethod in: aCollection [
82-
83-
self directSubclasses do: [ :subClass |
84-
subClass methods
85-
detect: [ :method | method signature = aMethod signature ]
86-
ifFound: [ :overridingMethod | aCollection add: overridingMethod ]
87-
ifNone: [ subClass addMethodOverriding: aMethod in: aCollection ] ]
88-
]
89-
9080
{ #category : #enumerating }
9181
FamixJavaClass >> allImplementedInterfacesHierarchy [
9282

src/Famix-Java-Entities/FamixJavaMethod.class.st

-10
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,6 @@ FamixJavaMethod >> overridesMethod [
333333
thenSelect: #isNotNil
334334
]
335335

336-
{ #category : #testing }
337-
FamixJavaMethod >> overridingMethods [
338-
339-
| overridingMethods |
340-
overridingMethods := OrderedCollection new.
341-
342-
self parentType addMethodOverriding: self in: overridingMethods.
343-
^ overridingMethods
344-
]
345-
346336
{ #category : #accessing }
347337
FamixJavaMethod >> parentScope [
348338
"Polymorphic alias to mimic GlobalVariable#parentScope and similar"

src/Famix-Java-Tests/FamixJavaMethodTest.class.st

+60-29
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,71 @@ FamixJavaMethodTest >> setUp [
1313
method := FamixJavaMethod new
1414
]
1515

16+
{ #category : #tests }
17+
FamixJavaMethodTest >> testAllOverridingMethods [
18+
19+
| signature overridingMethod otherOverridingMethod localClass subclass subSubclass |
20+
signature := 'javaMethod()'.
21+
method signature: signature.
22+
overridingMethod := FamixJavaMethod new signature: signature.
23+
otherOverridingMethod := FamixJavaMethod new signature: signature.
24+
25+
localClass := FamixJavaClass new.
26+
subclass := FamixJavaClass new.
27+
subSubclass := FamixJavaClass new.
28+
29+
localClass addMethod: method.
30+
subclass addMethod: overridingMethod.
31+
subSubclass addMethod: otherOverridingMethod.
32+
33+
FamixJavaInheritance new
34+
superclass: localClass;
35+
subclass: subclass.
36+
FamixJavaInheritance new
37+
superclass: subclass;
38+
subclass: subSubclass.
39+
40+
self
41+
assertCollection: method overridingMethods
42+
hasSameElements: {
43+
overridingMethod.
44+
otherOverridingMethod }
45+
]
46+
1647
{ #category : #tests }
1748
FamixJavaMethodTest >> testDefaultIsStub [
1849
self deny: method isStub
1950
]
2051

52+
{ #category : #tests }
53+
FamixJavaMethodTest >> testFirstOverridingMethods [
54+
55+
| signature overridingMethod otherOverridingMethod localClass subclass subSubclass |
56+
signature := 'javaMethod()'.
57+
method signature: signature.
58+
overridingMethod := FamixJavaMethod new signature: signature.
59+
otherOverridingMethod := FamixJavaMethod new signature: signature.
60+
61+
localClass := FamixJavaClass new.
62+
subclass := FamixJavaClass new.
63+
subSubclass := FamixJavaClass new.
64+
65+
localClass addMethod: method.
66+
subclass addMethod: overridingMethod.
67+
subSubclass addMethod: otherOverridingMethod.
68+
69+
FamixJavaInheritance new
70+
superclass: localClass;
71+
subclass: subclass.
72+
FamixJavaInheritance new
73+
superclass: subclass;
74+
subclass: subSubclass.
75+
76+
self
77+
assertCollection: method firstOverridingMethods
78+
hasSameElements: { overridingMethod }
79+
]
80+
2181
{ #category : #tests }
2282
FamixJavaMethodTest >> testIsClassSide [
2383

@@ -212,35 +272,6 @@ FamixJavaMethodTest >> testOverridingMethods [
212272
hasSameElements: { overridingMethod }
213273
]
214274

215-
{ #category : #tests }
216-
FamixJavaMethodTest >> testOverridingMethodsOnlyOneLevel [
217-
218-
| signature overridingMethod otherOverridingMethod localClass subclass subSubclass |
219-
signature := 'javaMethod()'.
220-
method signature: signature.
221-
overridingMethod := FamixJavaMethod new signature: signature.
222-
otherOverridingMethod := FamixJavaMethod new signature: signature.
223-
224-
localClass := FamixJavaClass new.
225-
subclass := FamixJavaClass new.
226-
subSubclass := FamixJavaClass new.
227-
228-
localClass addMethod: method.
229-
subclass addMethod: overridingMethod.
230-
subSubclass addMethod: otherOverridingMethod.
231-
232-
FamixJavaInheritance new
233-
superclass: localClass;
234-
subclass: subclass.
235-
FamixJavaInheritance new
236-
superclass: subclass;
237-
subclass: subSubclass.
238-
239-
self
240-
assertCollection: method overridingMethods
241-
hasSameElements: { overridingMethod }
242-
]
243-
244275
{ #category : #tests }
245276
FamixJavaMethodTest >> testSettingIsStub [
246277
method isStub: true.

src/Famix-PharoSmalltalk-Entities/FamixStClass.class.st

-10
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ FamixStClass >> accessedAttributes [
7171
^ self methodsWithoutSutbsAndConstructors asOrderedCollection flatCollect: [ :method | method accessedAttributes ]
7272
]
7373

74-
{ #category : #testing }
75-
FamixStClass >> addMethodOverriding: aMethod in: aCollection [
76-
77-
self directSubclasses do: [ :subClass |
78-
subClass methods
79-
detect: [ :method | method signature = aMethod signature ]
80-
ifFound: [ :overridingMethod | aCollection add: overridingMethod ]
81-
ifNone: [ subClass addMethodOverriding: aMethod in: aCollection ] ]
82-
]
83-
8474
{ #category : #accessing }
8575
FamixStClass >> allRecursiveTypes [
8676
"We cannot have children types in Smalltalk but this method is useful to compute some metrics."

src/Famix-PharoSmalltalk-Entities/FamixStMethod.class.st

-10
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,6 @@ FamixStMethod >> overriddenMethod [
297297
superclass lookUp: self signature ])
298298
]
299299

300-
{ #category : #testing }
301-
FamixStMethod >> overridingMethods [
302-
303-
| overridingMethods |
304-
overridingMethods := OrderedCollection new.
305-
306-
self parentType addMethodOverriding: self in: overridingMethods.
307-
^ overridingMethods
308-
]
309-
310300
{ #category : #'Famix-Extensions-metrics-support' }
311301
FamixStMethod >> printProtocol [
312302

src/Famix-PharoSmalltalk-Tests/FamixPharoMethodTest.class.st

+29-30
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ FamixPharoMethodTest >> setUp [
1919
method signature: signature.
2020
]
2121

22+
{ #category : #tests }
23+
FamixPharoMethodTest >> testFirstOverridingMethods [
24+
25+
| overridingMethod otherOverridingMethod localClass subclass subSubclass |
26+
27+
overridingMethod := FamixStMethod new signature: signature.
28+
otherOverridingMethod := FamixStMethod new signature: signature.
29+
30+
localClass := FamixStClass new.
31+
subclass := FamixStClass new.
32+
subSubclass := FamixStClass new.
33+
34+
localClass addMethod: method.
35+
subclass addMethod: overridingMethod.
36+
subSubclass addMethod: otherOverridingMethod.
37+
38+
FamixStInheritance new
39+
superclass: localClass;
40+
subclass: subclass.
41+
FamixStInheritance new
42+
superclass: subclass;
43+
subclass: subSubclass.
44+
45+
self
46+
assertCollection: method firstOverridingMethods
47+
hasSameElements: { overridingMethod }
48+
]
49+
2250
{ #category : #tests }
2351
FamixPharoMethodTest >> testIsClassSide [
2452
| method |
@@ -76,8 +104,7 @@ FamixPharoMethodTest >> testOverriddenMethodOnlyOneLevel [
76104
{ #category : #tests }
77105
FamixPharoMethodTest >> testOverridingMethods [
78106

79-
| signature overridingMethod c1 c2 |
80-
signature := 'pharoMethod'.
107+
| overridingMethod c1 c2 |
81108
method signature: signature.
82109
overridingMethod := FamixStMethod new signature: signature.
83110

@@ -96,34 +123,6 @@ FamixPharoMethodTest >> testOverridingMethods [
96123
hasSameElements: { overridingMethod }
97124
]
98125

99-
{ #category : #tests }
100-
FamixPharoMethodTest >> testOverridingMethodsOnlyOneLevel [
101-
102-
| overridingMethod otherOverridingMethod localClass subclass subSubclass |
103-
104-
overridingMethod := FamixStMethod new signature: signature.
105-
otherOverridingMethod := FamixStMethod new signature: signature.
106-
107-
localClass := FamixStClass new.
108-
subclass := FamixStClass new.
109-
subSubclass := FamixStClass new.
110-
111-
localClass addMethod: method.
112-
subclass addMethod: overridingMethod.
113-
subSubclass addMethod: otherOverridingMethod.
114-
115-
FamixStInheritance new
116-
superclass: localClass;
117-
subclass: subclass.
118-
FamixStInheritance new
119-
superclass: subclass;
120-
subclass: subSubclass.
121-
122-
self
123-
assertCollection: method overridingMethods
124-
hasSameElements: { overridingMethod }
125-
]
126-
127126
{ #category : #tests }
128127
FamixPharoMethodTest >> testSeveralOverridingMethods [
129128

src/Famix-Traits/FamixTClass.trait.st

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ FamixTClass classSide >> annotationFamixClassGroup [
7171
^ FamixClassGroup
7272
]
7373

74+
{ #category : #adding }
75+
FamixTClass >> addFirstMethodsOverriding: aMethod in: aCollection [
76+
77+
self directSubclasses do: [ :subClass |
78+
subClass methods
79+
detect: [ :method | method signature = aMethod signature ]
80+
ifFound: [ :overridingMethod | aCollection add: overridingMethod ]
81+
ifNone: [ subClass addMethodOverriding: aMethod in: aCollection ] ]
82+
]
83+
84+
{ #category : #private }
85+
FamixTClass >> addMethodOverriding: aMethod in: aCollection [
86+
87+
self directSubclasses do: [ :subClass |
88+
subClass methods
89+
detect: [ :method | method signature = aMethod signature ]
90+
ifFound: [ :overridingMethod | aCollection add: overridingMethod ].
91+
subClass addMethodOverriding: aMethod in: aCollection ]
92+
]
93+
7494
{ #category : #metrics }
7595
FamixTClass >> addedMethods [
7696
| allHierarchyMethodSignatures |

src/Famix-Traits/FamixTMethod.trait.st

+20
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ FamixTMethod classSide >> annotationFamixMethodGroup [
7373
^ FamixMethodGroup
7474
]
7575

76+
{ #category : #accessing }
77+
FamixTMethod >> firstOverridingMethods [
78+
79+
| overridingMethods |
80+
overridingMethods := OrderedCollection new.
81+
82+
self parentType addFirstMethodsOverriding: self in: overridingMethods.
83+
^ overridingMethods
84+
]
85+
7686
{ #category : #testing }
7787
FamixTMethod >> isDelegating [
7888

@@ -114,6 +124,16 @@ FamixTMethod >> mooseNameOn: stream [
114124
ifNil: [ self name ifNotNil: [ :aName | stream nextPutAll: aName ] ]
115125
]
116126

127+
{ #category : #testing }
128+
FamixTMethod >> overridingMethods [
129+
130+
| overridingMethods |
131+
overridingMethods := OrderedCollection new.
132+
133+
self parentType addMethodOverriding: self in: overridingMethods.
134+
^ overridingMethods
135+
]
136+
117137
{ #category : #accessing }
118138
FamixTMethod >> parentType [
119139
"Relation named: #parentType type: #FamixTWithMethods opposite: #methods"

0 commit comments

Comments
 (0)