Could not serialize EObject via backtracking [message #1388800] |
Fri, 27 June 2014 00:26 |
Jack Greenfield Messages: 18 Registered: June 2014 |
Junior Member |
|
|
I'm getting the following exception when serializing a GMF diagram to an XText resource:
java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null name=ID extends=[System|QualifiedName]? description=STRING? (properties+=Property properties+=Property*)? (annotations+=Annotation annotations+=Annotation*)? (metrics+=MetricGroup metrics+=MetricGroup*)? (constraints+=ConstraintGroup constraints+=ConstraintGroup*)? (elements+=Resource elements+=Resource*)? (elements+=Package elements+=Package*)? (elements+=Contract elements+=Contract*)? (connectors+=ProviderEndpoint connectors+=ProviderEndpoint*)? (connectors+=ConsumerEndpoint connectors+=ConsumerEndpoint*)? (relationships+=Dependency relationships+=Dependency*)? (relationships+=Relationship relationships+=Relationship*)? elements+=Component* null
Values: name(1), connectors(2)
Semantic Object: Model'org.example.model'.elements[0]->System'System1'
Context: Component
The xtext grammar and the GMF editor were developed independently, so both are of non trivial size. However, the salient piece of the grammar, from what I can tell, is as follows:
System returns system::System:
{system::System}
'system' name=ID ('extends' extends=[system::System|QualifiedName])? (description=STRING)?
('{'
('providers' '{' connectors+=ProviderEndpoint (',' connectors+=ProviderEndpoint)* '}')?
('consumers' '{' connectors+=ConsumerEndpoint (',' connectors+=ConsumerEndpoint)* '}')?
(elements+=Component)*
'}')?;
I've removed a few of the productions, since they aren't necessary to recreate the problem. So, here's the problem...
If I create a System and add first a ProviderEndpoint, then a ConsumerEndpoint, all is well, and the serialization looks like this:
package org.example.model {
system System1 {
providers {
< System1Proxy1
}
consumers {
> System1Proxy2
}
}
}
However, if I create a System and add first a ConsumerEndpoint, then a ProviderEndpoint, I get the exception shown above. A (perhaps overly) simple reading of the situation suggests that order matters, and that the serializer is having trouble writing to parts of the file that should precede parts already written.
It's easy to recreate the problem with other parts of the grammar where a container has an ordered list of contents by likewise first adding something that must come later in the serialization, and then adding something that must come earlier.
I tried adding a fragment provider, as follows:
public class LanguageFragmentProvider implements IFragmentProvider {
@Override
public String getFragment(EObject obj, Fallback fallback) {
String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj);
if (obj instanceof Model) {
return name;
} else if (obj instanceof Element) {
EObject container = obj.eContainer();
if (container != null && !(container instanceof Model)) {
String containerName = SimpleAttributeResolver.NAME_RESOLVER
.apply(container);
return containerName + "." + name;
}
}
return fallback.getFragment(obj);
}
@Override
public EObject getEObject(Resource resource, String fragment,
Fallback fallback) {
for (TreeIterator<EObject> allContents = resource.getAllContents(); allContents
.hasNext() ; ) {
EObject next = allContents.next();
if (fragment.equals(getFragment(next, fallback))) {
return next;
}
}
return fallback.getEObject(fragment);
}
}
And I've verified that it's getting called and producing the right results. As for scoping, I'm using the following fragments in the MWE2 workflow:
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
fragment = exporting.QualifiedNamesFragment auto-inject {}
Any idea what might be causing the problem and/or how to work around it?
Thanks.
[Updated on: Fri, 27 June 2014 00:27] Report message to a moderator
|
|
|
|
|
Re: Could not serialize EObject via backtracking [message #1389190 is a reply to message #1388923] |
Fri, 27 June 2014 13:05 |
Jack Greenfield Messages: 18 Registered: June 2014 |
Junior Member |
|
|
I did use & to join the clauses. Was surprised to see them repeated, given that only one should be allowed per the documentation, to your point. Sadly, the parser enforces the constraint, and flags the repeated elements as errors.
So, the point here is that the hard contract for serialization mentioned throughout the documentation is violated... The serializer writes a model that cannot be parsed.
[Updated on: Fri, 27 June 2014 15:24] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02240 seconds