Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [xcore] creating an instance of Map.Entry
[xcore] creating an instance of Map.Entry [message #1478395] Tue, 18 November 2014 16:50 Go to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 20
Registered: October 2014
Junior Member
Hi all,
in my Xcore model I defined a map entry class.

class MyMapEntry wraps java.util.Map.Entry {
refers ...
refers ...
}

with the primary purpose to build a "qualified association" (EMap).

In an operation, I implement an algorithm where would now also like to manually create instances of MyMapEntry.

However,
1. MyFactory does not exhibit a "createMyMapEntry" method. So I can't create an instance that way.
2. I can't say "new MyMapEntryImpl" -- it says that the constructor is not visible.

What seems to work is the following: MyFactoryImpl has a method "createMyMapEntry". So, I can say

(MyFactory,eINSTANCE as MyFactoryImpl).createMyMapEntry

My question is now: Is there a better way?
A cleaner way would probably be to create an additional class MyMapEntry2 without "wraps java.util.Map.Entry", which I can use for my purposes in the algorithm...

Best regards

Joel
Re: [xcore] creating an instance of Map.Entry [message #1478410 is a reply to message #1478395] Tue, 18 November 2014 17:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Joel,

Comments below.

On 18/11/2014 5:50 PM, Joel Greenyer wrote:
> Hi all,
> in my Xcore model I defined a map entry class.
>
> class MyMapEntry wraps java.util.Map.Entry {
> refers ...
> refers ...
> }
>
> with the primary purpose to build a "qualified association" (EMap).
>
> In an operation, I implement an algorithm where would now also like to
> manually create instances of MyMapEntry.
That's easier said than done as you noticed. So first question is, why
do you need to create an entry directly?
>
> However,
> 1. MyFactory does not exhibit a "createMyMapEntry" method. So I can't
> create an instance that way.
No, because there is no generated API for such things.
> 2. I can't say "new MyMapEntryImpl" -- it says that the constructor is
> not visible.
Indeed.
>
> What seems to work is the following: MyFactoryImpl has a method
> "createMyMapEntry". So, I can say
>
> (MyFactory,eINSTANCE as MyFactoryImpl).createMyMapEntry
>
> My question is now: Is there a better way?
MyFactory.eINSTANCE.create(MyPackage.Literals.MY_MAP_ENTRY). You can
cast the result to org.eclipse.emf.common.util.BasicEMap.Entry<K, V>.
> A cleaner way would probably be to create an additional class
> MyMapEntry2 without "wraps java.util.Map.Entry", which I can use for
> my purposes in the algorithm...
Perhaps you can write your algorithm such that you create entries via
"put"....
>
> Best regards
>
> Joel


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Rookie Q: How get StyledCellLabelProvider from EMF.edit
Next Topic:Extend Metadata Tutorial
Goto Forum:
  


Current Time: Thu Apr 25 06:37:26 GMT 2024

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

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

Back to the top