From a3316bee0ee8c72fcaa8b4e2ba5c5e3b809cd870 Mon Sep 17 00:00:00 2001 From: Clotilde Date: Tue, 7 Sep 2021 16:21:33 +0200 Subject: [PATCH] MooseQuery: flatten the result when querying the opposites in navigation queries. Corrected test accordingly --- src/Moose-Query-Test/MooseQueryTest.class.st | 17 ++++++++++++----- ...NavigationIncomingDirectionStrategy.class.st | 4 ++-- .../MQNavigationOppositeKindStrategy.class.st | 9 ++++++++- ...NavigationOutgoingDirectionStrategy.class.st | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Moose-Query-Test/MooseQueryTest.class.st b/src/Moose-Query-Test/MooseQueryTest.class.st index 36ee88731..d301a1029 100644 --- a/src/Moose-Query-Test/MooseQueryTest.class.st +++ b/src/Moose-Query-Test/MooseQueryTest.class.st @@ -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 } diff --git a/src/Moose-Query/MQNavigationIncomingDirectionStrategy.class.st b/src/Moose-Query/MQNavigationIncomingDirectionStrategy.class.st index 0dd46731d..236e9024b 100644 --- a/src/Moose-Query/MQNavigationIncomingDirectionStrategy.class.st +++ b/src/Moose-Query/MQNavigationIncomingDirectionStrategy.class.st @@ -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 } diff --git a/src/Moose-Query/MQNavigationOppositeKindStrategy.class.st b/src/Moose-Query/MQNavigationOppositeKindStrategy.class.st index 1ca0b41dd..d4b63820e 100644 --- a/src/Moose-Query/MQNavigationOppositeKindStrategy.class.st +++ b/src/Moose-Query/MQNavigationOppositeKindStrategy.class.st @@ -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 } diff --git a/src/Moose-Query/MQNavigationOutgoingDirectionStrategy.class.st b/src/Moose-Query/MQNavigationOutgoingDirectionStrategy.class.st index ce21e2fc2..92a9dc104 100644 --- a/src/Moose-Query/MQNavigationOutgoingDirectionStrategy.class.st +++ b/src/Moose-Query/MQNavigationOutgoingDirectionStrategy.class.st @@ -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 }