Problem with unresolved proxy serialization [message #915882] |
Tue, 18 September 2012 06:38 |
George Suaridze Messages: 5 Registered: October 2011 |
Junior Member |
|
|
Hello, something wrong with unresolved proxy serialization.
Use case:
1. read model from file, which contains unresolvable object;
2. if I try to save I'll get XtextSerializationException
I looked through the code, while model serialization CrossReferenceSerializer gets text from node if object is unresolvable proxy and that is right, but node is null for this proxy.
Then I looked at AbstractParseTreeConstructor, as I understand it recreates token tree and tries to link tokens with existing nodemodel in AbstractParseTreeConstructor.assignNodesByMatching method.
For crossreferences it executes method in the calss CrossReferenceSerializer:
public class CrossReferenceSerializer implements ICrossReferenceSerializer {
...
public boolean equalsOrReplacesNode(EObject context, CrossReference crossref, EObject target, INode node) {
if (crossref != node.getGrammarElement())
return false;
EReference ref = GrammarUtil.getReference(crossref);
if (!ref.isMany())
return true;
List<EObject> objects = linkingService.getLinkedObjects(context, ref, node);
return objects.contains(target);
}
...
public class DefaultLinkingService extends AbstractLinkingService {
...
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node)
throws IllegalNodeException {
final EClass requiredType = ref.getEReferenceType();
if (requiredType == null)
return Collections.<EObject> emptyList();
final String crossRefString = getCrossRefNodeAsString(node);
if (crossRefString != null && !crossRefString.equals("")) {
if (logger.isDebugEnabled()) {
logger.debug("before getLinkedObjects: node: '" + crossRefString + "'");
}
final IScope scope = getScope(context, ref);
QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
if (logger.isDebugEnabled()) {
logger.debug("after getLinkedObjects: node: '" + crossRefString + "' result: " + eObjectDescription);
}
if (eObjectDescription != null)
return Collections.singletonList(eObjectDescription.getEObjectOrProxy());
}
return Collections.emptyList();
}
...
as you can see it will always return false for unresolved object, because linkingService uses scope for finding objects, and scope doesn't contain unresolved objects.
How can I solve this problem? Should I post this as a bug?
I attached sample project, to reproduce this.
there is jUnit test to run org.example.domainmodel.SerializeTest
Eclipse Juno. Xtext 2.3.0
|
|
|
|
Powered by
FUDForum. Page generated in 0.03366 seconds