Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referencing UML from an Xtext DSL - handling incomplete qualified names
Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1386902] Sun, 22 June 2014 21:37 Go to next message
Stefan Mijatov is currently offline Stefan MijatovFriend
Messages: 59
Registered: March 2010
Location: Vienna, Austria
Member
When using import statements for referencing elements from another DSL, such as UML, only references of the top level (those which are at the same level as import statements) have the benefit from those import statements.

It means all the nested elements naturally get the qualified name starting from its parent that was imported. For instance, if I import a package with some class, I can declare the reference to that class with just its simple name, and the resolution will nicely work later. However, to refer to a property of that class, a qualified name of that property is composed of the name of the owner class and the name of the property itself.

This is normal and expected, however, I would like to use the simple name of the property (composed of only the name of the property) and when resolving the reference, use the reference to the class to compile the whole qualified name of the property.

To make my problem more clear, I provide a following example:

import somePackage.*
myDslElement ofType SomeClass { attribute SomeClass.someAttribute = 'aStringValue'}

So in this example I have to use SomeClass.someAttribute, in order for resolving the references to work.. How do I enable nesting the references and then make a qualified name of a reference based on its nesting?

What I want to achieve is this:

import somePackage.*
myDslElement ofType SomeClass { attribute someAttribute = 'aStringValue'}

I thought QualifiedNameProvider can solve this, however, in the QualifiedNameProvider class we only have access to the UML elements, and not the elements of the DSL referencing the UML model..
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1386903 is a reply to message #1386902] Sun, 22 June 2014 22:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

now i get your problem. why dont you do explicit scoping for the nested stuff

(Pseudo Code)

IScope scope_AttributeContainer_attribute(AttributeContainer ctx, Ereference r) {
    Scopes.scopeFor(ctx.getClass.getAttributes()
}


otherwise you would have to adapt org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getLocalElementsScope(IScope, EObject, EReference)
which may not be that easy


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1391254 is a reply to message #1386903] Mon, 30 June 2014 16:51 Go to previous messageGo to next message
Stefan Mijatov is currently offline Stefan MijatovFriend
Messages: 59
Registered: March 2010
Location: Vienna, Austria
Member
Is it s hard to understand what I am asking? Smile
My problem is not scoping but qualified name resolution when loading the model!

I want to show only simple names of UML elements in the editor (QualifiedNameProvider is responsible for this) and then when the resolution is invoked (EcoreUtil.resolve()) somehow build complete qualified names, and not simple ones, in order to have correct resolution..

[Updated on: Mon, 30 June 2014 16:55]

Report message to a moderator

Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1391603 is a reply to message #1391254] Tue, 01 July 2014 06:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Then why not use a Iqualifiednameprovider that produces simple names?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1391604 is a reply to message #1391603] Tue, 01 July 2014 06:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
.s. A grammar example would help. And your scoping implementation.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1391605 is a reply to message #1391604] Tue, 01 July 2014 06:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Pps and have a look at the scopes.scopefor methods and how the do qualifiednname calculation

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1391608 is a reply to message #1391605] Tue, 01 July 2014 06:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Alternative you can hook implicit import calculation in the importednamespaceawarelocalscopeprovider but this is pita compared to simply adapt scoping as I sugested

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1393275 is a reply to message #1391254] Thu, 03 July 2014 14:34 Go to previous message
Mary P. is currently offline Mary P.Friend
Messages: 48
Registered: November 2012
Member
Hello,
It seems like I had a similar issue but with the Operations of the Classes.

I have a reference to UML Operation, and its name looked like "ClassName.OperationName". What I want is simply "OperationName" without the name of the Class containing the operation.

In order to produce simple names for the Operations I implemented the following QualifiedNameProvider:

public class UmlQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	
	@Override
	public QualifiedName getFullyQualifiedName(final EObject obj) {

		QualifiedName res;
		if(obj instanceof Operation)
			res = super.getConverter().toQualifiedName(((Operation)obj).getName());
		else
			res = super.getFullyQualifiedName(obj);;
		return res;
		
	}
}


I am not sure that this will work properly for the Operations with the same names, but in my case all the names are unique.

If you have any better solution and you can share it with me, I will be very thankful.

Also, it seems like when I tested my editor, UmlQualifiedNameProvider did not work for the projects that had been created before I implemented UmlQualifiedNameProvider: the long names were still produced. But for the newly created projects, it worked fine and only simple names were generated.

Best regards,
Mary
Previous Topic:Prevent UpdateEditorStateJob and XtextBuilder from concurrent execution
Next Topic:XCore 1.1.2 not any more on updatesite
Goto Forum:
  


Current Time: Tue Apr 23 14:42:16 GMT 2024

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

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

Back to the top