Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Deriving qualified names
Deriving qualified names [message #663300] Mon, 04 April 2011 15:03 Go to next message
Alex Shterev is currently offline Alex ShterevFriend
Messages: 20
Registered: April 2010
Junior Member
Hi everybody,

I need to write a wrapper concept and I'm considering using a custom
qualified name provider to set the name of the wrapper to the respective
name of the target element.
I'll be grateful if you could share your experience with this sort of
thing :)


Here's what I mean:


My grammar:
------------

Wrapper:
'Wrapper' object=[external::Foo|QualifiedName] ':'
value1=STRING
value2=STRING
...
;

Foo:
'Foo' name=ID
;


Test:
name=ID
'includes' wrappers+=[Wrapper] (',' wrappers+=[Wrapper])*
;
-------------

To avoid confusion by introducing yet another object type, I thought it
would be nice if the Wrapper objects would be automatically accessible
by the name of their respective Foo objects e.g.:

Example:
-----------------

Foo myRefObject
Foo aNewObject

Wrapper myRefObject:
value1 = 'test'
value2 = 'test'

Wrapper aNewObject:
value1 = 'test'
value2 = 'test'

Test sample includes myRefObject, aNewObject
-----------------

I already did this by impementing a custom qualified name provider, but
then I had a bit of problems in the default scope provider - apparently
the Wrapper objects weren't added to the Xtext index:

resourceDescription.getExportedObjects(MyDslPackage.eINSTANC E.getWrapper())

returned an empty result set.
After writing my own scope provider I got it working, but now I'm
wondering if there would be any further complications along the way. Is
it a good idea to have 2 elements (of different types, of course) with
the same qualified name? My backup solution would be to add a prefix to
the wrapped instances, such as "wrapped_myRefObject".


Cheers,
Alex


P.S. I'm using Xtext 1.0.1 with Helios
Re: Deriving qualified names [message #663345 is a reply to message #663300] Mon, 04 April 2011 17:30 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

by default, only elements that have a name are exported and by default only elements that have a "name" feature have a name. The simplest solution for you would be to implement a IQualifiedNameProvider (as you suggest yourself), extending the DefaultDeclarativeQualifiedNameProvider. In the method qualifiedName(Wrapper p) you return the qualifiedName calculated for the referenced object. Adapting the scope provider is not necessary, then.
(there may be typos in the above names, so please debug that the code you implement is actually called, and don't forget binding the name provider in the runtime module).

In your grammar you will also need to refer to the Wrappers via a QualifiedName ([Wrapper] is short for [Wrapper|ID], so that you could refer to wrappers only by a simple name).

I haven't tried it, but I don't think there are problems with elements of different type having the same qualified name, provided they don't have a common super type, which you use for referencing them.

Alex
Previous Topic:[xtend2][xbase] Reference to constants
Next Topic:[xtext 2] Testing imports/cross references
Goto Forum:
  


Current Time: Wed Apr 24 22:43:47 GMT 2024

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

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

Back to the top