Skip to main content



      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] Wed, 12 October 2011 20:59 Go to next message
Eclipse UserFriend
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 12:48 Go to previous message
Eclipse UserFriend
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 Jul 04 11:23:36 EDT 2025

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

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

Back to the top