Error using Derived EMF EAttributes with Sirius and Xtext [message #1774926] |
Sat, 21 October 2017 04:28  |
Eclipse User |
|
|
|
I have a problem using Derived+Transient+Volatile EMF Attributes within a Sirius-based Editor in combination with an Xtex-based grammar. To be more specific, I have created a simple Ecore metamodel (see attached ecore-metamodel.png figure)
).
Basically, there are "MainEntities" that contain "SubEntities" and "AnotherSubEnties". An "AnotherSubEntity" can create Links to SubEntities. Please note the EAttribute "name" of "LinkToSub" which is unchangeable, volatile, transient and derived. The idea is that I can specify a "LinkToSub" by just giving a reference to a "SubEntity" and the name of "LinkToSub" is directly derived from this reference. This allows to maintain a nice AST without the need to enter arbitrary, not needed names.
From this metamodel, I have derived an Xtext grammar with obvious semantics. The only part I needed to tweak within this grammar is my own IQualifiedNameProvider. Therefore I provide an extended version of DefaultDeclarativeQualifiedNameProvider that basically calculates the name for LinkToSub during the prelinking phase. This works fine for my Xtext grammar.
def QualifiedName qualifiedName(LinkToSub link) {
val nodes = NodeModelUtils.findNodesForFeature(link, MetamodelPackage.Literals.LINK_TO_SUB__SUBENTITY);
if(!nodes.isEmpty()) {
val refname = NodeModelUtils.getTokenText(nodes.get(0));
val parentName = super.getFullyQualifiedName(link.eContainer());
val fqn = parentName.append(refname);
return fqn;
}
return QualifiedName.EMPTY;
}
Moreover, I have also created a Sirius-based model editor where I can model SubEntities, AnotherSubEntities and LinksToSub (as Edges). When I create a LinkToSub, it graphically creates the edge as expected and the properties view shows the right reference to the target SubEntity. The problem now is, when I try to save the model, I get the following error in a popup window:
An internal error occurred during: "Saving Models and Representations for project SiriusBugTest".
Imported namespace must not be null / empty
And here I got stuck. I don't see obvious reasons for what I could have made wrong and the message is too cryptic to guess the cause of the error. So far I could deduce that the problem seems to be related to the derived EAttribute and that it is somehow related to using Sirius in combination with Xtext. The latter became evident because if I create a model not using the Xtext grammar but the generated EMF tree editor, then this error does not appear.
So did anybody had the same problems? Are there obvious mistakes on my side? Or can anybody help me?
I am using Eclipse Oxygen with Sirius 5.0.2 and Xtext 2.12.
|
|
|
|
|
|
Re: Error using Derived EMF EAttributes with Sirius and Xtext [message #1778046 is a reply to message #1775097] |
Fri, 08 December 2017 09:38  |
Eclipse User |
|
|
|
Hi,
it seems that my problem indeed is related to my implementation of the qualified name provider. When I add a new "LinkToSub" and try to save the model, then the qualified name provider returns an empty name (as correctly assumed by Pierre Guilet). More precisely, the call: NodeModelUtils.findNodesForFeature(...) returns an empty node-set. I did some debugging and figured out that the method "ICompositeNode getNode(EObject)" from NodeModelUtils is not able to find a composite node in my specific case. It is hard for me to guess where the cause of the problem is. For instance, I am not quite sure what is the actual context from where the qualified name provider and thus the NodeModelUtils is called. It seems that at the calling point, the feature "subentity" is not (yet) set correctly. So far I have not found a solution to overcome this problem.
The question also is, is there any other way to implement the qualified name provider, e.g. without using the NodeModelUtils at all? Or maybe is there any other way to realize my use-case (with the derived feature) without using a custom qualified name provider?
Can anybody help me?
Thanks in advance,
Alex
|
|
|
Powered by
FUDForum. Page generated in 0.04100 seconds