Accessing other models during validation [message #912190] |
Thu, 13 September 2012 01:35  |
Eclipse User |
|
|
|
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 01:46] by Moderator
|
|
|
|
|
|
|
|
|
Re: Accessing other models during validation [message #912287 is a reply to message #912278] |
Thu, 13 September 2012 05:09  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04281 seconds