Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Bi-direction (EOpposite) in Xtext
Bi-direction (EOpposite) in Xtext [message #1769552] Tue, 01 August 2017 10:25 Go to next message
Eclipse UserFriend
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 01:06 Go to previous messageGo to next message
Eclipse UserFriend
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 01:17 Go to previous messageGo to next message
Eclipse UserFriend
what is the exact problem with bidirectional references you want to solve?
should both end appear in the syntax? is it just about serialization?
.....
Re: Bi-direction (EOpposite) in Xtext [message #1769743 is a reply to message #1769739] Thu, 03 August 2017 02:43 Go to previous messageGo to next message
Eclipse UserFriend
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 708 times)
  • Attachment: railway.ecore
    (Size: 4.05KB, Downloaded 113 times)
  • Attachment: Railway.xtext
    (Size: 2.13KB, Downloaded 82 times)
Re: Bi-direction (EOpposite) in Xtext [message #1769744 is a reply to message #1769743] Thu, 03 August 2017 02:55 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

thus my question: do you want to have bidi refs on textual level or not?
Re: Bi-direction (EOpposite) in Xtext [message #1769745 is a reply to message #1769744] Thu, 03 August 2017 03:02 Go to previous messageGo to next message
Eclipse UserFriend
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()));
	}

}

[Updated on: Thu, 03 August 2017 03:10] by Moderator

Re: Bi-direction (EOpposite) in Xtext [message #1769752 is a reply to message #1769744] Thu, 03 August 2017 03:32 Go to previous messageGo to next message
Eclipse UserFriend
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 03:34 Go to previous messageGo to next message
Eclipse UserFriend
yes remove the unwanted side should do the trick

to fix names/id problem see my post above
Re: Bi-direction (EOpposite) in Xtext [message #1769757 is a reply to message #1769753] Thu, 03 August 2017 03:44 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 11:10:05 EDT 2025

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

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

Back to the top