How to create a method with a generic collection type [message #735880] |
Thu, 13 October 2011 00:59 |
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 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 |
Ed Willink Messages: 7670 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?
|
|
|
Powered by
FUDForum. Page generated in 0.05879 seconds