Serialize cross-reference in stand-alone mode [message #1738402] |
Tue, 19 July 2016 13:10  |
Eclipse User |
|
|
|
Hi,
I am experiencing problems when serializing a cross-reference when using Xtext in a stand-alone context.
Below is a sample program that reproduces the serialization problem.
@Test
public void testCrossReferencing() {
ResourceSet resourceSet = new XtextResourceSet();
DomainModel dm = XXXFactory.eINSTANCE.createDomainModel();
dm.setName("TypesModel");
Type t = XXXFactory.eINSTANCE.createType();
t.setName("Integer");
dm.getElements().add(t);
URI uri1 = URI.createPlatformResourceURI("sample.tests/models/tmp/TypesModel.hddd");
Resource rs1 = resourceSet.createResource(uri1);
rs1.getContents().add(dm);
TypedElement te = XXXFactory.eINSTANCE.createTypedElement();
te.setType(t);
te.setName("attr");
ValueObject vo = XXXFactory.eINSTANCE.createValueObject();
vo.setName("VO1");
vo.getAttributes().add(te);
DomainModel dm2 = XXXFactory.eINSTANCE.createDomainModel();
dm2.setName("DataModel");
dm2.getElements().add(vo);
URI uri2 = URI.createPlatformResourceURI("sample.tests/models/tmp/DataModel.hddd");
Resource rs2 = resourceSet.createResource(uri2);
rs2.getContents().add(dm2);
try {
rs1.save(Collections.EMPTY_MAP);
rs2.save(Collections.EMPTY_MAP);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
rs2 contains a cross-reference from the TypedElement object to a TypeObject in rs1 via the type reference. The resulting stack trace upon saving rs2 is the following:
java.lang.RuntimeException: No EObjectDescription could be found in Scope TypedElement.type for DomainModel'TypesModel'.elements[0]->Type'Integer'
Semantic Object: DomainModel'DataModel'.elements[0]->ValueObject'VO1'.attributes[0]->TypedElement'attr'
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:77)
at
...
I have debugged the code up until the point that I could indeed verify that the scope is empty. No candidates exist to resolve the cross-reference.
From loading Xtext resources, I know that cross-references are only resolved when all resources are contained by the XtextResourceSet, so I expected something similar when adding and saving resources.
However, this doesn't seem to be the case. My question therefore is: how to update the index when adding new resources to the resourceset, such that the cross-references get resolved upon serialization of cross-references in Xtext resources?
|
|
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738427 is a reply to message #1738425] |
Tue, 19 July 2016 16:48   |
Eclipse User |
|
|
|
Hi
On the contrary, if you make sure you have a well-configured
URIMap/URIHandler, createPlatformResourceURI is very desirable for
standalone usage. The same code can be used standalone or within Eclipse
without chnage.
Regards
Ed Willink
On 19/07/2016 17:12, Christian Dietrich wrote:
> btw createPlatformResourceURI does not sound very standalone
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
|
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738500 is a reply to message #1738454] |
Wed, 20 July 2016 11:16   |
Eclipse User |
|
|
|
Thanks for your replies. The discussion the two of you had triggered me to perform a small experiment where the platform URI is replaced with a file URI. To my surprise, both resources, also the one that contains the cross-reference, were correctly serialized to disk. Great!
Question remains: why was the absolute file URI required for the Xtext index/scoping mechanism to properly resolve the cross-reference during serialization?
Btw. I tried to extend the URIMap of the URIConverter attached to the resourceSet with an entry to map the platform URI onto the file URI:
URI srcURI = URI.createPlatformResourceURI("sample.tests/");
URI trgtURI = URI.createFileURI("C:/myworkspace/sample.tests/");
resourceSet.getURIConverter().getURIMap().put(srcURI, trgtURI);
Somehow, normalization takes no effect so the platform URI from the example is not automatically translated into the physical URI. When I print the string representation of the normalized URI, the file URI is however correct:
URI uri1 = URI.createURI("platform:/resource/sample.tests/models/tmp/TypesModel.hddd");
System.out.println(resourceSet.getURIConverter().normalize(uri1).toString());
Console shows output:
file:/C:/myworkspace/sample.tests/tmp/TypesModel.hddd
Any thoughts on this?
|
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738516 is a reply to message #1738502] |
Wed, 20 July 2016 13:37   |
Eclipse User |
|
|
|
Again, thanks for your reply. It still leaves me a bit puzzled to be honest. Can you please elaborate more on the answer to my question? Apparently it's required for the Xtext global scope to be build with resources for which it holds that they can be properly referenced by a absolute file URI. Why is that the case?
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738536 is a reply to message #1738516] |
Wed, 20 July 2016 15:43   |
Eclipse User |
|
|
|
Niels Brouwers <forums-noreply@xxxxxxxx> wrote:
> Again, thanks for your reply. It still leaves me a bit puzzled to be
> honest. Can you please elaborate more on the answer to my question?
> Apparently it's required for the Xtext global scope to be build with
> resources for which it holds that they can be properly referenced by a
> absolute file URI. Why is that the case?
I dont get that Part of the question. In standalone mode the global scope
is the sum of all resources in the resourceset but what about your
customization to the scope
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738557 is a reply to message #1738402] |
Wed, 20 July 2016 20:15   |
Eclipse User |
|
|
|
The question is why the cross-reference serialization fails when using platform resource URIs (possibly that cannot be properly normalized), but succeeds when using file URIs?
I am not aware of any customizations I made to the global scope, however it could well be the case that I selected a different scope strategy in the MWE2 workflow to allow resolution of cross-references based on fully qualified names.
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738558 is a reply to message #1738557] |
Wed, 20 July 2016 20:32  |
Eclipse User |
|
|
|
Niels Brouwers <forums-noreply@xxxxxxxx> wrote:
> The question is why the cross-reference serialization fails when using
> platform resource URIs (possibly that cannot be properly normalized), but
> succeeds when using file URIs?
>
> I am not aware of any customizations I made to the global scope, however
> it could well be the case that I selected a different scope strategy in
> the MWE2 workflow to allow resolution of cross-references based on fully qualified names.
Can you please Share a complete example
|
|
|
Powered by
FUDForum. Page generated in 0.12967 seconds