Hi,
I came across a serialization error, which I simply can't figure out to understand/solve.
It seems like a specific Type gets interpreted as another one, during serialization.
I want to create a Xtext Embedded Editor in an other Editor.
First I need create a XtextResource based on my ecore Model.
My code looks like this:
EObject semanticElement = EcoreUtil.copy(originalSemanticElement.eResource().getContents().get(0));
XtextResource xtextResource = createVirtualXtextResource(originalSemanticElement.eResource().getURI(), semanticElement);
semanticElementFragment = originalResource.getURIFragment(originalSemanticElement);
protected XtextResource createVirtualXtextResource(URI uri, EObject semanticElement) throws IOException {
IResourceFactory resourceFactory = xtextInjector.getInstance(IResourceFactory.class);
// TODO use the synthetic scheme.
XtextResourceSet rs = xtextInjector.getInstance(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());
// Create virtual resource
XtextResource xtextVirtualResource = (XtextResource) resourceFactory
.createResource(URI.createURI(uri.toString()));
rs.getResources().add(xtextVirtualResource);
// Populate virtual resource with the given semantic element to edit
xtextVirtualResource.getContents().add(semanticElement);
// Save and reparse in order to initialize virtual Xtext resource
ByteArrayOutputStream out = new ByteArrayOutputStream();
xtextVirtualResource.save(out, Collections.emptyMap());
xtextVirtualResource.reparse(new String(out.toByteArray()));
return xtextVirtualResource;
}
In my Scoping provider I only inserted one case, because I use some primitive EClassifiers (EString, EInt, EDouble...) from the EcorePackage.eINSTANCE as reference in my project. So PrimitiveDatatypes.getPrimitivesEClassifiers
returns them in a List
override getScope(EObject context, EReference reference) {
if (reference == DatatypesPackage.eINSTANCE.variable_EType) {
return MultimapBasedScope.createScope(super.getScope(context, reference),
Scopes.scopeFor(PrimitiveDatatypes.getPrimitivesEClassifiers).allElements, false)
}
The Xtext grammar was created based on an ecore model.
The relevant part looks like this:
Wrapper returns wrapper::Wrapper:
{wrapper::Wrapper}
(name=EString)?
'{'
('ModulWrappers' '{' ModulWrappers+=ModulWrapper ( "," ModulWrappers+=ModulWrapper)* '}' )?
'}';
ModulWrapper returns wrapper::ModulWrapper:
{wrapper::ModulWrapper}
(name=EString)?
'{'
('Connectors' '{' connectors+=WrapperConnector ( "," connectors+=WrapperConnector)* '}' )?
'}';
WrapperFunction returns wrapper::WrapperFunction:
{wrapper::WrapperFunction}
(name=EString)?
'Input' ':'
(inputVars+=[wrapper::VariablePort|EString])?
'Output' ':'
(outputVars+=[wrapper::VariablePort|EString])?
('inputVars' '(' inputVars+=[wrapper::VariablePort|EString] ( "," inputVars+=[wrapper::VariablePort|EString])* ')' )?
('outputVars' '(' outputVars+=[wrapper::VariablePort|EString] ( "," outputVars+=[wrapper::VariablePort|EString])* ')' )?
'}';
VariablePort returns wrapper::VariablePort:
{wrapper::VariablePort}
(name=EString)?
'{'
('attribute' attribute=[datatypes::Attribute|EString])?
('direction' direction=[wrapper::WrapperConnector|EString])?
'}';
WrapperConnector returns wrapper::WrapperConnector:
WrapperFunction | VariablePort
;
Now if I try to create a XtextResource my Wrapperfunction gets surprisingly serialized to a Modulwrapper:
I fromatted the Wrapper Object in the original resource :
0: Wrapper {
cref ModulWrapper ModulWrappers [
0: ModulWrapper {
cref WrapperConnector connectors [
0: VariablePort {
attr EString name 'w_DWord'
ref Attribute attribute ref: Attribute@//@DeskAreas.0/@FunctionGroups.0/@Wrapper.0/@Modul/@Aktors.0/@attributes.0
}
1: WrapperFunction {
attr EString name 'WrapperFunc_1'
}
]
}
]
}
]
and the same node formatted from the XtextResource after serialization:
0: Wrapper {
cref ModulWrapper ModulWrappers [
0: ModulWrapper {
cref WrapperConnector connectors [
0: VariablePort {
attr EString name 'w_DWord'
ref Attribute attribute ref: Attribute@(unresolved proxy platform:/resource/ilm.example/Test.mfa#|3)
}
]
}
/*this is wrong!!*/
1: ModulWrapper {
attr EString name 'WrapperFunc_1'
}
]
}
]
}
So the WrapperFunction is now indeed a ModulWrapper...
I have absolutly no idea why this happens...
What did I miss?
Many thanks in advance