Skip to content

Commit d4a9b13

Browse files
authored
Merge pull request #726 from moosetechnology/723-overridingMethods-on-Java-interface-methods-does-not-work-properly
Fix #723
2 parents 3001348 + c557e83 commit d4a9b13

File tree

2 files changed

+130
-6
lines changed

2 files changed

+130
-6
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ FamixJavaInterface class >> annotation [
6363
{ #category : #private }
6464
FamixJavaInterface >> addMethodOverriding: aMethod in: aCollection [
6565

66-
(self implementations collect: #implementingClass) do: [
67-
:implementingClass |
68-
implementingClass addMethodOverriding: aMethod in: aCollection ].
66+
self implementations do: [ :implementation |
67+
| implClass |
68+
implClass := implementation implementingClass.
69+
implClass methods
70+
detect: [ :method | method signature = aMethod signature ]
71+
ifFound: [ :overridingMethod | aCollection add: overridingMethod ].
72+
implClass addMethodOverriding: aMethod in: aCollection ].
6973

7074
self directSubclasses do: [ :subInterface |
7175
subInterface methods
7276
detect: [ :method | method signature = aMethod signature ]
73-
ifFound: [ :overridingMethod | aCollection add: overridingMethod ]
74-
ifNone: [
75-
subInterface addMethodOverriding: aMethod in: aCollection ] ]
77+
ifFound: [ :overridingMethod | aCollection add: overridingMethod ].
78+
79+
subInterface addMethodOverriding: aMethod in: aCollection ]
7680
]
7781

7882
{ #category : #testing }

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

+120
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,74 @@ FamixJavaMethodTest >> testAllOverridingMethods [
4444
otherOverridingMethod }
4545
]
4646

47+
{ #category : #tests }
48+
FamixJavaMethodTest >> testAllOverridingMethodsInInterface [
49+
50+
| signature overridingMethod otherOverridingMethod i subclass subSubclass |
51+
signature := 'javaMethod()'.
52+
method signature: signature.
53+
overridingMethod := FamixJavaMethod new signature: signature.
54+
otherOverridingMethod := FamixJavaMethod new signature: signature.
55+
56+
i := FamixJavaInterface new.
57+
subclass := FamixJavaClass new.
58+
subSubclass := FamixJavaClass new.
59+
60+
i addMethod: method.
61+
subclass addMethod: overridingMethod.
62+
subSubclass addMethod: otherOverridingMethod.
63+
64+
FamixJavaImplementation new
65+
interface: i;
66+
implementingClass: subclass.
67+
FamixJavaInheritance new
68+
superclass: subclass;
69+
subclass: subSubclass.
70+
71+
self assertCollection: method overridingMethods hasSameElements: {
72+
overridingMethod.
73+
otherOverridingMethod }
74+
]
75+
76+
{ #category : #tests }
77+
FamixJavaMethodTest >> testAllOverridingMethodsInInterfaceWithExtendingInterface [
78+
79+
| signature overridingMethod otherOverridingMethod i subclass subSubclass i2 |
80+
signature := 'javaMethod()'.
81+
method signature: signature.
82+
overridingMethod := FamixJavaMethod new signature: signature.
83+
otherOverridingMethod := FamixJavaMethod new signature: signature.
84+
85+
i := FamixJavaInterface new
86+
name: 'i';
87+
yourself.
88+
i2 := FamixJavaInterface new
89+
name: 'i2';
90+
yourself.
91+
92+
subclass := FamixJavaClass new.
93+
subSubclass := FamixJavaClass new.
94+
95+
i addMethod: method.
96+
subclass addMethod: overridingMethod.
97+
subSubclass addMethod: otherOverridingMethod.
98+
99+
FamixJavaInheritance new
100+
superclass: i;
101+
subclass: i2.
102+
FamixJavaImplementation new
103+
interface: i2;
104+
implementingClass: subclass.
105+
106+
FamixJavaInheritance new
107+
superclass: subclass;
108+
subclass: subSubclass.
109+
110+
self assertCollection: method overridingMethods hasSameElements: {
111+
overridingMethod.
112+
otherOverridingMethod }
113+
]
114+
47115
{ #category : #tests }
48116
FamixJavaMethodTest >> testDefaultIsStub [
49117
self deny: method isStub
@@ -272,6 +340,58 @@ FamixJavaMethodTest >> testOverridingMethods [
272340
hasSameElements: { overridingMethod }
273341
]
274342

343+
{ #category : #tests }
344+
FamixJavaMethodTest >> testOverridingMethodsInInterface [
345+
346+
| signature overridingMethod i c |
347+
signature := 'javaMethod()'.
348+
method signature: signature.
349+
overridingMethod := FamixJavaMethod new signature: signature.
350+
351+
i := FamixJavaInterface new.
352+
c := FamixJavaClass new.
353+
354+
i addMethod: method.
355+
c addMethod: overridingMethod.
356+
357+
FamixJavaImplementation new
358+
interface: i;
359+
implementingClass: c.
360+
361+
self
362+
assertCollection: method overridingMethods
363+
hasSameElements: { overridingMethod }
364+
]
365+
366+
{ #category : #tests }
367+
FamixJavaMethodTest >> testOverridingMethodsInterfaceExtendsInterface [
368+
369+
| signature overridingMethod i i2 overridingMethod2 i3 |
370+
signature := 'javaMethod()'.
371+
method signature: signature.
372+
overridingMethod := FamixJavaMethod new signature: signature.
373+
overridingMethod2 := FamixJavaMethod new signature: signature.
374+
375+
i := FamixJavaInterface new.
376+
i2 := FamixJavaInterface new.
377+
i3 := FamixJavaInterface new.
378+
i addMethod: method.
379+
i2 addMethod: overridingMethod.
380+
i3 addMethod: overridingMethod2.
381+
382+
FamixJavaInheritance new
383+
superclass: i;
384+
subclass: i2.
385+
386+
FamixJavaInheritance new
387+
superclass: i2;
388+
subclass: i3.
389+
390+
self assertCollection: method overridingMethods hasSameElements: {
391+
overridingMethod.
392+
overridingMethod2 }
393+
]
394+
275395
{ #category : #tests }
276396
FamixJavaMethodTest >> testSettingIsStub [
277397
method isStub: true.

0 commit comments

Comments
 (0)