[xcore] creating an instance of Map.Entry [message #1478395] |
Tue, 18 November 2014 11:50  |
Eclipse User |
|
|
|
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 12:06  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03680 seconds