Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Bi-direction (EOpposite) in Xtext
Bi-direction (EOpposite) in Xtext [message #1769552] Tue, 01 August 2017 14:25 Go to next message
Nicholas Kong is currently offline Nicholas KongFriend
Messages: 59
Registered: July 2016
Location: China
Member
To Whom It May Concern,

I have one meta-model project, which have bi-direction reference in it. Base on this meta-model, I also have some generated instance model (XMI Schema).

Now, I want to transfer these XMI model into Xtext DSL. But as I know, Xtext support bi-direction not well. So how should I do?
Re: Bi-direction (EOpposite) in Xtext [message #1769737 is a reply to message #1769552] Thu, 03 August 2017 05:06 Go to previous messageGo to next message
Nicholas Kong is currently offline Nicholas KongFriend
Messages: 59
Registered: July 2016
Location: China
Member
No one knows how to handle this problem?
Re: Bi-direction (EOpposite) in Xtext [message #1769739 is a reply to message #1769737] Thu, 03 August 2017 05:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
what is the exact problem with bidirectional references you want to solve?
should both end appear in the syntax? is it just about serialization?
.....


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Bi-direction (EOpposite) in Xtext [message #1769743 is a reply to message #1769739] Thu, 03 August 2017 06:43 Go to previous messageGo to next message
Nicholas Kong is currently offline Nicholas KongFriend
Messages: 59
Registered: July 2016
Location: China
Member
Thanks for your replay. Christian.

Sorry for my description not clearly.
I have attache the meta-model.
index.php/fa/30244/0/

1,I want to use Xtext in this meta-model. But after I generate the DSL I find it has a bidirectional reference. These two reference must be appeared and serialized. So what should I do? Remove the EOpposite attribute from this Reference? or ?:

Switch returns Switch:
	'Switch'
	'{'
	('id' id=EInt)?
	'currentPosition' currentPosition=Position
	('connectsTo' '(' connectsTo+=[TrackElement|STRING] ("," connectsTo+=[TrackElement|STRING])* ')')?
[b]	('positions' '(' positions+=[SwitchPosition|STRING] ("," positions+=[SwitchPosition|STRING])* ')')?[/b]
	'}';

SwitchPosition returns SwitchPosition:
	'SwitchPosition'
	'{'
	('id' id=EInt)?
	'position' position=Position
[b]	'switch' switch=[Switch|STRING][/b]
	'}';


2,Each of this model Element only has id, dosen't have name. I can create the model element, but when I create reference between two element. Xtext alert that "Couldn't resolve reference to Semaphore '0'."
Sample Model:
RailwayContainer {
	semaphores{
		Semaphore{
			id 0 
			signal GO
		}
	}
	routes{
		Route {
			id 1
			entry '0'
			exit '0'
			definedBy{
				Sensor{
					id 9
				},
				Sensor{
					id 8
				}
			}
		}		
	}
}

  • Attachment: 1.png
    (Size: 76.40KB, Downloaded 425 times)
  • Attachment: railway.ecore
    (Size: 4.05KB, Downloaded 45 times)
  • Attachment: Railway.xtext
    (Size: 2.13KB, Downloaded 39 times)
Re: Bi-direction (EOpposite) in Xtext [message #1769744 is a reply to message #1769743] Thu, 03 August 2017 06:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi,

thus my question: do you want to have bidi refs on textual level or not?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Bi-direction (EOpposite) in Xtext [message #1769745 is a reply to message #1769744] Thu, 03 August 2017 07:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
and is this about referencing via id or is it about opposites?

the first one can be solved easily

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	override bindIQualifiedNameProvider() {
		MyQNP
	}
	
}


package org.xtext.example.mydsl1;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;

import railway.Semaphore;

public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	public QualifiedName qualifiedName(Semaphore s) {
		return QualifiedName.create(Integer.toString(s.getId()));
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 03 August 2017 07:10]

Report message to a moderator

Re: Bi-direction (EOpposite) in Xtext [message #1769752 is a reply to message #1769744] Thu, 03 August 2017 07:32 Go to previous messageGo to next message
Nicholas Kong is currently offline Nicholas KongFriend
Messages: 59
Registered: July 2016
Location: China
Member
No, I think. I compare the two kinds of generated text grammar, they are same!!!! (one has EOpposite, the other does not).
So I just remove the EOpposite attribute from the M2, am I right?


For the question 2, do you have any IDEA about this part?



Re: Bi-direction (EOpposite) in Xtext [message #1769753 is a reply to message #1769752] Thu, 03 August 2017 07:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
yes remove the unwanted side should do the trick

to fix names/id problem see my post above


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Bi-direction (EOpposite) in Xtext [message #1769757 is a reply to message #1769753] Thu, 03 August 2017 07:44 Go to previous message
Nicholas Kong is currently offline Nicholas KongFriend
Messages: 59
Registered: July 2016
Location: China
Member
Wow. It works.

Thank you very much. ( ;

Previous Topic:Setting up Xtext dev. environment (Help needed)
Next Topic:[Xtend] Activate Xtend Java generation in plain Maven Project in Eclipse
Goto Forum:
  


Current Time: Mon Sep 20 12:30:34 GMT 2021

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

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

Back to the top