Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Instance a custom element inside the model factory
[SOLVED] Instance a custom element inside the model factory [message #1674729] Sat, 14 March 2015 21:47 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear all,

I have defined my language, named SARL with the following rule in my grammar:
Action returns xtend:XtendFunction:
   {SarlAction}
	name=FunctionID
	(
		=> '('
		(	parameters+=Parameter
			(=>',' parameters+=Parameter)* 
		)?
		')'
	)?
;


I have defined a custom implementation of the SarlAction:
public class SarlActionImplCustom extends XtendFunctionImplCustom implements SarlAction {
...
}


In the class SarlFactoryImpl, the function createSarlAction is defined as:
  public SarlAction createSarlAction()
  {
    SarlActionImpl sarlAction = new SarlActionImpl();
    return sarlAction;
  }



How to change the MWE2 script to generate the SarlFactoryImpl with the following code in place of the previous code:
  public SarlAction createSarlAction()
  {
    SarlActionImplCustom sarlAction = new SarlActionImplCustom();
    return sarlAction;
  }

[Updated on: Mon, 20 April 2015 08:46]

Report message to a moderator

Re: Instance a custom element inside the model factory [message #1675617 is a reply to message #1674729] Sun, 15 March 2015 05:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

do you use a manually maintained metamodel or a derived one?
if you use a manually maintained one you can use EcoreGenerator Fragment to do this.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Instance a custom element inside the model factory [message #1675665 is a reply to message #1675617] Sun, 15 March 2015 06:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
p.s. alternatively (if you do not use the efactories outside xtext) you can use a custom IAstFactory (subslass of DefaultEcoreElementFactory)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Instance a custom element inside the model factory [message #1692846 is a reply to message #1675665] Mon, 20 April 2015 08:45 Go to previous message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
For solving my problem, I created a subclass of EMFGeneratorFragment (with its associated xpt file). This fragment make possible to change the super types of the Ecore element implementations.

The code is available at: https://github.com/gallandarakhneorg/sarl/blob/OOP-Xtend/plugins/io.sarl.lang/src/io/sarl/lang/generator/ecore/SARLEMFGeneratorFragment.java

Since this code override a function of EMFGeneratorFragment for enhancing its behavior, I plan to submit a patch for EMFGeneratorFragment.
Previous Topic:customize error "Cannot use this in a static context"
Next Topic:[SOLVED] Incomplete and invalid serialization of Ecore elements
Goto Forum:
  


Current Time: Thu Mar 28 12:54:35 GMT 2024

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

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

Back to the top