Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to get the name of an unresolved reference(Xtext 2.0)
How to get the name of an unresolved reference [message #716587] Wed, 17 August 2011 19:11 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I would like, only for one type of object, to get the name of the unresolved cross-reference. This is related to what I wanted here: http://www.eclipse.org/forums/index.php/t/235358/

The name is always "null" for unresolved cross-references.

How could I do to override this behaviour for one type of reference? I'been searching but I haven't found anything.

As always, thanks for your help.

Re: How to get the name of an unresolved reference [message #716594 is a reply to message #716587] Wed, 17 August 2011 19:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi,

can you elaborate a bit in which context the "name" is null?
LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage
has the information about the name of the type and the text that is written in the dsl file.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get the name of an unresolved reference [message #716599 is a reply to message #716594] Wed, 17 August 2011 19:53 Go to previous messageGo to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi Christian,

Yes, I'm able to get the name in LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage and write a custom warning message.

The problem comes when I want to do the code generation: I load the object containing the unresolved reference, and then, I get the unresolved reference itself, but its method getName() returns "null".

This is a little example of the loading:

IProject iProject = ResourcesPlugin.getWorkspace().getRoot().getProject("Test");
		URI u = URI.createURI("platform:/resource/Test/test.mydsl");
		Resource resource ;

		XtextResourceSet xresourceSet = (XtextResourceSet) i     njector.getInstance(XtextResourceSetProvider.class).get(iProject);
		xresourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		resource = xresourceSet.getResource(u,true);
		EObject model = resource.getContents().get(0);
		Model m = (Model)model;
		System.out.println(m.getRef().getRef().getName()); //returns null


Thanks.
Re: How to get the name of an unresolved reference [message #716602 is a reply to message #716599] Wed, 17 August 2011 20:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi,

since the cross reference is not resolved you of course get null for every feature of this cross reference.
but there is stil the trick to access the node model to workaround this problem.

Model:
	elements+=Element*
;

Element:
	"element" name=ID ("refs" refs=[Element])?
;


Model m = (Model) r.getContents().get(0);
		Element e1 = m.getElements().get(0);
		for (INode n : NodeModelUtils.findNodesForFeature(e1, MyDslPackage.Literals.ELEMENT__REFS)) {
			System.out.println(n.getText());
		}


Please note: this will work just for the name, nor nothing else.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 17 August 2011 20:09]

Report message to a moderator

Previous Topic:Xtend generation File attributes
Next Topic:ClassCastException in OutlinePage
Goto Forum:
  


Current Time: Sun Apr 18 12:48:14 GMT 2021

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

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

Back to the top