Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolving Crossreferences in Eclipse context
Resolving Crossreferences in Eclipse context [message #985460] Thu, 15 November 2012 12:12 Go to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
I'd like to resolve crossreferences across multiple files in my DSL to display some actual values in Tooltips.

Multiple files are included with explicit include statements like in C. I have a class, that processes reads these include statements, put the referenced files in a ResourceSet and calls EcoreUtil.resolveAll() on the ResourceSet to resolve crossreferences across multiple files.

This works fine when running it Standalone after calling StandaloneSetup. When called in EObjectDocumentationProvider or anywhere else in the editor context crossreferences don't get resolved and remain as "Link<someNumbers>" in the Model.

Why does EcoreUtil.resolveAll() not work in the eclipse context and how can I resolve these crossreferences?

I'm sure, I'm doing something horribly wrong, but I haven't found the right way yet. Wink
Re: Resolving Crossreferences in Eclipse context [message #985513 is a reply to message #985460] Thu, 15 November 2012 13:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6385
Registered: July 2009
Senior Member
Hi how do you get the resource set. ?

--
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: Resolving Crossreferences in Eclipse context [message #985545 is a reply to message #985513] Thu, 15 November 2012 13:35 Go to previous messageGo to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
It's a bit messy. Maybe I need to clean that up...

List<Resource> result = new ArrayList<Resource>();
URI rootFile = URI.createFileURI(filename);
Resource rootResource = null;
ResourceSet rs = new ResourceSetImpl();
rootResource = rs.getResource(rootFile, true);

<recursion that adds imported files to result>

result.add(0, rootResource);
ResourceSet resourceSet = new ResourceSetImpl();
for(Resource resource : result) {
	resourceSet.getResource(resource.getURI(), true);
}
EcoreUtil.resolveAll(resourceSet);


I hope that's all of the relevant lines.
Re: Resolving Crossreferences in Eclipse context [message #985547 is a reply to message #985545] Thu, 15 November 2012 13:38 Go to previous messageGo to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
I forgot... the List<Resource> is returned in a Variable resources and then this happens:
		List<Resource> resources = createResources(filename);
		if (resources != null) {
			ResourceSet resourceSet = new ResourceSetImpl();
			for(Resource resource : resources) {
				resourceSet.getResource(resource.getURI(), true);
			}
			EcoreUtil.resolveAll(resourceSet);


I really need to clean up this mess...
Re: Resolving Crossreferences in Eclipse context [message #985567 is a reply to message #985545] Thu, 15 November 2012 13:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6385
Registered: July 2009
Senior Member
Use Iresourcesetprovider to get the resourceset

--
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: Resolving Crossreferences in Eclipse context [message #985641 is a reply to message #985567] Thu, 15 November 2012 15:15 Go to previous messageGo to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
ok, I used

IResourceSetProvider resourceSetProvider;
ResourceSet resourceSet = resourceSetProvider.get(ResourcesPlugin.getWorkspace().getRoot().getProject());

to initialize the ResourceSet but the references still don't get resolved. Have I used IResourceSetProvider correctly?
Re: Resolving Crossreferences in Eclipse context [message #985648 is a reply to message #985641] Thu, 15 November 2012 15:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6385
Registered: July 2009
Senior Member
Can you give more Context? How where do you call the stuff. Are you
sure you use the right project?

--
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: Resolving Crossreferences in Eclipse context [message #986271 is a reply to message #985460] Mon, 19 November 2012 16:48 Go to previous message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
I got it...

Here's something for others that have this problem:
To get the resourceSet from a URI:
IResourceSet resourceSet = null;
if (resourceSetProvider != null) {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	String s = uri.isPlatformResource() ? uri.toPlatformString(true) : uri.toString();
	IPath path = new Path(s);
	IResource resource = workspace.getRoot().getFile(path);
	IProject project = null == resource ? null : resource.getProject();
	resourceSet = resourceSetProvider.get(project==null?);
}else{
	resourceSet = new ResourceSetImpl();
}

The ResourceSetProvider can be initialized by Guice. By supplying (optional = true) it will be null when running standalone, thus explaining the if-clause above.
(optional = true)
IResourceSetProvider resourceSetProvider;


If this solution is stupid, please tell me...
Previous Topic:Functions with parameter types
Next Topic:Scoping and cross-references
Goto Forum:
  


Current Time: Thu Oct 23 11:14:01 GMT 2014

Powered by FUDForum. Page generated in 0.03303 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software