Skip to main content



      Home
Home » Modeling » TMF (Xtext) » IQualifiedName references to object inherited from other DSL
IQualifiedName references to object inherited from other DSL [message #1798583] Tue, 20 November 2018 11:09 Go to next message
Eclipse UserFriend
I have one project with a DSL where I can define NodeType which contains interfaces and ports. See MyTypes grammar dsl.

Then I have another project with a Topology DSL where I can add Nodes and Cables. The nodes refer to the imported:NodeType using QualifiedName as follows:

[i]Node:
'node-id:' name=ID
'type:' type=[imported::NodeType|QualifiedName]
;[/i]

This part works fine.
But then I model a Cable with two endpoints that refers to a PortRef as follows:

Cable:
'cable-id:' name=ID
'endpoint1:' endpoint1= PortRef
'endpoint2:' endpoint2= PortRef
;

PortRef:
node=[Node|QualifiedName]
;

My question is how to write the reference since the available ports are defined in the imported grammar for the node type?

So an example instance of MyTypes could be:

FamilyId: myNodeFamily
NodeTypeId: myNodeType
InterfaceId: myIf
PortId: A PortName: 'A'
PortId: B PortName: 'B'

And then I would like to be able to refer to a port as follows from MyPrc:

cluster: MyCluster
node-id: MyNode1 type: MyNodeType

cable-id: myCable endpoint1: MyNode1.myIf.A

So far have only been to select MyNode1 or MyNodeType.

Currently I have this in MyPrcQualifiedNameProvider.xtend:

class MyPrcQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
@Inject IQualifiedNameConverter converter = new IQualifiedNameConverter.DefaultImpl();

override QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof Node) {
val nodes = NodeModelUtils.findNodesForFeature(obj, MyPrcPackage.Literals.NODE__TYPE)
for (node : nodes) {
val text2 = NodeModelUtils.getTokenText(node);
if (text2 !== null) {
return converter.toQualifiedName(text2.toUpperCase);
}
}
}
}
}

And this in MyTypesQualifiedNameProvider.xtend:

class MyTypesQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
@Inject IQualifiedNameConverter converter = new IQualifiedNameConverter.DefaultImpl();

override QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof NodeType) {
val text = obj.getName();
if (text !== null) {
return converter.toQualifiedName(text.toUpperCase);
}
}
else if (obj instanceof Interface) {
val text = obj.getName();
if (text !== null) {
return converter.toQualifiedName(text.toUpperCase);
}
}
else if (obj instanceof Port) {
val text = obj.getName();
if (text !== null) {
return converter.toQualifiedName(text.toUpperCase);
}
}
}
}

Do I need to use both in order to achieve what I am after?
  • Attachment: MyTypes.xtext
    (Size: 0.56KB, Downloaded 88 times)
  • Attachment: MyPrc.xtext
    (Size: 0.81KB, Downloaded 74 times)
Re: IQualifiedName references to object inherited from other DSL [message #1798585 is a reply to message #1798583] Tue, 20 November 2018 11:13 Go to previous messageGo to next message
Eclipse UserFriend
if you want to use the reference as part of the qualified name: yes. but you usually need to do this only at the place of decl. in this case the place that defines Node
the part that defines PortRef needs no change (if you want want to refer to PortRefs too or if you have other rules on how to build names. do you?)

[Updated on: Tue, 20 November 2018 11:14] by Moderator

Re: IQualifiedName references to object inherited from other DSL [message #1798586 is a reply to message #1798585] Tue, 20 November 2018 11:22 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for fast feedback. I don't need to refer to portRefs.
So to make sure I understand: My grammar should work and I should add code in MyPrcQualifiedNameProvider.xtend to resolve the references in MyTypes grammar?
Re: IQualifiedName references to object inherited from other DSL [message #1798589 is a reply to message #1798586] Tue, 20 November 2018 11:40 Go to previous message
Eclipse UserFriend
no what i say:

the qualified name provider of the language that declares the things should give the things names.
in your case the Node is defined in myPrc
so MyPrcQualifiedNameProvider should read the node text.

i dont know why you have customizations in MyTypesQualifiedNameProvider
(the to uppercase thing)

[Updated on: Tue, 20 November 2018 11:54] by Moderator

Previous Topic:Xtext DSLs ignored in Maven Multiple Modules Project
Next Topic:Working with unordered groups
Goto Forum:
  


Current Time: Tue Jun 17 19:56:32 EDT 2025

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

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

Back to the top