Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Error when invoking a definition from Java with polymorphism
[Xpand] Error when invoking a definition from Java with polymorphism [message #559942] Mon, 20 September 2010 13:45 Go to next message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: August 2010
Location: Munich
Junior Member
Hey,

I have the following scenario: I work with 4 different versions of a meta model (MM1.ecore, MM2.ecore, MM3.ecore, MM4.ecore) and 1 general version (GMM.ecore) which should cover the common types of the 4 versions. All metamodels are defined in different files and MM1 to MM4 have references to GMM. (I didn't develop them so I am not able to change them)

GMM has types from which the other meta models inherit. So I have type A1, A2, A3 and A4 in MM1 ... MM4 which are all subtypes of type A specified in GMM. This is done via the ESuper Types property of the EClasses.

For each meta model I also have the corresponding Java classes in jar librarys (mm1.jar, mm2.jar, mm3.jar, mm4.jar, gmm.jar), so I am able to handle all these classes / types in my Java code.

Now I want to create a definition in an Xpand template for type A and invoke it in Java with e.g. type/class A1:

Xpand: file "gen.xpt"
«DEFINE main FOR A»
«ENDDEFINE»


Java:
private void generate(A1 a1)
{
  EmfMetaModel MM1 = new EmfMetaModel();
  EmfMetaModel GMM = new EmfMetaModel();
  MM1.setMetaModelFile("src/MM1.ecore");
  GMM.setMetaModelFile("src/GMM.ecore");
  this.context.registerMetaModel(MM1);
  this.context.registerMetaModel(GMM);

  XpandFacade facade = XpandFacade.create(this.context);
  facade.evaluate("src::gen::main", a1);
}


This invokation leads to the error message: "No Definition 'main for A1' could be found!" Internal error : element was null

If I add the following text into the Xpand template, it works:
«DEFINE main FOR A1»
«ENDDEFINE»


Is there anything wrong in my code or does Xpand not support this specific scenario?

I am really despaired Sad
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #559959 is a reply to message #559942] Mon, 20 September 2010 14:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6543
Registered: July 2009
Senior Member
hi,

i cannot reproduce this with a simple sample. your sample is missing imports - maybe this is the problem

~Christian
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #560037 is a reply to message #559942] Mon, 20 September 2010 21:14 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: August 2010
Location: Munich
Junior Member
Unfortuneately the imports are not the problem Sad

I got the same error message Sad
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #560038 is a reply to message #560037] Mon, 20 September 2010 21:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6543
Registered: July 2009
Senior Member
Hi,

another thing you can try is to register the metamodels via package name and not via ecore file.

~Christian
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #560039 is a reply to message #559942] Mon, 20 September 2010 21:18 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: August 2010
Location: Munich
Junior Member
You mean in the Java code?
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #560040 is a reply to message #560039] Mon, 20 September 2010 21:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6543
Registered: July 2009
Senior Member
Yes:

EmfMetaModel MM1 = new EmfMetaModel();
MM1.setMetaModelPackage(ChildPackage.class.getName());
EmfMetaModel MM2 = new EmfMetaModel();
MM2.setMetaModelPackage(ParentPackage.class.getName());


~Christian
Re: [Xpand] Error when invoking a definition from Java with polymorphism [message #630542 is a reply to message #559942] Mon, 04 October 2010 00:21 Go to previous message
Stephan Krusche is currently offline Stephan KruscheFriend
Messages: 18
Registered: August 2010
Location: Munich
Junior Member
I now found out that for all types in the general metamodel the properties "abstract" and "interface" are set to true in the ecore file.

I also tried out Xtend in this scenario and I also get an error there:
Couldn't resolve type for 'A'. Did you forget to configure the corresponding metamodel?


Could that be the problem? Are Xpand/Xtend not able to handle interfaces as types?
Previous Topic:Misaligned feature name problems after upgrading to SR1
Next Topic:[Acceleo] How to access list element?
Goto Forum:
  


Current Time: Thu Dec 18 16:23:01 GMT 2014

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

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