Skip to content

Commit

Permalink
Merge pull request #1240 from moosetechnology/dsm-non-association-dep…
Browse files Browse the repository at this point in the history
…endencies

Dsm non association dependencies
  • Loading branch information
NicolasAnquetil authored Nov 17, 2024
2 parents b1d5baf + 3b709fc commit 4374097
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/MooseIDE-Dependency/FamixTClass.extension.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Extension { #name : #FamixTClass }

{ #category : #'*MooseIDE-Dependency' }
FamixTClass >> addDeclaredTypesIn: dependencies [
FamixTClass >> addNonAssociationDependenciesTo: dependencies [

self children do: [ :c | c addDeclaredTypesIn: dependencies ].
self children do: [ :c | c addNonAssociationDependenciesTo: dependencies ].

]
18 changes: 15 additions & 3 deletions src/MooseIDE-Dependency/FamixTMethod.extension.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
Extension { #name : #FamixTMethod }

{ #category : #'*MooseIDE-Dependency' }
FamixTMethod >> addDeclaredTypesIn: dependencies [
FamixTMethod >> addNonAssociationDependenciesTo: dependencies [

self children do: [ :c | c addDeclaredTypesIn: dependencies ].
self declaredType ifNotNil: [ dependencies add: self declaredType ]
self children do: [ :c | c addNonAssociationDependenciesTo: dependencies ].

declaredType ifNotNil: [
dependencies add: declaredType.

( (declaredType usesFamixTrait: FamixTParametricEntity) and:
[ declaredType genericization isNotNil ])
ifTrue: [
declaredType concreteParameters do: [ :param |
param children ifNotEmpty: [ dependencies add: param ]
]
]

]
]
4 changes: 2 additions & 2 deletions src/MooseIDE-Dependency/FamixTPackage.extension.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Extension { #name : #FamixTPackage }

{ #category : #'*MooseIDE-Dependency' }
FamixTPackage >> addDeclaredTypesIn: dependencies [
FamixTPackage >> addNonAssociationDependenciesTo: dependencies [

self children do: [ :c | c addDeclaredTypesIn: dependencies ].
self children do: [ :c | c addNonAssociationDependenciesTo: dependencies ].
]
18 changes: 16 additions & 2 deletions src/MooseIDE-Dependency/FamixTTypedEntity.extension.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
Extension { #name : #FamixTTypedEntity }

{ #category : #'*MooseIDE-Dependency' }
FamixTTypedEntity >> addDeclaredTypesIn: dependencies [
FamixTTypedEntity >> addNonAssociationDependenciesTo: dependencies [
"if declaredType is a Concretization of a ParametricEntity, then must look at its concreteParameters
if they are actual classes (not GenericParameterType), then add them as dependencies
This is check through an heuristic: if they have some children, then it must be an actual class"

self declaredType ifNotNil: [dependencies add: self declaredType]
declaredType ifNotNil: [
dependencies add: declaredType.

( (declaredType usesFamixTrait: FamixTParametricEntity) and:
[ declaredType genericization isNotNil ])
ifTrue: [
declaredType concreteParameters do: [ :param |
param children ifNotEmpty: [ dependencies add: param ]
]
]

]
]
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ MiDependencyStructuralMatrixBrowserModel >> getDependenciesFrom: entityX to: ent
]
]
ifFalse: [
"case of declaredType"
"case of dependencies not coming from an association"
dependency isStub
ifTrue: [ false ]
ifFalse: [ self entity: dependency belongsTo: entityY ]
Expand Down
4 changes: 2 additions & 2 deletions src/MooseIDE-Dependency/MooseEntity.extension.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Extension { #name : #MooseEntity }

{ #category : #'*MooseIDE-Dependency' }
MooseEntity >> addDeclaredTypesIn: dependencies [
"default is to do nothing (no declaredType to add)"
MooseEntity >> addNonAssociationDependenciesTo: dependencies [
"default is to do nothing (no extra dependencies to add)"
]

{ #category : #'*MooseIDE-Dependency' }
Expand Down
10 changes: 4 additions & 6 deletions src/MooseIDE-Dependency/TEntityMetaLevelDependency.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ TEntityMetaLevelDependency >> miTreeExtension [
{ #category : #'*MooseIDE-Dependency' }
TEntityMetaLevelDependency >> queryAllOutgoingForDSM [
"Query all the outgoing associations of the receiver and its children.
Example:
aFAMIXClass queryAllOutgoing.
--> Will return a MooseOutgoingQueryResult containing the FAMIXAssociation having aFAMIXClass or its children as source
"
This is a special implementation that catches more dependencies.
For example it gets the declaredType of variables.
This is temporary until we resolve the issue of declaredType not being an Association"

| dependencies |
dependencies := self queryAllOutgoing.
self addDeclaredTypesIn: dependencies.
self addNonAssociationDependenciesTo: dependencies.
^ dependencies
]

Expand Down
132 changes: 117 additions & 15 deletions src/MooseIDE-Tests/MiDependencyStructuralMatrixBrowserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MiDependencyStructuralMatrixBrowserTest >> defaultEntityToSelect [
^{ FamixStClass new name: 'a'. FamixStClass new name: 'b' }
]

{ #category : #'tests - tags' }
{ #category : #running }
MiDependencyStructuralMatrixBrowserTest >> makeGraphNode: anEntity [

^AIGraphNode new
Expand All @@ -34,11 +34,12 @@ MiDependencyStructuralMatrixBrowserTest >> setUp [
| mth1 mth2 |

super setUp.

model := FamixStModel new.
class1 := model newClassNamed: 'class1'.
class2 := model newClassNamed: 'class2'.
class3 := model newClassNamed: 'class3'.

"Note: need to be a Java model to test ParametricEntities"
model := FamixJavaModel new.
class1 := model newClassNamed: 'Class1'.
class2 := model newClassNamed: 'Class2'.
class3 := model newClassNamed: 'Class3'.

mth1 := (model newMethodNamed: 'mth1') parentType: class1.
mth2 := (model newMethodNamed: 'mth2') parentType: class2.
Expand All @@ -48,7 +49,7 @@ MiDependencyStructuralMatrixBrowserTest >> setUp [

]

{ #category : #'tests - tags' }
{ #category : #running }
MiDependencyStructuralMatrixBrowserTest >> shapeAtRow: rEntity column: cEntity2 [

^browser diagram canvas shapes detect: [ :sh |
Expand All @@ -57,13 +58,13 @@ MiDependencyStructuralMatrixBrowserTest >> shapeAtRow: rEntity column: cEntity2
]
]

{ #category : #'tests - tags' }
{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testCanTagEntities [

self deny: browser canTagEntities
]

{ #category : #'tests - tags' }
{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testDoesNotOpenEmptyDetailedDSM [
"sets a fake spec model that delegates #userActionOn: to the original model
We checks that #userActionOn: was called and #openDetailedDSMOn: was not"
Expand All @@ -90,7 +91,7 @@ MiDependencyStructuralMatrixBrowserTest >> testDoesNotOpenEmptyDetailedDSM [
self assert: detailedDSM isNil
]

{ #category : #'tests - tags' }
{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testDoubleClickCallsUserAction [
"sets a fake spec model on the visualization to check that #userAction: is called
with the right tuple when double clicking on a square"
Expand All @@ -111,19 +112,120 @@ MiDependencyStructuralMatrixBrowserTest >> testDoubleClickCallsUserAction [
self assert: detailedDSM value model equals: class2.
]

{ #category : #'tests - tags' }
{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testOutgoingDependencyFromInvocation [

| dependencies |
dependencies := class1 methods anyOne queryAllOutgoingForDSM.

self assert: dependencies size equals: 1.
self assert: dependencies anyOne class equals: FamixJavaInvocation.
self assert: dependencies anyOne candidates anyOne name equals: 'mth2'.

]

{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testOutgoingDependencyFromMethodDeclaredType [

| mth2 dependencies |
mth2 := class2 methods anyOne.
mth2 declaredType: class3.

dependencies := mth2 queryAllOutgoingForDSM.

self assert: dependencies size equals: 1.
self assert: dependencies anyOne class equals: FamixJavaClass.
self assert: dependencies anyOne name equals: 'Class3'.

]

{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testOutgoingDependencyFromVMethodDeclaredTypeParametric [
"code:
Class2
ParametricClass<Class1> mth2
Note: FamixJavaConcretization is an association and we are not interested in its genericEntity here
Note: hueristic to detect a concreteParameter being a genuine class is to check it has children
That's why we use Class1 and not Class3 as concreteParameter"

| mth2 parametricClass dependencies |
parametricClass := model newParametricClass
name: 'ParametricClass' ;
genericization: model newConcretization ;
addConcreteParameter: class1 ;
yourself.

mth2 := class2 methods anyOne.
mth2 declaredType: parametricClass.

dependencies := mth2 queryAllOutgoingForDSM.

self assert: dependencies size equals: 2.
dependencies do: [ :dep |
{ 'ParametricClass' . 'Class1' } includes: dep name
]
]

{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testOutgoingDependencyFromVariableDeclaredType [

| mth2 dependencies |
mth2 := class2 methods anyOne.
(model newLocalVariableNamed: 'local2')
parentBehaviouralEntity: mth2 ;
declaredType: class3.

dependencies := mth2 queryAllOutgoingForDSM.

self assert: dependencies size equals: 1.
self assert: dependencies anyOne class equals: FamixJavaClass.
self assert: dependencies anyOne name equals: 'Class3'.

]

{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testOutgoingDependencyFromVariableDeclaredTypeParametric [
"code:
Class2
mth2
ParametricClass<Class1> local2
Note: FamixJavaConcretization is an association and we are not interested in its genericEntity here
Note: hueristic to detect a concreteParameter being a genuine class is to check it has children
That's why we use Class1 and not Class3 as concreteParameter"

| mth2 parametricClass dependencies |
parametricClass := model newParametricClass
name: 'ParametricClass' ;
genericization: model newConcretization ;
addConcreteParameter: class1 ;
yourself.

mth2 := class2 methods anyOne.
(model newLocalVariableNamed: 'local2')
parentBehaviouralEntity: mth2 ;
declaredType: parametricClass.

dependencies := mth2 queryAllOutgoingForDSM.

self assert: dependencies size equals: 2.
dependencies do: [ :dep |
{ 'ParametricClass' . 'Class1' } includes: dep name
]
]

{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testTitleOfDSM [

browser followEntity: { class1 . class2 }.

browser withWindowDo: [ : window |
self assert: (window title beginsWith: 'Dependency Structural Matrix ').
self assert: (window title includesSubstring: 'class1').
self assert: (window title includesSubstring: 'class2')
self assert: (window title includesSubstring: 'Class1').
self assert: (window title includesSubstring: 'Class2')
]
]

{ #category : #'tests - tags' }
{ #category : #tests }
MiDependencyStructuralMatrixBrowserTest >> testTitleOfDetailedDSM [
"detailed DSM title should show the original entities"
| detailedDSM |
Expand All @@ -136,6 +238,6 @@ MiDependencyStructuralMatrixBrowserTest >> testTitleOfDetailedDSM [
detailedDSM withWindowDo: [ : window || title |
title := window title.
window close.
self assert: title equals: 'DSM class1 -> class2'
self assert: title equals: 'DSM Class1 -> Class2'
]
]

0 comments on commit 4374097

Please sign in to comment.