Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Warnings in generated code for model package
Warnings in generated code for model package [message #420434] Mon, 30 June 2008 13:53 Go to next message
Pete Ellis is currently offline Pete EllisFriend
Messages: 85
Registered: July 2009
Member
Hello everyone,

With the move to EMF 2.3, generated model code now results in warnings in
the package interface. An interface called "Literals" is added to the
package interface that reuses the names of attributes from the package
itself to define literals corresponding to all of the model's meta objects.
For example:

interface Literals {
EClass DATA_ELEMENT = eINSTANCE.getDataElement();
}

Each and every entry in the Literals interface gets flagged with a warning
indicating, for example, "The field XyzPackage.Literals.DATA_ELEMENT is
hiding a field from type XyzPackage".

Obviously, it is preferable for the automatically generated model code to
come through error/warning free... :)

It is curious, however... since one would have to get to those fields
explicitly via XyzPackage.Literals.DATA_ELEMENT, which is clearly different
and distinct from XyzPackage.DATA_ELEMENT, I'm not sure why the warning is
getting generated at all...

Any insights here would be appreciated. Thanks!

-Pete
Re: Warnings in generated code for model package [message #420445 is a reply to message #420434] Mon, 30 June 2008 16:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Pete,

Comments below.

Pete Ellis wrote:
> Hello everyone,
>
> With the move to EMF 2.3, generated model code now results in warnings in
> the package interface. An interface called "Literals" is added to the
> package interface that reuses the names of attributes from the package
> itself to define literals corresponding to all of the model's meta objects.
> For example:
>
> interface Literals {
> EClass DATA_ELEMENT = eINSTANCE.getDataElement();
> }
>
> Each and every entry in the Literals interface gets flagged with a warning
> indicating, for example, "The field XyzPackage.Literals.DATA_ELEMENT is
> hiding a field from type XyzPackage".
>
> Obviously, it is preferable for the automatically generated model code to
> come through error/warning free... :)
>
> It is curious, however... since one would have to get to those fields
> explicitly via XyzPackage.Literals.DATA_ELEMENT, which is clearly different
> and distinct from XyzPackage.DATA_ELEMENT, I'm not sure why the warning is
> getting generated at all...
>
It's possible to turn the literals interface off in the GenPackage
options, but it's kind of a nice to have thing for efficient access to
the Ecore metadata. It's basically complaining that within the Literals
interface itself the numeric constants of the containing interface are
already visible. Who cares, is my thought, given that all the clients
will access it in a qualified way...
> Any insights here would be appreciated. Thanks!
>
You could turn that warning off, or I think you could even add an
@SuppressWarning("...") to the Literals interface to turn that warning
off only in that context; regeneration won't remove Annotations, so
maybe that's the best approach.
> -Pete
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Warnings in generated code for model package [message #420471 is a reply to message #420445] Tue, 01 July 2008 12:13 Go to previous messageGo to next message
Pete Ellis is currently offline Pete EllisFriend
Messages: 85
Registered: July 2009
Member
Ed -

Thanks; seems like the @SuppressWarnings is the work-around for the time
being.

It is interesting as well that such warnings are generated based on the
*possibility* of attribute hiding... there are NO cases, as you know, in the
Literals interface in which any of the attributes are accessed, thus nothing
is *actually* being hidden... seems like the warning should be placed on
statements that use the attributes that are subject to being hidden, not the
attributes themselves (in which case the Package interface that is generated
would emerge warning-free)... a topic for a different newsgroup I suppose.

Thanks again for the feedback,
-Pete
Re: Warnings in generated code for model package [message #420474 is a reply to message #420471] Tue, 01 July 2008 12:24 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040800000607000800010509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Pete,

JDT has lots of warnings that are just based on style preferences.
Here's one someone reported just now but that I won't fix:

239107 <https://bugs.eclipse.org/bugs/show_bug.cgi?id=239107>

Since Java will always have rules for which specific name will be
resolved, this particular issue is more about potential problems than
actual ones. I agree with your assessment though. It might be better
to have this warning show up only in situations where the referenced
name could refer to something else that's also visible without
qualification...


Pete Ellis wrote:
> Ed -
>
> Thanks; seems like the @SuppressWarnings is the work-around for the time
> being.
>
> It is interesting as well that such warnings are generated based on the
> *possibility* of attribute hiding... there are NO cases, as you know, in the
> Literals interface in which any of the attributes are accessed, thus nothing
> is *actually* being hidden... seems like the warning should be placed on
> statements that use the attributes that are subject to being hidden, not the
> attributes themselves (in which case the Package interface that is generated
> would emerge warning-free)... a topic for a different newsgroup I suppose.
>
> Thanks again for the feedback,
> -Pete
>
>
>

--------------040800000607000800010509
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Pete,<br>
<br>
JDT has lots of warnings that are just based on style preferences.&nbsp;
Here's one someone reported just now but that I won't fix:<br>
<blockquote><a name="b239107"
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=239107">239107</a><br>
</blockquote>
Since Java will always have rules for which specific name will be
resolved, this particular issue is more about potential problems than
actual ones.&nbsp; I agree with your assessment though.&nbsp; It might be better
to have this warning show up only in situations where the referenced
name could refer to something else that's also visible without
qualification...<br>
<br>
<br>
Pete Ellis wrote:
<blockquote cite="mid:g4d6ut$ts1$1@build.eclipse.org" type="cite">
<pre wrap="">Ed -

Thanks; seems like the @SuppressWarnings is the work-around for the time
being.

It is interesting as well that such warnings are generated based on the
*possibility* of attribute hiding... there are NO cases, as you know, in the
Literals interface in which any of the attributes are accessed, thus nothing
is *actually* being hidden... seems like the warning should be placed on
statements that use the attributes that are subject to being hidden, not the
attributes themselves (in which case the Package interface that is generated
would emerge warning-free)... a topic for a different newsgroup I suppose.

Thanks again for the feedback,
-Pete


</pre>
</blockquote>
</body>
</html>

--------------040800000607000800010509--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to use XMLResource.load(Node node, ...) to load an Ecore model
Next Topic:load resource while launching plug gin
Goto Forum:
  


Current Time: Thu Apr 25 19:31:31 GMT 2024

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

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

Back to the top