Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ecore for operation returning EList<? extends XXX>
ecore for operation returning EList<? extends XXX> [message #431478] Sun, 12 July 2009 21:32 Go to next message
gary s thompson is currently offline gary s thompsonFriend
Messages: 83
Registered: July 2009
Member
Hi

Can some one provide me with some ecore xml which gives an example of
how have an operation that returns a list of type EList<? extends T>.

That is of course assuming that you are allowed covariant array return
types.


regards
gary
Re: ecore for operation returning EList<? extends XXX> [message #431479 is a reply to message #431478] Mon, 13 July 2009 04:53 Go to previous messageGo to next message
Chris Graham is currently offline Chris GrahamFriend
Messages: 4
Registered: July 2009
Junior Member
Hello,

I've been trying unsuccessfully to do something like this with Topcased
and although I don't have a solution I thought I might just post what I've
tried already.

What I've done is create a Generic class using the following Topcased
modelling elements:

- <Class> CustomList
|
- <Redefinable Template Signature>
|
- <Classifier Template Parameter> M
|
- <Class> M

This creates the following java code:

public class CustomList<M> extends EObjectImpl implements EObject {

(you can ignore the 'extends EObjectImpl implements EObject' bit - that is
automatically generated by EMF).

Now comes that bit that's similar to your problem Gary - what I want to do
is declare a property with type 'CustomList<ListObject>'. To do this I
created the following Topcased model elements:

- <Class> TestClass
|
- <Property> myProperty : InnerTestClass
- <<eClass>><Class>InnerTestClass

Where InnerTestClass was created by right clicking on the TestClass and
selecting Create Child -> Nested Classifier -> Class.

Also InnerTestClass uses an ECore::EClass stereotype and sets the
'Instance Class Name' property of the stereotype to
'CustomList<ListObject>' (it's just a string input). This created the
following java code in TestClass:

public CustomList<ListObject> myProperty;

Which looks just like I want but the trouble is the ListObject class isn't
imported into the TestClass, i.e. TestClass is missing the line:

import package.ListObject;

Which of course creates a compiler error. That can be fixed by just adding
a dummy ListObject property to TestClass but that is dodgy and I don't
want to do that.

I have tried various techniques described in the article
" http://www.eclipse.org/articles/article.php?file=Article-Def ining-Generics-with-UML-Templates/index.html",
i.e. using eGenericType, template bindings and template parameter
substitutions, etc but can't get anything to work the way I want it too.

So my question is how can i create a property that returns the type
'CustomList<ListObject>' AND automatically generate the import statement
'import package.ListObject'?

-- Chris Graham
Re: ecore for operation returning EList<? extends XXX> [message #431488 is a reply to message #431478] Mon, 13 July 2009 13:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30686
Registered: July 2009
Senior Member
Gary,

I modified Ecore.ecore EObject's operation to produce this.

<eOperations name="eCrossReferences">
<eGenericType eClassifier="#//EEList">
<eTypeArguments>
<eUpperBound eTypeParameter="#//EObject/eCrossReferences/T"/>
</eTypeArguments>
</eGenericType>
<eTypeParameters name="T"/>
</eOperations>

gary thompson wrote:
> Hi
>
> Can some one provide me with some ecore xml which gives an example of
> how have an operation that returns a list of type EList<? extends T>.
>
> That is of course assuming that you are allowed covariant array return
> types.
>
>
> regards
> gary
Re: ecore for operation returning EList<? extends XXX> [message #431489 is a reply to message #431479] Mon, 13 July 2009 13:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30686
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080901040609090907080608
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Chris,

Comments below.

Chris Graham wrote:
> Hello,
>
> I've been trying unsuccessfully to do something like this with
> Topcased and although I don't have a solution I thought I might just
> post what I've tried already.
>
> What I've done is create a Generic class using the following Topcased
> modelling elements:
>
> - <Class> CustomList
> |
> - <Redefinable Template Signature>
> |
> - <Classifier Template Parameter> M
> |
> - <Class> M
Hmmm. Did you read the UML2 article about how to model Ecore/Java style
generics:

http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Defin ing_Generics_with_UML_Templates/article.html

>
> This creates the following java code:
>
> public class CustomList<M> extends EObjectImpl implements EObject {
No good will come if this...
>
> (you can ignore the 'extends EObjectImpl implements EObject' bit -
> that is automatically generated by EMF).
>
> Now comes that bit that's similar to your problem Gary - what I want
> to do is declare a property with type 'CustomList<ListObject>'. To do
> this I created the following Topcased model elements:
>
> - <Class> TestClass
> |
> - <Property> myProperty : InnerTestClass
> - <<eClass>><Class>InnerTestClass
>
> Where InnerTestClass was created by right clicking on the TestClass
> and selecting Create Child -> Nested Classifier -> Class.
>
> Also InnerTestClass uses an ECore::EClass stereotype and sets the
> 'Instance Class Name' property of the stereotype to
> 'CustomList<ListObject>' (it's just a string input). This created the
> following java code in TestClass:
>
> public CustomList<ListObject> myProperty;
>
> Which looks just like I want but the trouble is the ListObject class
> isn't imported into the TestClass, i.e. TestClass is missing the line:
>
> import package.ListObject;
>
> Which of course creates a compiler error. That can be fixed by just
> adding a dummy ListObject property to TestClass but that is dodgy and
> I don't want to do that.
>
> I have tried various techniques described in the article
> " http://www.eclipse.org/articles/article.php?file=Article-Def ining-Generics-with-UML-Templates/index.html",
> i.e. using eGenericType, template bindings and template parameter
> substitutions, etc but can't get anything to work the way I want it too.
I guess you did read it then. Another approach you might try is define
it directly in Ecore and then export to UML to see how it should be
represented...
>
> So my question is how can i create a property that returns the type
> 'CustomList<ListObject>' AND automatically generate the import
> statement 'import package.ListObject'?
My problem is I can't say much of anything about what's happening in
UML. Certainly this isn't difficult with Ecore. You'd defined a
CustomList EDataType, not unliked EEList, and you'd defined a ListObject
EDataType. Then you could use them to define EAttributes.
>
> -- Chris Graham
>

--------------080901040609090907080608
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Chris,<br>
<br>
Comments below.<br>
<br>
Chris Graham wrote:
<blockquote
cite="mid:980b6297594c07a0d1fd71f53a210709$1@www.eclipse.org"
type="cite">Hello,
<br>
<br>
I've been trying unsuccessfully to do something like this with Topcased
and although I don't have a solution I thought I might just post what
I've tried already.
<br>
<br>
What I've done is create a Generic class using the following Topcased
modelling elements:
<br>
<br>
- &lt;Class&gt; CustomList
<br>
Re: ecore for operation returning EList<? extends XXX> [message #431495 is a reply to message #431488] Mon, 13 July 2009 21:26 Go to previous messageGo to next message
gary s thompson is currently offline gary s thompsonFriend
Messages: 83
Registered: July 2009
Member
Ed Merks wrote:
> Gary,
>
> I modified Ecore.ecore EObject's operation to produce this.
> <eOperations name="eCrossReferences">
> <eGenericType eClassifier="#//EEList">
> <eTypeArguments>
> <eUpperBound eTypeParameter="#//EObject/eCrossReferences/T"/>
> </eTypeArguments>
> </eGenericType>
> <eTypeParameters name="T"/>
> </eOperations>
>
> gary thompson wrote:
>> Hi
>>
>> Can some one provide me with some ecore xml which gives an example of
>> how have an operation that returns a list of type EList<? extends T>.
>>
>> That is of course assuming that you are allowed covariant array return
>> types.
>>
>>
>> regards
>> gary


Hi Ed
many thanks for the reply. This is also where I arrived at (after about
4 hour of sweating : don't the professionals make it look so easy ;-)).

It isn't the easiest thing to understand especially from the sample
ecore editor (it has too many places to put types and type references,
but thats down to the flexibility of generic I guess) or from the xml
but once its all together it looks so right.

So thanks for such a nice implementation that really works so well and
covers all the bases.


regards
gary
Re: ecore for operation returning EList<? extends XXX> [message #431551 is a reply to message #431489] Thu, 16 July 2009 07:18 Go to previous message
Chris Graham is currently offline Chris GrahamFriend
Messages: 4
Registered: July 2009
Junior Member
Hello Ed,

Thanks so much for your comments - as you suggested I ended up defining it
in Ecore and then exporting to UML which showed me where I was going wrong
- in the article:


http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Defin ing_Generics_with_UML_Templates/article.html

The '<<eReference>> <Property> myCars : ArrayList_Car [0..*]' property
described half way down the article is actually one half of an association
between the ArrayList class and the ArrayList_Car GenericType class. I was
just modelling it as a property without the association which didn't work
at all.

-- Chris Graham
Previous Topic:[CDO] acquire a lock could notify others ?
Next Topic:[CDO] Derby drivers
Goto Forum:
  


Current Time: Mon Dec 09 01:58:20 GMT 2019

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

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

Back to the top