Accessing other models during validation [message #912190] |
Thu, 13 September 2012 05:35 |
Moritz Höser Messages: 11 Registered: September 2012 |
Junior Member |
|
|
Hi all,
I am trying to access the Xtext model of another file during validation. I found several topics about this, but none of them finally worked for me.. So I would be very thankful for hints.
I have DSLs A (Cod) and B (Sod), they do not rely on each other, but A uses information from B during validation.
Following Christian's answer to validation, I read all exported Objects of a certain type. It works, but all the exported Objects return proxies, and I don't know when and how to resolve them. I need not only the qualifiedName, but some other features (Lists).
// Validator of DSL A ("Cod")
@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider;
@Inject
IContainer.Manager containerManager;
@Check
private void checkCodModel(CodModel model) {
IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(model.eResource());
IResourceDescription resourceDescription = index.getResourceDescription(model.eResource().getURI());
for (IContainer visibleContainer : containerManager.getVisibleContainers(resourceDescription, index)) {
for (IEObjectDescription od : visibleContainer.getExportedObjectsByType(SodPackage.Literals.SOD_MODEL)) {
// Proxy only :(
SodModel sodModel = (SodModel) od.getEObjectOrProxy();
// Do validation
}
}
}
So I changed the getEObjectOrProxy-line to
@Inject
private XtextResourceSet resourceSet;
// ...
for (IEObjectDescription od : visibleContainer.getExportedObjectsByType(SodPackage.Literals.SOD_MODEL)) {
// Load associated resource
URI uri = od.getEObjectURI().trimFragment();
Resource sodResource = resourceSet.getResource(uri, true);
SodModel sodModel = (SodModel) sodResource.getContents().get(0);
// Do validation
}
// ...
This works, but as the doc suggests, this solution is not aware of unsaved editor changes (and not even saved changes). What would be the intended way to access the neighbor DSL file in this case, please?
P.S. I cannot find the class XtextResourceSetProvider as suggested by Sebastian, what plugin would it be in?
[Updated on: Thu, 13 September 2012 05:46] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Accessing other models during validation [message #912278 is a reply to message #912266] |
Thu, 13 September 2012 08:55 |
Moritz Höser Messages: 11 Registered: September 2012 |
Junior Member |
|
|
Thank you very much Christian!
I changed the code to the following:
for (IEObjectDescription od : visibleContainer.getExportedObjectsByType(SodPackage.Literals.SOD_MODEL)) {
// Resolved proxy :)
SodModel sodModel = (SodModel) model.eResource().getResourceSet().getEObject(
od.getEObjectURI(), true);
// Do validation
}
and as far as I could test it, not only all of the references are resolved, but also the latest changes are processed.
Would you be so kind and give a brief explanation or reference? I can not find information about the difference between the injected ResourceSet and the model element's RS.
[Updated on: Thu, 13 September 2012 08:56] Report message to a moderator
|
|
|
Re: Accessing other models during validation [message #912287 is a reply to message #912278] |
Thu, 13 September 2012 09:09 |
|
Hi,
in the editor the resource set depends on the project to work properly (IResourceSetProvider). if you create a new one
you have to use a project specific which is tricky since validation
is a runtime and not a ui concept
=> you would need a utility that gives you the resourceset for runtime and ui
=> the easiest is to use the resourceset you already have.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.04305 seconds