Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Operation should return a Collection but just returns Class (Code Generation)
Operation should return a Collection but just returns Class (Code Generation) [message #1749726] Sat, 10 December 2016 09:47 Go to next message
Hannes Kuchen is currently offline Hannes KuchenFriend
Messages: 9
Registered: December 2016
Junior Member
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 #1749811 is a reply to message #1749726] Mon, 12 December 2016 16:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6851
Registered: July 2009
Senior Member
Hi

Specify an upperbound that is larger than 1.

Regards

Ed Willink
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1749965 is a reply to message #1749811] Wed, 14 December 2016 14:03 Go to previous messageGo to next message
Hannes Kuchen is currently offline Hannes KuchenFriend
Messages: 9
Registered: December 2016
Junior Member
Sadly I do not know where to set the upperbound I just used multiplicities. If you are refering to something else could you describe, where to find that property.
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1749973 is a reply to message #1749965] Wed, 14 December 2016 14:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6851
Registered: July 2009
Senior Member
Hi

[Sorry, I missed that you hd already mentioned multiplicity in your original comment.]

You or the tooling are clearly doing something wrong. Without a repro we can only guess.

Regards

Ed Willink
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1750035 is a reply to message #1749973] Thu, 15 December 2016 11:32 Go to previous messageGo to next message
Hannes Kuchen is currently offline Hannes KuchenFriend
Messages: 9
Registered: December 2016
Junior Member
I created a simple examble project.

The createModels() operation should return a Collection or List or something similar of Models.

To do that I set the multiplicity to 0...*

When generating code the method just looks like:

Model createModels() {
}
Re: Operation should return a Collection but just returns Class (Code Generation) [message #1750047 is a reply to message #1750035] Thu, 15 December 2016 12:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6851
Registered: July 2009
Senior Member
Hi

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.

If I strip the redundant profile, and just do UML2Ecore, the Ecore file has correct collection multiplicities. Generating the Model gives:

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<Model> createModels() {
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new UnsupportedOperationException();
}

I see no problem with the information you have so far provided.

Regards

Ed Willink
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 Go to previous messageGo to next message
Hannes Kuchen is currently offline Hannes KuchenFriend
Messages: 9
Registered: December 2016
Junior Member
Ed Willink wrote on Thu, 15 December 2016 12:54
Hi

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 #1750113 is a reply to message #1750079] Fri, 16 December 2016 09:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6851
Registered: July 2009
Senior Member
Hi

I've just installed Papyrus 3.0.0M4 and cannot find any form of code generation. Certainly no "Designer" capability.

If you want to understand the basic UML2 project facilities, I suggest that you follow a UML2 and EMF tutorials. But you really shouldn't need to. Papyrus should offer all the facilities you need.

Since this is the Papyrus newsgroup, perhaps someone familiar with working within rather than behind Papyrus can help you better.

Regards

Ed Willink
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 Go to previous message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 246
Registered: March 2011
Location: Paris Saclay, France
Senior Member
-
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.
Previous Topic:Papyrus Designer update website certification error
Next Topic:Create node at droplocation
Goto Forum:
  


Current Time: Mon Sep 28 16:34:07 GMT 2020

Powered by FUDForum. Page generated in 0.02289 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top