|
Re: What's illegal about '$'? [message #1732068 is a reply to message #1732067] |
Thu, 12 May 2016 12:15 |
|
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 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Christian W. Damus wrote on Thu, 12 May 2016 14:15Hi, 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 #1732095 is a reply to message #1732084] |
Thu, 12 May 2016 14:25 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Felix Dorner wrote on Thu, 12 May 2016 15:11On 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:33Hi
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01533 seconds