Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to create a method with a generic collection type
How to create a method with a generic collection type [message #735880] Thu, 13 October 2011 00:59 Go to next message
Behrang Saeedzadeh is currently offline Behrang Saeedzadeh
Messages: 11
Registered: July 2009
Location: Melbourne, Australia
Junior Member
Hi,

I want to programmatically create the UML model for the following classes:

public class Foo {
}


public class Bar {
 public java.util.List<Foo> getFoos() {
 }
}


Ideally, I want a diagram that contains only two classes Foo and Bar (and no java.util.List) in which getFoos() returns java.util.List<Foo>. However what I have right now, creates two classes Foo and List<Foo>. The relevant part in which I create the getFoos() method is shown below:

Package package = ...;
BasicEList paramNames = ...;
BasicEList paramTypes = ...;

String methodName = "getFoos";
String returnTypeStr = "java.util.List<Foo>";

Class returnType = package.create_owned_class(returnTypeStr, false);
Operation op = barClass.createOwnedOperation(methodName, paramNames, paramTypes, returnType);


As it can be seen, the problem with the code above is that I need to pass a returnType to createOwnedOperation and the only way I know of how to create that type is to create a class named List<Foo> which is not what I need. In reality, there are only three classes: List, Foo, and Bar.

How's it possible to accomplish this?
Re: How to create a method with a generic collection type [message #736142 is a reply to message #735880] Thu, 13 October 2011 16:48 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4115
Registered: July 2009
Senior Member
Hi

Use the UML Model Editor or Papyrus to create some small models and see
what they generate, then you can hand code the same thing.

Regards

Ed Willink

On 13/10/2011 01:59, Behrang Saeedzadeh wrote:
> Hi,
>
> I want to programmatically create the UML model for the following
> classes:
>
> public class Foo {
> }
>
> public class Bar {
> public java.util.List<Foo> getFoos() {
> }
> }
>
> Ideally, I want a diagram that contains only two classes Foo and Bar
> (and no java.util.List) in which getFoos() returns
> java.util.List<Foo>. However what I have right now, creates two
> classes Foo and List<Foo>. The relevant part in which I create the
> getFoos() method is shown below:
>
> Package package = ...;
> BasicEList paramNames = ...;
> BasicEList paramTypes = ...;
>
> String methodName = "getFoos";
> String returnTypeStr = "java.util.List<Foo>";
>
> Class returnType = package.create_owned_class(returnTypeStr, false);
> Operation op = barClass.createOwnedOperation(methodName, paramNames,
> paramTypes, returnType);
>
> As it can be seen, the problem with the code above is that I need to
> pass a returnType to createOwnedOperation and the only way I know of
> how to create that type is to create a class named List<Foo> which is
> not what I need. In reality, there are only three classes: List, Foo,
> and Bar.
>
> How's it possible to accomplish this?
Previous Topic:LiteralUnlimitedNatural.UNLIMITED
Next Topic:Tutorial for creating UML programmatically
Goto Forum:
  


Current Time: Fri Oct 31 20:50:42 GMT 2014

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

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