Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Generic valueType for EMap
Generic valueType for EMap [message #1004758] Wed, 23 January 2013 20:19 Go to next message
Jason Roberts is currently offline Jason RobertsFriend
Messages: 5
Registered: February 2012
Junior Member
I have created an model class, Expression<T>, that I would like to use as the valueType for a map feature in another EClass.

    /**
     * @model keyType="java.lang.String" valueType="com.example.expression.Expression" containment="true"
     */
    public EMap<String, Expression<Boolean>> getBooleanParameters();


When I generate the model, the method signature is changed to:
public EMap<String, Expression> getBooleanParameters();


Does EMF support specifying a generic type for a map valueType?


Re: Generic valueType for EMap [message #1004911 is a reply to message #1004758] Thu, 24 January 2013 05:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Jason,

In Xcore you'd express that like this:

package com.example.expression

class Expression<T>
{
}

class StringToBooleanExpressionMapEntry wraps java.util.Map$Entry
{
String key
refers Expression<Boolean> value
}

class AnotherClass
{
contains StringToBooleanExpressionMapEntry[] booleanParameters
}

It generates this:

/*...
* @model
mapType="com.example.expression.StringToBooleanExpressionMapEntry<org.eclipse.emf.ecore.EString,
com.example.expression.Expression<org.eclipse.emf.ecore.EBooleanObject>>"
* @generated
*/
EMap<String, Expression<Boolean>> getBooleanParameters();

The information about map's type is determined from this in the
generated package.

* @model keyUnique="false" keyDataType="org.eclipse.emf.ecore.EString"
*
valueType="com.example.expression.Expression<org.eclipse.emf.ecore.EBooleanObject>"
* @generated
*/
EClass getStringToBooleanExpressionMapEntry();


It's very tricky to get the annotations correct, so while it's
definitely possible, there's nothing in the way of error feedback when
you make typos. In Xcore, if you do something wrong, it will tell you
immediately in the editor.


On 23/01/2013 9:19 PM, Jason Roberts wrote:
> I have created an model class, Expression<T>, that I would like to use
> as the valueType for a map feature in another EClass.
>
>
> /**
> * @model keyType="java.lang.String"
> valueType="com.example.expression.Expression" containment="true"
> */
> public EMap<String, Expression<Boolean>> getBooleanParameters();
>
>
> When I generate the model, the method signature is changed to:
>
> public EMap<String, Expression> getBooleanParameters();
>
>
> Does EMF support specifying a generic type for a map valueType?
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generic valueType for EMap [message #1005188 is a reply to message #1004911] Thu, 24 January 2013 15:57 Go to previous messageGo to next message
Jason Roberts is currently offline Jason RobertsFriend
Messages: 5
Registered: February 2012
Junior Member
Ed,

It appears that this cannot be done purely with annotated java? If I understand your response correctly, I will first have to create an EClass for the map entry in the ECore editor?
Re: Generic valueType for EMap [message #1005198 is a reply to message #1005188] Thu, 24 January 2013 16:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Jason,

No, it can if you get the annotations right. It's certainly expressible
in Ecore and I did check that the model code generated from the Xcore
has @model annotations that can be used as input for creation a model
from annotated Java and I showed you what those annotations look like.

On 24/01/2013 4:57 PM, Jason Roberts wrote:
> Ed,
>
> It appears that this cannot be done purely with annotated java? If I
> understand your response correctly, I will first have to create an
> EClass for the map entry in the ECore editor?
No, but when it's a big battle to get it right with annotations, it
might be easier to do it in the Ecore editor, let EMF generate the right
annotations (be sure to delete the methods and the package interface so
EMF generates them fully), and then continue from there.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generic valueType for EMap [message #1005222 is a reply to message #1005198] Thu, 24 January 2013 17:09 Go to previous messageGo to next message
Jason Roberts is currently offline Jason RobertsFriend
Messages: 5
Registered: February 2012
Junior Member
Thanks Ed, you are the man. It works now. The mapType javadoc annotation was so long that my formatter was splitting up the lines which was causing problems when reloading the genmodel.
Re: Generic valueType for EMap [message #1404814 is a reply to message #1004911] Tue, 05 August 2014 23:50 Go to previous messageGo to next message
Jack Greenfield is currently offline Jack GreenfieldFriend
Messages: 18
Registered: June 2014
Junior Member
That's a nice feature. However, if it hadn't been for this nice forum post, I would not have known about it. Despite searching fairly carefully for documentation on Xcore, other than the wiki page, which is just a quick overview, I haven't found any. Please tell me I've just looked in the wrong places, and point me to the documentation.

Thanks.
Re: Generic valueType for EMap [message #1404886 is a reply to message #1404814] Wed, 06 August 2014 04:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Jack,

Sorry, there's no hidden documentation.

On 06/08/2014 1:50 AM, Jack Greenfield wrote:
> That's a nice feature. However, if it hadn't been for this nice forum
> post, I would not have known about it. Despite searching fairly
> carefully for documentation on Xcore, other than the wiki page, which
> is just a quick overview, I haven't found any. Please tell me I've
> just looked in the wrong places, and point me to the documentation.
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generic valueType for EMap [message #1405077 is a reply to message #1404886] Wed, 06 August 2014 14:20 Go to previous message
Jack Greenfield is currently offline Jack GreenfieldFriend
Messages: 18
Registered: June 2014
Junior Member
Thanks for fast reply, Ed. I wonder what other powerful features lie undocumented within Xcore...
Previous Topic:KM3 Specification of an Ecore Model
Next Topic:Array of references in model
Goto Forum:
  


Current Time: Fri Apr 19 11:17:14 GMT 2024

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

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

Back to the top