Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #723 #726

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
16 changes: 10 additions & 6 deletions src/Famix-Java-Entities/FamixJavaInterface.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ FamixJavaInterface class >> annotation [
{ #category : #private }
FamixJavaInterface >> addMethodOverriding: aMethod in: aCollection [

(self implementations collect: #implementingClass) do: [
:implementingClass |
implementingClass addMethodOverriding: aMethod in: aCollection ].
self implementations do: [ :implementation |
| implClass |
implClass := implementation implementingClass.
implClass methods
detect: [ :method | method signature = aMethod signature ]
ifFound: [ :overridingMethod | aCollection add: overridingMethod ].
implClass addMethodOverriding: aMethod in: aCollection ].

self directSubclasses do: [ :subInterface |
subInterface methods
detect: [ :method | method signature = aMethod signature ]
ifFound: [ :overridingMethod | aCollection add: overridingMethod ]
ifNone: [
subInterface addMethodOverriding: aMethod in: aCollection ] ]
ifFound: [ :overridingMethod | aCollection add: overridingMethod ].

subInterface addMethodOverriding: aMethod in: aCollection ]
]

{ #category : #testing }
Expand Down
120 changes: 120 additions & 0 deletions src/Famix-Java-Tests/FamixJavaMethodTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,74 @@ FamixJavaMethodTest >> testAllOverridingMethods [
otherOverridingMethod }
]

{ #category : #tests }
FamixJavaMethodTest >> testAllOverridingMethodsInInterface [

| signature overridingMethod otherOverridingMethod i subclass subSubclass |
signature := 'javaMethod()'.
method signature: signature.
overridingMethod := FamixJavaMethod new signature: signature.
otherOverridingMethod := FamixJavaMethod new signature: signature.

i := FamixJavaInterface new.
subclass := FamixJavaClass new.
subSubclass := FamixJavaClass new.

i addMethod: method.
subclass addMethod: overridingMethod.
subSubclass addMethod: otherOverridingMethod.

FamixJavaImplementation new
interface: i;
implementingClass: subclass.
FamixJavaInheritance new
superclass: subclass;
subclass: subSubclass.

self assertCollection: method overridingMethods hasSameElements: {
overridingMethod.
otherOverridingMethod }
]

{ #category : #tests }
FamixJavaMethodTest >> testAllOverridingMethodsInInterfaceWithExtendingInterface [

| signature overridingMethod otherOverridingMethod i subclass subSubclass i2 |
signature := 'javaMethod()'.
method signature: signature.
overridingMethod := FamixJavaMethod new signature: signature.
otherOverridingMethod := FamixJavaMethod new signature: signature.

i := FamixJavaInterface new
name: 'i';
yourself.
i2 := FamixJavaInterface new
name: 'i2';
yourself.

subclass := FamixJavaClass new.
subSubclass := FamixJavaClass new.

i addMethod: method.
subclass addMethod: overridingMethod.
subSubclass addMethod: otherOverridingMethod.

FamixJavaInheritance new
superclass: i;
subclass: i2.
FamixJavaImplementation new
interface: i2;
implementingClass: subclass.

FamixJavaInheritance new
superclass: subclass;
subclass: subSubclass.

self assertCollection: method overridingMethods hasSameElements: {
overridingMethod.
otherOverridingMethod }
]

{ #category : #tests }
FamixJavaMethodTest >> testDefaultIsStub [
self deny: method isStub
Expand Down Expand Up @@ -272,6 +340,58 @@ FamixJavaMethodTest >> testOverridingMethods [
hasSameElements: { overridingMethod }
]

{ #category : #tests }
FamixJavaMethodTest >> testOverridingMethodsInInterface [

| signature overridingMethod i c |
signature := 'javaMethod()'.
method signature: signature.
overridingMethod := FamixJavaMethod new signature: signature.

i := FamixJavaInterface new.
c := FamixJavaClass new.

i addMethod: method.
c addMethod: overridingMethod.

FamixJavaImplementation new
interface: i;
implementingClass: c.

self
assertCollection: method overridingMethods
hasSameElements: { overridingMethod }
]

{ #category : #tests }
FamixJavaMethodTest >> testOverridingMethodsInterfaceExtendsInterface [

| signature overridingMethod i i2 overridingMethod2 i3 |
signature := 'javaMethod()'.
method signature: signature.
overridingMethod := FamixJavaMethod new signature: signature.
overridingMethod2 := FamixJavaMethod new signature: signature.

i := FamixJavaInterface new.
i2 := FamixJavaInterface new.
i3 := FamixJavaInterface new.
i addMethod: method.
i2 addMethod: overridingMethod.
i3 addMethod: overridingMethod2.

FamixJavaInheritance new
superclass: i;
subclass: i2.

FamixJavaInheritance new
superclass: i2;
subclass: i3.

self assertCollection: method overridingMethods hasSameElements: {
overridingMethod.
overridingMethod2 }
]

{ #category : #tests }
FamixJavaMethodTest >> testSettingIsStub [
method isStub: true.
Expand Down
Loading