|
|
|
Re: Bi-direction (EOpposite) in Xtext [message #1769743 is a reply to message #1769739] |
Thu, 03 August 2017 06:43 |
Nicholas Kong 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.
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 623 times) -
Attachment: railway.ecore
(Size: 4.05KB, Downloaded 93 times) -
Attachment: Railway.xtext
(Size: 2.13KB, Downloaded 57 times)
|
|
|
|
Re: Bi-direction (EOpposite) in Xtext [message #1769745 is a reply to message #1769744] |
Thu, 03 August 2017 07:02 |
|
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()));
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 03 August 2017 07:10] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03316 seconds