Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » What's illegal about '$'?
What's illegal about '$'? [message #1732067] Thu, 12 May 2016 11:52 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
In one of my models I have an enum-typed attribute with "optional" semantics. For this I need a dedicated "none" value in the corresponding enum type. Some time ago I chose "$none$" as the name for that enum constant, to clearly mark that this is not a normal value.

Since some update, EMF started to complain "The name '$none$' is not well formed".

Why is this reported?

Given that the enum is part of my API, how can I avoid the validation error while keeping that definition?

thanks,
Stephan
Re: What's illegal about '$'? [message #1732068 is a reply to message #1732067] Thu, 12 May 2016 12:15 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Stephan,

That enum value cannot be generated as a Java name because the '$' is
reserved by Java for inner classes and synthetics.

Note that Ecore does let you specify different values for the enum
literal and name. So, perhaps you can leave the literal as '$none$'
for serialization compatibility and set a name that Java will accept
for code generation.

HTH,

Christian


On 2016-05-12 11:52:48 +0000, Stephan Herrmann said:

> In one of my models I have an enum-typed attribute with "optional"
> semantics. For this I need a dedicated "none" value in the
> corresponding enum type. Some time ago I chose "$none$" as the name for
> that enum constant, to clearly mark that this is not a normal value.
>
> Since some update, EMF started to complain "The name '$none$' is not
> well formed".
>
> Why is this reported?
>
> Given that the enum is part of my API, how can I avoid the validation
> error while keeping that definition?
>
> thanks,
> Stephan
Re: What's illegal about '$'? [message #1732076 is a reply to message #1732068] Thu, 12 May 2016 13:01 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Christian W. Damus wrote on Thu, 12 May 2016 14:15
Hi, Stephan,

That enum value cannot be generated as a Java name because the '$' is
reserved by Java for inner classes and synthetics.


Thanks, but no: '$' is a valid letter for Java identifiers. It just "shouldn't" be used in hand-written code. And that's exactly what I'm implying by this naming.

Quote:

Note that Ecore does let you specify different values for the enum
literal and name. So, perhaps you can leave the literal as '$none$'
for serialization compatibility and set a name that Java will accept
for code generation.


In my case it's not about serialization, but about the generated Java enum, which has a constant $NONE$ (which the java compiler happily accepts).

Now, by my own reasoning, this constant "should" not be used in client code, but I have no control over that. I'd hate to break any clients due to such a non-issue.

The question remains: why is EMF complaining about an identifier which is perfectly fine in Java? I'd be fine with a warning, but an error (in a place where a previous version of EMF did not report anything) looks wrong to me. What well-formedness rules are being applied here?

best,
Stephan


Re: What's illegal about '$'? [message #1732084 is a reply to message #1732076] Thu, 12 May 2016 13:11 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
On 12-May-16 15:01, Stephan Herrmann wrote:

> The question remains: why is EMF complaining about an identifier which
> is perfectly fine in Java?

Ask 100 Java devs if they can use $ and 99 will say no..

I'd be fine with a warning, but an error (in
> a place where a previous version of EMF did not report anything) looks
> wrong to me. What well-formedness rules are being applied here?

Code is here:
http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EcoreValidator.java#n1909

Looks like $ is explicitly added to the list of invalid things, no idea
why..
Re: What's illegal about '$'? [message #1732087 is a reply to message #1732084] Thu, 12 May 2016 13:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It's all 'explained' in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=459697, so it changed in Mars.

My understanding of Ecore's Java generation is that it supports
generation of a useful Java representation for a sensible model. It is
not an abstraction that supports generation of corner-case Java, so
excluding $ by default is appropriate even if some experts may know better.

In this case it might be helpful for a genmodel option to suppress the
error.

In other cases such as contrived name collisions between auto-generated
getXXX and manually added getXXX to achieve interesting virtual
functionality, Ecore is likely to remain inadequate for 'expert's.

Regards

Ed Willink


On 12/05/2016 14:11, Felix Dorner wrote:
> On 12-May-16 15:01, Stephan Herrmann wrote:
>
>> The question remains: why is EMF complaining about an identifier which
>> is perfectly fine in Java?
>
> Ask 100 Java devs if they can use $ and 99 will say no..
>
> I'd be fine with a warning, but an error (in
>> a place where a previous version of EMF did not report anything) looks
>> wrong to me. What well-formedness rules are being applied here?
>
> Code is here:
> http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EcoreValidator.java#n1909
>
> Looks like $ is explicitly added to the list of invalid things, no
> idea why..
>
>
>
>
Re: What's illegal about '$'? [message #1732095 is a reply to message #1732084] Thu, 12 May 2016 14:25 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Felix Dorner wrote on Thu, 12 May 2016 15:11
On 12-May-16 15:01, Stephan Herrmann wrote:

> The question remains: why is EMF complaining about an identifier which
> is perfectly fine in Java?

Ask 100 Java devs if they can use $ and 99 will say no..


likely, and the one who will say yes probably is a tool developer.
Actually, I thought tool developers are the (main) target audience for direct EMF usage ...

Ed Willink wrote on Thu, 12 May 2016 15:33
Hi

It's all 'explained' in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=459697, so it changed in Mars.


Thanks for the reference. And so I'm late complaining ...

Quote:
In this case it might be helpful for a genmodel option to suppress the error.


Definitely!

Isn't raising a new, unsuppressable error always a strong statement, likely to break some unexpected but successful usage downstream?

Luckily, I can still generate code that works from this "illegal" model ;P

best,
Stephan
Re: What's illegal about '$'? [message #1732097 is a reply to message #1732095] Thu, 12 May 2016 14:42 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
On 12-May-16 16:25, Stephan Herrmann wrote:

> likely, and the one who will say yes probably is a tool developer.
> Actually, I thought tool developers are the (main) target audience for
> direct EMF usage ...

Ok bad joke: There's no $$$$ in tool development!
Re: What's illegal about '$'? [message #1732099 is a reply to message #1732097] Thu, 12 May 2016 14:56 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Felix Dorner wrote on Thu, 12 May 2016 16:42

Ok bad joke: There's no $$$$ in tool development!


Very Happy
Previous Topic:ResourceSet referencing existing, loaded Resources
Next Topic:Problem with SubstringValue EMF Query 1.7.0
Goto Forum:
  


Current Time: Fri Apr 19 04:44:43 GMT 2024

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

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

Back to the top