Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Solved] Replacing an EStructuralFeature with a placeholder name in Xtext DSL
[Solved] Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1589503] Wed, 28 January 2015 08:40 Go to next message
Eclipse UserFriend
Hello,

I have a problem I couldn't find anything about, so I want to ask you.

I created a DSL where I can import an Ecore model.
From this model I reference an EClass and EOperations of that EClass using the ScopeProvider. This works perfectly fine.
But the next step is to reference EStructuralFeatures of that class. This works fine too, but I want to reference the corresponding Setters of those EStructuralFeatures. For example: the feature 'name' shall be called 'setName' in my Xtext document.

I created a simple example project for you to get a proper overview of what I want.

The grammar looks like this:
generate getterSetter "http://www.xtext.org/example/mydsl/GetterSetter"
import "http://www.eclipse.org/emf/2002/Ecore"

Model:
	imports+=Import*
	greetings+=Greeting*;

FQN:
	ID ('.' ID)*;

Import returns Import:
	'import' importURI=STRING;

Greeting:
	Operation | Setter;

Operation:
	'do' c=[EClass|FQN] '->' op=[EOperation] '(' ')';

Setter:
	'set' c=[EClass|FQN] '->' feature=[EStructuralFeature] '(' ')';



The example document looks like this:
import "railcab.ecore"

do railcab.Railcab -> start()
set railcab.Railcab -> speed()
do railcab.Railcab -> stop()


And I want the middle line to be:
set railcab.Railcab -> setSpeed()


How can I accomplish that?
Do I have to create a new NameProvider or something else?
Is this even possible?
Or are there any other helpful sources / topics I missed?

Thanks in advance,
Florian

[Updated on: Sun, 15 February 2015 13:49] by Moderator

Re: Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1589565 is a reply to message #1589503] Wed, 28 January 2015 09:21 Go to previous messageGo to next message
Eclipse UserFriend
Without having a look at your code: The Scopes.scopeFor Method has a variant which takes three Parameters - the objects, a qualifiedname function (a closure if you usw xtend) and a parent scope ( IScope.NULLSCOPE)
Re: Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1600809 is a reply to message #1589565] Wed, 04 February 2015 09:02 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian! That is exactly what I was looking for. I did not know I could simply add a qualifiedname function to the scope.
Re: Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1617842 is a reply to message #1600809] Sun, 15 February 2015 09:42 Go to previous messageGo to next message
Eclipse UserFriend
Hello again!

Another very similar problem came up to me. What I now have to do is this:

I want to reference an EOperation without the corresponding class in the model.

The document shall look like this:
import "railcab.ecore"
package railcab
op Railcab.start


and the grammar looks like this:
grammar org.xtext.example.mydsl.GetterSetter with org.eclipse.xtext.common.Terminals

generate getterSetter "http://www.xtext.org/example/mydsl/GetterSetter"
import "http://www.eclipse.org/emf/2002/Ecore"

Model:
	imports+=Import*
	('package' packages+=[EPackage])*
	operations+=Operation*;

FQN: ID ('.' ID)*;

Import returns Import:
	'import' importURI=STRING;

Operation:
	'op' op=[EOperation|FQN];


My ScopeProvider looks like this now:
var Function<EOperation, QualifiedName> getNameComputationForOperation = [
		QualifiedName::create(it.getOperationName)]

	def String getOperationName(EOperation feature) {
		return feature.EContainingClass.name + '.' + feature.name
	}

	def IScope scope_Operation_op(Operation operation, EReference ref) {
		val scope = new ArrayList<EOperation>()
		val model = operation.eContainer as Model
		model.packages.forEach[p|
			p.EClassifiers.filter(typeof(EClass)).forEach[eclass|
				scope.addAll(eclass.EOperations)
			]
		]
		return Scopes::scopeFor(scope, getNameComputationForOperation, IScope.NULLSCOPE)
	}


But this does not seem to work, because I get this error
index.php/fa/20861/0/
but the quickfix tells me that the object exists.

When I use any symbolc other than '.' it works just fine.
So what am I missing here?

Thanks in advance,
Florian
Re: Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1618033 is a reply to message #1617842] Sun, 15 February 2015 12:44 Go to previous messageGo to next message
Eclipse UserFriend
if the name consists of several junks you have to respect that.
Use iqualiednameconverter or qualifiedname.create(part1,...,partn)
Re: Replacing an EStructuralFeature with a placeholder name in Xtext DSL [message #1618101 is a reply to message #1618033] Sun, 15 February 2015 13:47 Go to previous message
Eclipse UserFriend
Thanks again Christian! I thought my code would do exactly the same thing (because of the auto corrections), so I was digging in the wrong direction with my research.
QualifiedName.create("part1.part2") does not the same as QualifiedName.create("part1", "part2").
Well thanks again Smile

[Updated on: Sun, 15 February 2015 13:48] by Moderator

Previous Topic:XtextDay San Francisco - Free and reduced tickets
Next Topic:integrate xtext with a webapplication
Goto Forum:
  


Current Time: Sat Nov 08 09:24:49 EST 2025

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

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

Back to the top