Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to make DSL editor distinguish between EAttribute and EReference(How to make DSL editor distinguish between EAttribute and EReference )
How to make DSL editor distinguish between EAttribute and EReference [message #1427521] Sat, 20 September 2014 10:04 Go to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Hello,
Please I have and issue and I need some pointing, this my grammar (JIT ecore generation DSL )and it's compiling and merely working, the only issue is that I can't construct an EAttribute as always the content proposal only proposes the created Eclasses and does not proposes the data types that I want to use (MyDataType) as the eType is a cross reference and the eAttributeType is a derived reference.

so I want to get a content proposal with the defined types as well as the created Eclasses, and depending on the choice and EAttribute or an EReference is created.

I know about overriding the ProposalProvider, but here It seems that the grammar is missing somthing, since when I commented the EReference and kept the EAttribute I still get the error.
 
Student
       age:String    <=== getting error here as it can't resolve String

School
      students:Student


MyEStructuralFeature returns ecore::EStructuralFeature:
	{ecore::EAttribute} name=ID ':'  (eType=[ ecore::EDataType|MyDefaultDataType] (defaultValueLiteral=MyValue)?)
	| {ecore::EReference} name=ID ':' (eType=[ecore::EClass])
;

MyEClass returns ecore::EClass:
	{ecore::EClass} name=ID (NEWLINE eStructuralFeatures+=MyEStructuralFeature)+;

MyDataType returns ecore::EDataType:
	{EBoolean} name='Boolean'
	| {EInteger} name='Integer'
	| {ENumber} name='Number'
	| {EString} name='String'
	| {UUID} name='UUID';

MyDefaultDataType:
	'Boolean' | 'Integer' | 'Number' | 'String' | 'UUID';



Thank you
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1427543 is a reply to message #1427521] Sat, 20 September 2014 10:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi you should introduce a keyword like attr and ref

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1427779 is a reply to message #1427543] Sat, 20 September 2014 19:56 Go to previous messageGo to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Thank you Christian, but the issue is that I'm getting like Quote:
Cannot find compatible feature type in sealed EClass EAttribute from imported package http://www.eclipse.org/emf/2002/Ecore: The type 'EAttribute' does not have a feature type'.
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428031 is a reply to message #1427779] Sun, 21 September 2014 06:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the error message should be clear. the feature is called eType isnt it?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428068 is a reply to message #1428031] Sun, 21 September 2014 07:43 Go to previous messageGo to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Yes basically the feature is eType, but the grammar as it is produces only EReferences and does not handle the creation of EAttributes, so I wanted to introduce like you said a new keyword called type but this was rejected and thus the error, I tried the IDerivedStateComputer in order to hook the model creation and modify the Model on the fly but I'm getting liker related error such as can't resolve cross-reference.
thanks again
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428077 is a reply to message #1428068] Sun, 21 September 2014 08:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
please give the whole context. (grammar)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428082 is a reply to message #1428068] Sun, 21 September 2014 08:14 Go to previous messageGo to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
My goal is to do an JIT ecore model generator

this is the old grammar with EAttribute and EReference :
https://www.eclipse.org/forums/index.php/m/1424738/#msg_1424738


this how I modified my grammar in order to use the DerivedStateComputer


FPackage /*returns ecore::EPackage*/:
	(eClassifiers+=FClass
	(NEWLINE NEWLINE eClassifiers+=FClass)*)?;

FProperty returns ecore::EStructuralFeature:
	{FProperty} name=ID ':' ((multi?=ASTERISK)? ((eAttributeType=FDataType (defaultValueLiteral=FValue)?) |
	eReferenceType=[ecore::EClass]));

FClass returns ecore::EClass:
	{ecore::EClass} name=ID (NEWLINE eStructuralFeatures+=FProperty)+;

FValue:
	STRING | NUMBER | INT | BOOLEAN;

enum FDataType:
	Boolean='Boolean'
	| Integer='Integer'
	| Number='Number'
	| String='String'
	| UUID='UUID';

terminal ASTERISK:
	'*';

terminal BOOLEAN returns ecore::EBoolean:
	'true' | 'false';

terminal NUMBER returns ecore::EDouble:
	'-'? INT? '.' INT (('E' | 'e') '-'? INT)?;

terminal ID:
	'^'? ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;

terminal INT returns ecore::EInt:
	('0'..'9')+;

terminal STRING returns ecore::EString:
	'"' ('\\' ('b' | 't' | 'n' | 'f' | 'r' | 'u' | '"' | "'" | '\\') | !('\\' | '"'))* '"' |
	"'" ('\\' ('b' | 't' | 'n' | 'f' | 'r' | 'u' | '"' | "'" | '\\') | !('\\' | "'"))* "'";

terminal ML_COMMENT:
	'/*'->'*/';

terminal SL_COMMENT:
	'//' !('\r' | '\n')* ('\r'? '\n')?;

terminal NEWLINE:
	('\r'? '\n');

terminal WS:
	('\t' | ' ')+;	





and this is where I hook the model , the DrivedStateComputer


	override discardDerivedState(DerivedStateAwareResource resource) {
		resource.allContents.filter(typeof(FProperty)).forEach [ attr |
			(attr.eContainer as EClass).EStructuralFeatures.remove(attr)
		]
	}

	override installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
		resource.allContents.filter(FProperty).forEach [
			toEReference
		]
	}

	def EStructuralFeature toEStructuralFeature(FProperty attr) {
		if (attr.EReferenceType != null) {
			attr.toEReference
		} else {
			attr.toEAttribute
		}
	}

	def EStructuralFeature toEReference(FProperty ref) {
		val eReference = EcoreFactory::eINSTANCE.createEReference
		eReference.name = ref.name
		eReference.EType = ref.EReferenceType.eClass
		if (ref.multi)
			eReference.upperBound = -1
		var eClass = ref.eContainer as EClass
		eClass.EStructuralFeatures.remove(ref);
		eClass.EStructuralFeatures += eReference
		return eReference
	}

	def EStructuralFeature toEAttribute(FProperty attr) {
		val eAttribute = EcoreFactory::eINSTANCE.createEAttribute
		eAttribute.name = attr.name
		eAttribute.EType = attr.EAttributeType.toEDataType
		if (attr.multi)
			eAttribute.upperBound = -1
		eAttribute.defaultValueLiteral = attr.defaultValueLiteral
		var eClass = attr.eContainer as EClass
		eClass.EStructuralFeatures.remove(attr)
		eClass.EStructuralFeatures += eAttribute
		return eAttribute
	}

	def EDataType toEDataType(FDataType e) {
		switch (e) {
			case BOOLEAN:
				return EcorePackage::eINSTANCE.EBoolean
			case STRING:
				return EcorePackage::eINSTANCE.EString
			case NUMBER:
				return EcorePackage::eINSTANCE.EDouble
			case INTEGER:
				return EcorePackage::eINSTANCE.EInt
			case UUID: {
				val uuid = EcoreFactory::eINSTANCE.createEDataType
				uuid.name = e.getName
				uuid.instanceClassName = "java.util.UUID"
				return uuid
			}
		}
	}



thank you
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428085 is a reply to message #1428082] Sun, 21 September 2014 08:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and what is the actual error? and when do you get it?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428090 is a reply to message #1428085] Sun, 21 September 2014 08:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
p.s: did you have a look at http://xtextcasts.org/episodes/18-model-optimization

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428101 is a reply to message #1428090] Sun, 21 September 2014 08:50 Go to previous messageGo to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Yes that was my source of inspiration Smile the problem with this is that when I'm trying to create a reference it says that it couldn't resolve the cross-reference
Ex :
Person 
     name:String
     parents: * Person // here it can't resolve the person ref
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428104 is a reply to message #1428101] Sun, 21 September 2014 08:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i cannot reproduce that one (not using your derivedstatecomputer) maybe you throw away too much there. or do you have other customizations?
do you have build automatically on?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428206 is a reply to message #1428104] Sun, 21 September 2014 12:56 Go to previous messageGo to next message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Hi Christian,
yes my automatic build is on, and this is basically the whole grammar, I'm getting an issue with the scope, it throws an NPE when looking for FProperty and this because of (comment in the code section)
	def EStructuralFeature toEReference(FProperty ref) {
		val eReference = EcoreFactory::eINSTANCE.createEReference
		eReference.name = ref.name
		eReference.EType = ref.EReferenceType.eClass
		if (ref.multi)
			eReference.upperBound = -1
		var eClass = ref.eContainer as EClass
		eClass.EStructuralFeatures.remove(ref); //this part I remove the FProperty from the model
		eClass.EStructuralFeatures += eReference
		return eReference
	}

and the linker error says that no model element is attached which is normal in my case since I want to replace each FProperty by an EAttribute or an EReference.
I may be doing it the wrong way, or may be there is a simpler way to just create an ecore model directly from the grammar ?

Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428259 is a reply to message #1428206] Sun, 21 September 2014 14:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i still dont understand why you do this all.

why remove?

as i said before: simply use xcore. or have a look what is does to get eattributes running.
i dont think that derivedstatecomputer stuff is neccesary. maybe it is ok to simply customize the linker.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make DSL editor distinguish between EAttribute and EReference [message #1428271 is a reply to message #1428259] Sun, 21 September 2014 15:07 Go to previous message
Riadh HAJ AMOR is currently offline Riadh HAJ AMORFriend
Messages: 15
Registered: September 2014
Junior Member
Yes Christian,
I have a requirement to implement an ecore DSL with a specific layout to give something like
Customer
          name:String
          cutomers:* Customer

and this model should be seen as an ecore model on the fly, no code generation behind
so what would be seen if the DSL file opened by a ecore reflective editor something like :
EClass : Customer     //EClass here
        name : EString    //EAttribute
        customers : Customer   //EReference

what is complicating my life is this on the fly modification to get the ecore MM ( thus the remove)
thanks and I will dig in the xcore code may be I will find somthing.
Previous Topic:Disable some commands from Xbase library
Next Topic:[xtext] Delete Xtext Index (file or via clean?)
Goto Forum:
  


Current Time: Thu Apr 25 15:36:29 GMT 2024

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

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

Back to the top