|
Re: ClassifierId across different but related models [message #1697274 is a reply to message #1697261] |
Tue, 02 June 2015 21:10 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ernesto,
You'd need an if/else first on the package(s) involved. Of course
classifier IDs are unique only within a given package.
On 02/06/2015 9:42 PM, Ernesto Posse wrote:
> I have two models, M1 and M2, where M2 imports some elements from M1,
> and I want to do a simple switch (not a visitor) over some elements
> from M1 and M2. For example, M1 has elements E1 and E2 where E2 has E1
> as super-type, and M2 has element E3 which also has E1 as super-type.
>
> I would like to do
>
>
> void f(E1 element)
> {
> switch (element.eClass.getClassifierId())
> {
> case M1Package.E2:
> // do something with E2 element
> break;
> case M2Package.E3: // do something with E2 element
> break;
> }
> }
>
>
> The problem is that in the generated code, the classifierId for
> M1Package.E2 and M2Package.E3 is the same, resulting in a duplicate case.
>
> How can I make such switch in such a way that it is efficient?
>
> Thanks.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: ClassifierId across different but related models [message #1697282 is a reply to message #1697276] |
Tue, 02 June 2015 21:57 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ernesto,
You can test c.ePackage() == MPackage1Package.eINSTANCE first and then
switch on the classifiers of that package. You can of course also test
c == M1Package.Literals.E1 as well. Of course good old fashioned
instanceof tests work as well. You can also look and how an
ComposedAdapterFactory works too. It's not clear your goal. Elegance of
expression? Performance?
On 02/06/2015 11:24 PM, Ernesto Posse wrote:
> Thanks Ed.
>
> So the only way is something as follows?
>
>
> static String f(E1 element)
> {
> EClass c = element.eClass();
> if (c == M1Factory.eINSTANCE.getM1Package().getE1())
> return "E1";
> else if (c == M1Factory.eINSTANCE.getM1Package().getE2())
> return "E2";
> else if (c == M2Factory.eINSTANCE.getM2Package().getE3())
> return "E3";
> return "None";
> }
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02871 seconds