Operation should return a Collection but just returns Class (Code Generation) [message #1749726] |
Sat, 10 December 2016 09:47 |
Eclipse User |
|
|
|
Hi Guys,
how exactly is it possible to specify a return type of a procedure as colletion of a certain type.
One Example would be.
I have a Class Studyplan and want to get all Subjects returned.
The result I would like to get from the CodeGenerator
public Collection<Subject> getAllSubjects(){
}
But I just get (even though I changed the multiplicity of the return parameter to 0...*):
public Subject getAllSubjects(){
}
|
|
|
|
|
|
|
|
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1750079 is a reply to message #1750047] |
Thu, 15 December 2016 20:05 |
Eclipse User |
|
|
|
Ed Willink wrote on Thu, 15 December 2016 12:54Hi
Your don't explain how you generate code. I assumed that your path was UML2Ecore2Java, but as a minimum if your example is Java I would expect to see "public", so I have no idea what you are doing.
I just right-clicked on Root Element-> Designer -> Generate Java Code
Ed Willink wrote on Thu, 15 December 2016 12:54
If I strip the redundant profile, and just do UML2Ecore, the Ecore file has correct collection multiplicities. Generating the Model gives:
How do I do that?
Thanks in advance.
|
|
|
|
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1750228 is a reply to message #1750113] |
Mon, 19 December 2016 07:05 |
|
-
Hi,
@Ed: you don't see the code generation menu until you install the Papyrus SW designer extension
@Hannes
I tried the model that you attached with the current designer snapshot. I get
Model[] createModels() {
This means the "*" multiplicity results in an array. We recently fixed a bug concerning the return type, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=506293
Thus, you need to use a nightly designer build which you can get here:
https://hudson.eclipse.org/papyrus/view/Designer/job/papyrus-designer-neon-papyrusnightly/ws/releng/org.eclipse.papyrus.designer.p2/target/repository/
However, If you need to return a Collection<Model> instead of the array, you need to leave multiplicity at 1 and assign a suitable return type. There are two options>
(1) the quick&dirty one: declare a class with the name Collection<Model> and apply the PapyrusJava stereotype ""External". Thus, no code
will be generated for this class, its name will appear when other model elements reference it, Use this type as return type of the createModels method
(2) Declare a class named Collection with a template signature having a classifier template parameter T. Then create a new class, e.g. Collection<Model> or Collection_Model. Create a template-binding relationship between this class and the Collection template class. The template binding contains the appropriate parameter substitution, i.e. T->Model. Since template bindings in UML are quite tedious to use, we plan to facilitate this task by providing a wizard which automatically creates bound template classes and the template binding relationship in the future.
|
|
|
Powered by
FUDForum. Page generated in 0.04154 seconds