Serialize cross-reference in stand-alone mode [message #1738402] |
Tue, 19 July 2016 13:10 |
Niels Brouwers Messages: 80 Registered: July 2009 |
Member |
|
|
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?
Kind regards,
Niels Brouwers.
|
|
|
|
|
|
|
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738536 is a reply to message #1738516] |
Wed, 20 July 2016 15:43 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Re: Serialize cross-reference in stand-alone mode [message #1738558 is a reply to message #1738557] |
Wed, 20 July 2016 20:32 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
Powered by
FUDForum. Page generated in 0.04584 seconds