Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing other models during validation(Proxies and ResourceSets)
icon5.gif  Accessing other models during validation [message #912190] Thu, 13 September 2012 01:35 Go to next message
Moritz Höser is currently offline 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 01:46]

Report message to a moderator

Re: Accessing other models during validation [message #912234 is a reply to message #912190] Thu, 13 September 2012 03:18 Go to previous messageGo to next message
Moritz Höser is currently offline Moritz Höser
Messages: 11
Registered: September 2012
Junior Member
I tried another hint to resolve the proxy:

			for (IEObjectDescription od : visibleContainer.getExportedObjectsByType(SodPackage.Literals.SOD_MODEL)) {
				// References to external types not resolved :(
				SodModel sodModel = (SodModel) resourceSet.getEObject(od.getEObjectURI(), true);
				// Do validation
			}


This resolution (in the validator of DSL A) is working, but only for the "direct" features of SodModel (DSL B). References to another Entity of DSL C, which both A and B reference to, are proxies again. The linking succeeds, but I think I am accessing the resources of DSL B not the correct way in the validator of DSL A.
Re: Accessing other models during validation [message #912244 is a reply to message #912234] Thu, 13 September 2012 03:35 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6144
Registered: July 2009
Senior Member
Hi,

use the resourceset of the object you are validating not a new one.

~Christian
Re: Accessing other models during validation [message #912245 is a reply to message #912234] Thu, 13 September 2012 03:30 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6144
Registered: July 2009
Senior Member
Use the resource set of the object you are validating not a new one

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Accessing other models during validation [message #912256 is a reply to message #912244] Thu, 13 September 2012 03:54 Go to previous messageGo to next message
Moritz Höser is currently offline Moritz Höser
Messages: 11
Registered: September 2012
Junior Member
Hi,
thank you, but I thought this is what I am doing by using
@Inject
	private XtextResourceSet resourceSet;

?
Re: Accessing other models during validation [message #912266 is a reply to message #912256] Thu, 13 September 2012 04:19 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6144
Registered: July 2009
Senior Member
i meant

model.eResource().getResourceSet()
Re: Accessing other models during validation [message #912278 is a reply to message #912266] Thu, 13 September 2012 04:55 Go to previous messageGo to next message
Moritz Höser is currently offline 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 04:56]

Report message to a moderator

Re: Accessing other models during validation [message #912287 is a reply to message #912278] Thu, 13 September 2012 05:09 Go to previous message
Christian Dietrich is currently online Christian Dietrich
Messages: 6144
Registered: July 2009
Senior Member
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.
Previous Topic:Problem with contentassist antlr in ui project
Next Topic:Get a list of referencing object
Goto Forum:
  


Current Time: Thu Jul 31 07:46:14 EDT 2014

Powered by FUDForum. Page generated in 0.05754 seconds