Skip to main content



      Home
Home » Modeling » TMF (Xtext) » IQualifiedNameProvider: using referenced objects to calculate elements name?!(Getting a "cyclic resolution of lazy links")
IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #528743] Wed, 21 April 2010 11:48 Go to next message
Eclipse UserFriend
My DSL has an Element whose name is derived from the name of a referenced element.

In xtext 0.7.2 this was no problem. Now in xtext 1.0.0 this doesn't work any more because of the mentioned "cyclic resolution".

How can i circumvent this?

Service:
	....
	entity=[Entity]


public class MyQualifiedNameProvider extends SimpleNameProvider {
	
	public String getQualifiedName(EObject e) {
		if(e instanceof Service){			
			return (Service)e).getEntity().getName()+"Service";
		}
		return super.getQualifiedName(e);
	}
}
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #528811 is a reply to message #528743] Wed, 21 April 2010 16:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi Eckle,

two possible solutions come into my mind:
1) You could implement a sort of two-phase IResourceDescription.Manager
that handles this use case properly.
2) Assuming you use simple names and the simple name of the entity is
used to link it, you could traverse the node model
(NodeUtil.getNode(service)) to compute the entity's name before the link
is actually established.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 21.04.10 17:48, schrieb Eckle:
> My DSL has an Element whose name is derived from the name of a
> referenced element.
>
> In xtext 0.7.2 this was no problem. Now in xtext 1.0.0 this doesn't work
> any more because of the mentioned "cyclic resolution".
>
> How can i circumvent this?
>
>
> Service:
> ....
> entity=[Entity]
>
>
>
> public class MyQualifiedNameProvider extends SimpleNameProvider {
>
> public String getQualifiedName(EObject e) {
> if(e instanceof Service){
> return (Service)e).getEntity().getName()+"Service";
> }
> return super.getQualifiedName(e);
> }
> }
>
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #528846 is a reply to message #528743] Thu, 22 April 2010 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Thank you, No 2 does the thing.
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #540664 is a reply to message #528846] Wed, 16 June 2010 18:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I have a similar problem, could you please tell me, where you are traversing the tree to set the name?
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #541501 is a reply to message #528743] Mon, 21 June 2010 07:44 Go to previous messageGo to next message
Eclipse UserFriend
actualy i assemble full qualified names (no longer simple names). This is done in the QualifiedNameProvider. There the method looks like
String qualifiedName(YOURELEMENTINQUESTION x) {
   //       return assembled name
    }

and does nothing than to call a helper method that proviedes the name from the given element in question and the EStructuralFeature that should be used.

Mainly i used NodeUtil.getNodeAdapter(element).getParserNode() and NodeUtil.findNodesForFeature(element, feature) to get the appropriate nodes.

Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #541611 is a reply to message #541501] Mon, 21 June 2010 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Ok, thank you.

Am 21.06.2010 13:44, schrieb Eckle:
> actualy i assemble full qualified names (no longer simple names). This
> is done in the QualifiedNameProvider. There the method looks like
> String qualifiedName(YOURELEMENTINQUESTION x) {
> // return assembled name
> }
> and does nothing than to call a helper method that proviedes the name
> from the given element in question and the EStructuralFeature that
> should be used.
>
> Mainly i used NodeUtil.getNodeAdapter(element).getParserNode() and
> NodeUtil.findNodesForFeature(element, feature) to get the appropriate
> nodes.
>
>
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #550784 is a reply to message #540664] Wed, 04 August 2010 06:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I had a similar problem and I implemented what was stated here for things to work.

Initially for a novice like myself I found the solution cryptic. Hence I have put down detailed steps (detailing the same solution) below

Define a new class with method mentioned below
public class <Module>QualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	public String qualifiedName(<OBJECT_THAT_DOES_NOT_HAVE_NAME> service) {
// OBJECT_THAT_DOES_NOT_HAVE_NAME = Service class as per the example in this thread.
		if (service != null) {
			EStructuralFeature eStructuralFeature = service.eClass().getEStructuralFeature(<Module>PackageImpl.SERVICE_REFERENCE__ENTITY);
//SERVICE_REFERENCE__ENTITY is the ID of the structural feature. Have a look at <Module>PackageImpl class to see which is the appropriate id for you.
			List<AbstractNode> nodes = NodeUtil.findNodesForFeature(service, eStructuralFeature);
			return nodes.get(0).getLeafNodes().get(1).getText();
// I found the name that I was looking for in the above path. Not sure whether it would be different for others. The basic crux being that name has to be retrieved from the nodes list only.
		}
		return null;
	}
}


Finally, bind your new QualifiedNameProvider
public class <Module>RuntimeModule extends Abstract<Module>RuntimeModule {
	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return <Module>QualifiedNameProvider.class;
	}
}


Thanks.
Regards,
- Nimesh
Re: IQualifiedNameProvider: using referenced objects to calculate elements name?! [message #889030 is a reply to message #541611] Mon, 18 June 2012 18:19 Go to previous message
Eclipse UserFriend
Bug 382266 (I'm not allowed to post links yet) is an enhancement request for this to be more clearly explained in the doc - vote for it! Razz
Previous Topic:Xtext grammar from an existing ecore metamodel, programmatically setting required features
Next Topic:Please help me with my grammer
Goto Forum:
  


Current Time: Fri Jul 04 05:05:48 EDT 2025

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

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

Back to the top