Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » QualifiedNameProvider not working
QualifiedNameProvider not working [message #801037] Fri, 17 February 2012 21:00 Go to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi!

I just don't get it. I have still problems with scoping + qualified names:

Here is my grammar:
Domainmodel : elements += Type*;
Type: 
	DataType | Entity // | Identifier
;
DataType: 'datatype' id = ID 
	// (othername?='rename' otherid=[Identifier])?
;
Entity: 'entity' id = ID 
	// (othername?='rename' yetanothername=ID)?
   '{' features += Feature* '}';

Feature: name = ID ':' type = [Type];

//Identifier :
//	'identifier' id = ID
//;


Here is a scope function (XTend):

	def IScope scope_Feature_type(Feature feature, EReference eRef) {
		
		val parent = feature.getContainerOfType(typeof(Domainmodel))
		val elements = parent.elements

		return scopeFor(elements)
	}


Since I use "id" instead of "name" attributes, I change the QualifiedNameProvider (extending DefaultDeclarativeQualifiedNameProvider)

QualifiedName qualifiedName(Type e) {

	QualifiedName qfn;
	if(e instanceof DataType) {
		DataType datatype = (DataType) e;
		qfn = QualifiedName.create(datatype.getName());
	} else qfn = null; // look so far only at DataType
	
	return qfn;
}


I have bound the QualifiedNameProvider to the RuntimeModule.

The funny thing now is: if I return "null" instead of "qfn" or if I override the "getFullyQualifiedName" returning "null" again and using "name" attributes instead of "id" attributes, everything still works (I can reference to the datatype although they have a null qualified name)! How can this work?

I would be very glad about any help, since I am tired of experimenting around.

At a further step I want to add the commented lines in the grammar above - so I think, somehow the QualifiedNameProvider HAS to be used, but it does not work so far. With println-methods I saw that the qualifiedName functions were called correctly, but their return value (null or anything else didn't matter).
Re: QualifiedNameProvider not working [message #801044 is a reply to message #801037] Fri, 17 February 2012 21:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is since you customized scoping

scopeFor(elements) calls
scopeFor(elements, IScope.NULLSCOPE) calls
scopeFor(elements, QualifiedName.wrapper(SimpleAttributeResolver.NAME_RESOLVER), outer)

=> SimpleAttributeResolver.NAME_RESOLVER is used and not your nameprovider

so what you shoulf do is

@Inject IQualifiedNameProvider nameprovider

....

scopeFor(elements,nameprovider, IScope::NULLSCOPE)


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: QualifiedNameProvider not working [message #802015 is a reply to message #801044] Sun, 19 February 2012 09:02 Go to previous messageGo to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Ahh cool! Thx!

But now I follow another problem:

Here the grammer (should be almost like above):

Domainmodel : elements += Elements*;

Elements : 
	// typefeature = Type | identifierfeature = Identifier
	Type | Identifier
;

Type: 
	DataType | Entity
;

DataType: 'datatype' id = ID 
	(othername?='rename' otherid=[Identifier])?
;

Entity: 'entity' id = ID 
	(othername?='rename' yetanothername=ID)?
   '{' features += Feature* '}';

Feature: name = ID ':' type = [Type];

Identifier :
	'identifier' idid = ID
;


Now I want to get the name of the reference (otherid=[Identifier]). There are two intuitive possibilities (marked as "first try" and "second try" in the code beyond) which lead into the problems:
(1) "An internal error occurred during: "XtextReconcilerJob".
Cyclic resolution of lazy links : DataType.otherid->DataType.otherid"
(2) "An internal error occurred during: "Xtext validation".
Cyclic resolution of lazy links : DataType.otherid->DataType.otherid"

I tried the hint from Alexander Nittka here from here (at the bottom):
http://www.eclipse.org/forums/index.php/m/707310/
which lead me to the "third try" - which seems to be working, but is somehow a hack in order to overcome the cyclic resolution problem.

public class MyBlaQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {

   @Inject
   private IQualifiedNameConverter converter = new IQualifiedNameConverter.DefaultImpl();


   QualifiedName qualifiedName(DataType e) {
      // first try - cyclic resolution
      // return converter.toQualifiedName(
      //		e.isOthername()? e.getOtherid().getIdid() : e.getId());
		
      // second try - cyclic resolution
      // return e.isOthername() ?
      //       getFullyQualifiedName(e.getOtherid()) :
      //	   converter.toQualifiedName(e.getId());
		
      // third try - no cyclc resolution, but not nice since trying to go indirectly via node model
      String name = null;
      if(e.isOthername()) {
         List<INode> nodes = NodeModelUtils.findNodesForFeature(e, MyBlaPackage.Literals.DATA_TYPE__OTHERID);
         INode first = nodes.get(0);
         name = NodeModelUtils.getTokenText(first);
	} else name = e.getId();
		
	return converter.toQualifiedName(name);
}
	
   QualifiedName qualifiedName(Entity e) {
      return converter.toQualifiedName(
          e.isOthername()? e.getYetanothername() : e.getId());
      }
	
   QualifiedName qualifiedName(Identifier e) {
      return converter.toQualifiedName(e.getIdid());
   }
}


Are there other (concise and easy to implement) possibilities to get the name of a referenced object? I would prefer not to work with the NodeModelUtils, since my grammar can change and I do not get the changes directly as some kind of errors in the Nodemodel calls in contrast to if I would have worked with the code from "first try" and "second try" since changes to types or feature names are reflected directly in the code.
Re: QualifiedNameProvider not working [message #802075 is a reply to message #802015] Sun, 19 February 2012 11:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi this is a chicken and egg problem so you have to go on the node model

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 19 February 2012 11:25]

Report message to a moderator

Re: QualifiedNameProvider not working [message #884689 is a reply to message #802075] Mon, 11 June 2012 15:50 Go to previous message
Michael Vorburger is currently offline Michael VorburgerFriend
Messages: 103
Registered: July 2009
Senior Member
Thank you for pointing to NodeModelUtils.findNodesForFeature here, very useful info. FTR: I've created a new bug report issue 382266 (I can't post links here yet) suggesting this may be added to documentation.
Previous Topic:local scope, qualified name and Cyclic resolution of lazy links
Next Topic:Naming and Containment Hierarchy Issue
Goto Forum:
  


Current Time: Thu Apr 25 04:53:45 GMT 2024

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

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

Back to the top