Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Create object of dsl ecore classes programatically from generator (xtend)(Cannot instantiate the interface type of DSL ecore sub-classes from generator.xtend)
Create object of dsl ecore classes programatically from generator (xtend) [message #1870650] Wed, 04 September 2024 14:26 Go to next message
Anders Ishoey is currently offline Anders IshoeyFriend
Messages: 3
Registered: January 2024
Junior Member
The classes in my ecore explorer (all of them, including "PortInfo") are not marked "interface" or "abstract".
The code below rases an editor error on "
P1=new PortInfo;
" saying "cannot instantiate the interface of type PortInfo"

			«{var PortInfo P1 ; 
				P1=new PortInfo;
				P1.signal=r.name ;
				P1.direction=tRtlPortDirection.PORT_OUT;
				P1.signalType=r.typeString;
				RegIF.portList.add(P1);
			}»


I want the generator.xtend to collect information while generating and at some point add it to a list, that is a reference attribute in the class of the "RegIF" object.


If "PortInfo" is indeed an interface although NOT marked as such in the ecore, I believe I have to create an implementation for it. I did that in a separate xtend file

import ridl2.PortInfo
import ridl2.tRtlPortDirection

class PortInfo1 implements PortInfo{
	String signal
	String signalType
	tRtlPortDirection direction
	
	override getDirection() {
		return direction
	}


and do this instead in generator.xtend :

			«{var PortInfo1 P1 ; 
				P1=new PortInfo1;
				P1.signal=r.name ;
				P1.direction=tRtlPortDirection.PORT_OUT;
				P1.signalType=r.typeString;
				RegIF.portList.add(P1);
			}»

Obviously "RegIF.portList.add(P1); " fails miserably because "PortInfo1 " is a wrong class.

The overall question is: How do I make the PortInfo objects in the xtend code so I can add to RegIF.portList (in the same xtend code)

Alternatively, where and how do I add a PortInfo list to the RegIF class without editing generated files.
  • Attachment: eclipse2.jpg
    (Size: 19.38KB, Downloaded 5 times)
  • Attachment: eclipse1.jpg
    (Size: 30.47KB, Downloaded 6 times)
  • Attachment: eclipse3.jpg
    (Size: 31.66KB, Downloaded 5 times)
Re: Create object of dsl ecore classes programatically from generator (xtend) [message #1870653 is a reply to message #1870650] Wed, 04 September 2024 14:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
In emf you create instances with

MyPackageFactory.eInstance.createMyClass


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create object of dsl ecore classes programatically from generator (xtend) [message #1870674 is a reply to message #1870653] Thu, 05 September 2024 06:27 Go to previous message
Anders Ishoey is currently offline Anders IshoeyFriend
Messages: 3
Registered: January 2024
Junior Member
Thanks!
This solved my problem. In my context the literal wording is
import ridl2.Ridl2Factory
...
var PortInfo P ;
P=new PortInfo; // wrong
P=Ridl2Factory.eINSTANCE.createPortInfo; // right

/Anders
Previous Topic:[LSP]: How to support project configuration files
Next Topic:Lua xText Grammar: Distinguish between variable reference and declaration
Goto Forum:
  


Current Time: Thu Sep 19 10:54:45 GMT 2024

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

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

Back to the top