Referencing UML from an Xtext DSL - handling incomplete qualified names [message #1386902] |
Sun, 22 June 2014 17:37  |
Eclipse User |
|
|
|
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 #1393275 is a reply to message #1391254] |
Thu, 03 July 2014 10:34  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.08501 seconds