Working with Xtext enum names.

552 views
Skip to first unread message

Andrew Clark

unread,
May 13, 2014, 5:49:04 AM5/13/14
to xtend...@googlegroups.com
I am upgrading to Xtend 2.5 (from 2.4) and have notice that the new stricter compiler checks don't like Xtext(EMF) enums, specifically the names.

i.e. for a simple Xtext model

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals


Model:
foo=Foo
;
enum Foo : one | two | three ;


If I want to get the name of the enum and use auto complete in xtend.

package org.xtext.example.mydsl

import org.xtext.example.mydsl.myDsl.Model

class Foo {
def fooName (Model m){
return m.foo.name 
}

}

I get an error 

"Ambiguous feature call.
The methods
name() in Enum and
getName()
   in Foo
both match."

Easily solved by changing this to m.foo.getName , but that is ugly IMO I liked being able to use .name , and I am not clear on why Xtend finds this ambiguous.

Is there a more elegant solution or is that just the way it is now in Xtend with Xtext?

Sven Efftinge

unread,
May 13, 2014, 6:03:49 AM5/13/14
to xtend...@googlegroups.com
It is ambiguous because
 ‘name’ is a sugared way to call methods like ‘name()’, ‘isName()' or ‘getName()’

We didn’t want to introduce a precedence here, as none will ever remember that.
So if there’s an ambiguity, you cannot use the sugar. 

Sven

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Andrew Clark

unread,
May 13, 2014, 6:20:25 AM5/13/14
to xtend...@googlegroups.com
I always get upset when I don't get my sugar :-)

I can understand that it is ambiguous if getName() and name() are defined in the same class but as getName() is on Foo and name() is on Enum , I don't see why the sugar could not just choose the nearest matching method. i.e. foo is of type Foo and Foo has a matching (unambiguous) method.

If I wanted to use the Enum name explicitly I could always user foo.name() .

I assume I have not fully understood the problem, so can you enlighten me to why this would not work.

Andrew 

Sven Efftinge

unread,
May 13, 2014, 6:31:25 AM5/13/14
to xtend...@googlegroups.com
Foo implements Enum, so both methods are equally available on the receiver object “m.foo”.
Yes, you can write name() or getName() to resolve the conflict.
To avoid surprises in such cases, the compiler forces you to do so.
signature.asc
Reply all
Reply to author
Forward
0 new messages