Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Final modifier in EMF-generated methods(How to get rid of the "final" modifier in EMF-generated methods ?)
Final modifier in EMF-generated methods [message #1445156] Wed, 15 October 2014 03:58 Go to next message
Gordan Vosicki is currently offline Gordan VosickiFriend
Messages: 13
Registered: March 2013
Junior Member
An EMF ECore model can contain generated methods with a defined body (within a "body" annotation).
In some cases, the method arguments can be modifier in the method, this is perfectly legal Java code.
Unfortunately, the latest generator version (in Luna) seems to add the "final" keyword to all arguments, even if they are modified within the methos body, leading to compilation errors.

How to get rid of this "final" modifier ?
Is there an annotation which can be used to do it ?


    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void toSax(final SAXGenerator sax, final String elemTag, final Locale locale) throws SAXException {
        if (locale != null) {
            ELocalized<T> lr = getLocalized(locale);

            if (lr == null) {
                lr = getBestLocalized(locale);
            }
            if (lr != null) {
                lr.toSAX(sax);
            } else {
                locale = null;       // ***** This line causes the compilation error *****
            }
        }

        if (locale == null) {
            // There is no good locale available, leave the choice to the client !
            for (ELocalized<T> lr : objects) {
                lr.toSAX(sax);
            }
        }

    }

Re: Final modifier in EMF-generated methods [message #1445193 is a reply to message #1445156] Wed, 15 October 2014 05:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30133
Registered: July 2009
Senior Member
Gordon,

Comments below.

On 15/10/2014 5:58 AM, Gordan Vosicki wrote:
> An EMF ECore model can contain generated methods with a defined body
> (within a "body" annotation).
> In some cases, the method arguments can be modifier in the method,
> this is perfectly legal Java code.
> Unfortunately, the latest generator version (in Luna) seems to add the
> "final" keyword to all arguments, even if they are modified within the
> methos body, leading to compilation errors.
Yes, that was changed two years ago.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=390744
>
> How to get rid of this "final" modifier ?
There isn't a ways.
> Is there an annotation which can be used to do it ?
No, the problem, as you can see in the bugzilla, is that Xbase assumes
parameters are final. Given that assigning to parameters is generally
considered bad style (granted, who's the arbiter for that) it seemed
okay to simply generate all operations that way. Of course it's easy
enough to work around with a local variable (if you don't have thousands
of operation bodies that need to be rewritten. And of course we could
guard the behavior with yet another GenModel flag, but haven't already
done so...

>
>
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public void toSax(final SAXGenerator sax, final String elemTag,
> final Locale locale) throws SAXException {
> if (locale != null) {
> ELocalized<T> lr = getLocalized(locale);
>
> if (lr == null) {
> lr = getBestLocalized(locale);
> }
> if (lr != null) {
> lr.toSAX(sax);
> } else {
> locale = null; // ***** This line causes the
> compilation error *****
> }
> }
>
> if (locale == null) {
> // There is no good locale available, leave the choice to
> the client !
> for (ELocalized<T> lr : objects) {
> lr.toSAX(sax);
> }
> }
>
> }
>
>
Previous Topic:[CDO] gastro example problem
Next Topic:[CDO] OCL query fails with an SQL statement already in cache
Goto Forum:
  


Current Time: Thu May 23 06:43:47 GMT 2019

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

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

Back to the top