Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtext 2] Some problems with qualified names
[xtext 2] Some problems with qualified names [message #663041] Sat, 02 April 2011 16:42 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

This is really 2 questions in one shot:

1. In order to override how qualified names are created, I created my own IQualifiedNameProvider that extends DefaultDeclarativeQualifiedNameProvider. It is doing its job, as far as I can tell. The problem is that in the editor, I get errors because elements cannot be resolved (the error message is "could not resolve reference to..") In the editor, I've been trying to use both simple names and qualified names (e.g. "Name" and "mypackage.Person.Name" but it doesn't work. My guess is that I need to do something else to have this recognized, but so far, I haven't found where Sad

2. Once #1 is solved, I wonder if Xtext out of the box will resolve reference when elements in the editor are declared with simple and complex names. For example, if I type "Name" or "myPackage.Person.Name" XText will resolve both to the type Name.

Many thanks in advance,
-Alex

[Updated on: Sun, 03 April 2011 08:14]

Report message to a moderator

Re: Some problems with qualified names [message #663042 is a reply to message #663041] Sat, 02 April 2011 16:57 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

both should work without problems. can you share with a example grammar what you exacly did? btw qualified name are working out of the box and are by default constructed by the elements parents' name and the elements name:

grandparentsname.parentsname.elementsname

~Christian


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

[Updated on: Sat, 02 April 2011 18:02]

Report message to a moderator

Re: Some problems with qualified names [message #663055 is a reply to message #663042] Sat, 02 April 2011 20:25 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Christian for the reply Smile

Here is a snippet of the grammar:

Protobuf:
  (package=Package)?
  (imports+=Import)*
  (options+=Option)*
  (elements+=ProtobufElement)*;
  
Package:
  'package' name=QualifiedName ';';

QualifiedName:
  ID ('.' ID)*;

ProtobufElement:
  Type | ExtendMessage;

Type:
  Message | Enum;

Message:
  'message' name=ID '{'
  elements+=MessageElement*
  ('extensions' extensionsFrom=INT 'to' (extensionsTo=INT | 'max') ';')?
  '}';


The problem is the following:

1. 'package' should be top-parent of the qualified name (e.g. Message should include Package in the FQN)
2. 'package' is optional

In this case, I couldn't figure out how to express this in the grammar. So in the grammar, 'package' is not a parent of anybody (but it should.)

Instead, I created an IQualifiedNameProvider that does this:

  @Override public QualifiedName getFullyQualifiedName(EObject obj) {
    QualifiedName fqn = super.getFullyQualifiedName(obj);
    if (fqn == null || obj instanceof Package) return fqn;
    Package p = finder.findPackage(obj);
    if (p == null) return fqn;
    List<String> segments = new ArrayList<String>(fqn.getSegments());
    segments.add(0, p.getName());
    return QualifiedName.create(segments.toArray(new String[segments.size()]));
  }


I wouldn't be surprised if what I did was silly Very Happy

Thanks!
-Alex
Re: Some problems with qualified names [message #663059 is a reply to message #663055] Sat, 02 April 2011 21:37 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

first if you are using Xtext 2.0.0 you should mention this in your posts since Xtext 2.0.0 is still in development and there are some API changes between the versions. The current production release is Xtext 1.0.2.

I tried you reproduce your problem using Xtext 2.0.0 M6 and found following

Since your grammar lacks the actual interesing thing (the reference/the imports) i slightly modified it and ignored the importing topic.

Message:
  'message' name=ID '{'
  otherMessage=[Message|QualifiedName]
  ('extensions' extensionsFrom=INT 'to' (extensionsTo=INT | 'max') ';')?
  '}';


when binding the QNP in my runtime module
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyQNP.class;
	}
	
}


it works nice with following sample models

package other;
message b
{
	test.a
	extensions 1 to 2;
}


package test;
message a
{
	other.b
	extensions 1 to 2;
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Some problems with qualified names [message #663065 is a reply to message #663059] Sun, 03 April 2011 04:28 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Hi Christian,

Thanks so much for your help. It worked! Smile

I apologize for not specifying I'm using Xtext 2.0. I should have.

Best regards,
-Alex
Previous Topic:[xtext 2] parsing files shipped in the plug-in itself
Next Topic:[xtext 2] how to create own URI format for imports?
Goto Forum:
  


Current Time: Thu Apr 25 09:00:11 GMT 2024

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

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

Back to the top