Skip to content

Commit

Permalink
Merge pull request #352 from moosetechnology/moose-query-dev
Browse files Browse the repository at this point in the history
MooseQuery: flatten the result when querying the opposites in navigation queries.
  • Loading branch information
ClotildeToullec authored Sep 7, 2021
2 parents a388426 + a3316be commit f3374d7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/Moose-Query-Test/MooseQueryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,18 @@ MooseQueryTest >> testSourceThroughInvocation [
{ #category : #tests }
MooseQueryTest >> testTargetThroughInvocation [

self assertCollection: (method1 targetThrough: FamixTInvocation) storage flattened hasSameElements: {method2}.
self assertCollection: (method1 targetThrough: FamixTInvocation) hasSameElements: ((method1 queryOutgoing: FamixTInvocation) collect: #to).
self assertCollection: (class2 targetThrough: FamixTInvocation) storage flattened hasSameElements: {method2}.


self
assertCollection:
(method1 targetThrough: FamixTInvocation) storage flattened
hasSameElements: { method2 }.
self
assertCollection: (method1 targetThrough: FamixTInvocation)
hasSameElements:
((method1 queryOutgoing: FamixTInvocation) flatCollect: #target).
self
assertCollection:
(class2 targetThrough: FamixTInvocation) storage flattened
hasSameElements: { method2 }
]

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ MQNavigationIncomingDirectionStrategy class >> ensureAssociation: anObject with:
]

{ #category : #accessing }
MQNavigationIncomingDirectionStrategy class >> entityFor: anEntity [
^ anEntity source
MQNavigationIncomingDirectionStrategy class >> entityFor: anAssociation [
^ anAssociation source
]

{ #category : #accessing }
Expand Down
9 changes: 8 additions & 1 deletion src/Moose-Query/MQNavigationOppositeKindStrategy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ Class {

{ #category : #enumerating }
MQNavigationOppositeKindStrategy class >> collectResultFrom: aCollection query: aQuery [
^ aCollection collect: [ :each | aQuery directionStrategy entityFor: each ]

"We flat collect because some associations have multivalued targets (ex: TAssociation has #candidates) and some have only 1 target.
The mechanisms of #flatCollect: only works if all items in the collection are collections,
so we use the mechanism of #flattened while collecting."

^ Array streamContents: [ :stream |
aCollection do: [ :each |
(aQuery directionStrategy entityFor: each) flattenOn: stream ] ]
]

{ #category : #running }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ MQNavigationOutgoingDirectionStrategy class >> ensureAssociation: anObject with:
]

{ #category : #accessing }
MQNavigationOutgoingDirectionStrategy class >> entityFor: anEntity [
^ anEntity target
MQNavigationOutgoingDirectionStrategy class >> entityFor: anAssociation [
^ anAssociation target
]

{ #category : #accessing }
Expand Down

0 comments on commit f3374d7

Please sign in to comment.