Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 436459

Summary: ForTask problem if expression uses an array
Product: [Modeling] Sirius Reporter: Laurent Redor <laurent.redor>
Component: CoreAssignee: Maxime Porhel <maxime.porhel>
Status: CLOSED FIXED QA Contact: Julien Dupont <julien.dupont>
Severity: major    
Priority: P3 CC: julien.dupont, maxime.porhel
Version: 0.9Keywords: triaged
Target Milestone: 2.0.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Project ForTaskWithArray.design
none
Project ForTaskWithArray.sample
none
ForTaskWithArray.sample (and not the design project twice)
none
Sample none

Description Laurent Redor CLA 2014-06-03 09:55:37 EDT
Created attachment 243884 [details]
Project ForTaskWithArray.design

If the expression of a ForTask is an array, returned by the service interpreter or the variable interpreter, this task iterates only on one element (the array itself) and not on each element of the array.

Steps to reproduce:
* Import the project "ForTaskWithArray.design" in a workspace
* Launch a runtime
* Import the project "ForTaskWithArray.sample" in the runtime-workspace
* Open the diagram "new Diag"
* Use the tool "Duplicates classes with array with service" on p1 package, nothing happens (KO)
* Use the tool "Duplicates classes with array with variable" on p1 package, nothing happens (KO)
* Use the tool "Duplicates classes with list with service" on p1 package, the 3 classes are duplicated as expected. The behavior for the first tools should be the same.

In this use case, the difference between the 3 tools is that:
* the first iterates on an array (returned by the service org.eclipse.sirius.sample.fortaskwitharray.Services.getEClassesAsArray(EPackage))
* the second iterates on an array (returned by a variable)
* and the third iterates on a list (returned by the service org.eclipse.sirius.sample.fortaskwitharray.Services.getEClassesAsList(EPackage))

In ForTask, an array should be considered as list.
Comment 1 Laurent Redor CLA 2014-06-03 09:56:23 EDT
Created attachment 243885 [details]
Project ForTaskWithArray.sample
Comment 2 Maxime Porhel CLA 2014-07-28 05:11:09 EDT
Laurent, it seems you uploaded the same design project twice.
Comment 3 Laurent Redor CLA 2014-07-28 05:23:45 EDT
Created attachment 245426 [details]
ForTaskWithArray.sample (and not the design project twice)
Comment 4 Maxime Porhel CLA 2014-07-28 05:24:28 EDT
Created attachment 245427 [details]
Sample
Comment 5 Maxime Porhel CLA 2014-07-28 05:25:10 EDT
Thank you Laurent.
Comment 6 Maxime Porhel CLA 2014-07-28 08:21:56 EDT
See https://git.eclipse.org/r/30583, which propose a draft which enables ForTask  to iterate over arrays. 

But I think here the real issue is thaht we should call evaluateCollection instead of evaluate and then each IInterpreters should be able to handle arrays in its evaluateCollectionMethod.
Comment 7 Maxime Porhel CLA 2014-08-07 04:53:12 EDT
The current behavior allows to iterate on the for taks over non EObject elements, in this case, the evaluation context is still the element on which the for expression has been evaluated.

so we should correct handle the array case here but continue to call evaluate and not evalauteCollection which returns a collection of EObject and will remove the possibility to iterate over non EObject elements. However, handling the array case in the evaluateCollection method seems a good idea, it could be done in a separate commit/step on this bug.
Comment 8 Maxime Porhel CLA 2014-08-08 10:20:41 EDT
See
 . https://git.eclipse.org/r/#/c/30583/ which corrects the ForTask
 . https://git.eclipse.org/r/#/c/31171/ which handled arrays in our interpreters evaluateCollection methods.
Comment 9 Maxime Porhel CLA 2014-08-18 10:02:22 EDT
Corrected by commits
 . 389b9ddb366b77f1f05910d9dd33d50ecd43771d
 . 008bc96206e8afd5ad65cf0820cae88709c7be26
 . 7b7c8e2882cf16424e1694f51965dc49acc0f8e4
Comment 10 Pierre-Charles David CLA 2014-10-27 06:52:31 EDT
Available in Sirius 2.0.0.