Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmTypesBuilder generate final parameters
JvmTypesBuilder generate final parameters [message #1002252] Fri, 18 January 2013 03:52 Go to next message
Davide Poletti is currently offline Davide Poletti
Messages: 4
Registered: August 2009
Junior Member
Im'm tring to generate, using the Xtend Xbase API, a simple Java mathod.
This is the Xtend code.

var jvmMethod = element.toMethod("fromSap",element.newTypeRef(element.dtoFullName))[
						var jvmTypeReference= fromSap.sapType;
						
						var param = toParameter("sapOb",jvmTypeReference)
						parameters+=param
						body = ['''....''')]



everything works fine except the parameter that has the final modifier.
This is the generated code:

public class DTOTest {
  public DTOTest fromSap(final String sapOb) {
    DTOTest result = new DTOTest();
    return result;
    
  }
}



I tried to add:

	param.setFinal(false);

but I got

This expression is not allowed in this context, since it doesn't cause any side effects.


at compile time

Can someone help me to remove the final modifier from the generated code?

Davide

[Updated on: Fri, 18 January 2013 03:59]

Report message to a moderator

Re: JvmTypesBuilder generate final parameters [message #1002304 is a reply to message #1002252] Fri, 18 January 2013 06:04 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Davide,

parameters are considered to be final in the linking / scoping of the
expression that are contained in your method. If they weren't final,
none of the could be used from within lambda expressions. Unfortunately
there is no means of 'final' in the reflective API (java.lang.reflect)
for parameters. Therefore no property 'isFinal' can be exposed. Why do
you want to generate non-final parameters in the first place?

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 18.01.13 09:52, schrieb Davide Poletti:
> Im'm tring to generate, using the Xtend Xbase API, a simple Java mathod.
> This is the Xtend code.
>
> var jvmMethod =
> element.toMethod("fromSap",element.newTypeRef(element.dtoFullName))[
> var jvmTypeReference= fromSap.sapType;
>
> var param = toParameter("sapOb",jvmTypeReference)
> parameters+=param
> body = ['''....''')]
>
>
>
> everything works fine except the parameter that has the final modifier.
> This is the generated code:
>
> public class DTOTest {
> public DTOTest fromSap(final String sapOb) {
> DTOTest result = new DTOTest();
> return result;
> }
> }
>
>
> I tried to add:
> param.setFinal(false);
>
> but I got
>
> This expression is not allowed in this context, since it doesn't cause
> any side effects.
>
>
> at compile time
>
> Davide
>
Re: JvmTypesBuilder generate final parameters [message #1002326 is a reply to message #1002304] Fri, 18 January 2013 07:06 Go to previous message
Davide Poletti is currently offline Davide Poletti
Messages: 4
Registered: August 2009
Junior Member
Actually there is no problem and I even find out that declaring parameters as final is even a good practice .

It looked only strange to me that there was no possibility to change this behaviour.

Thanks

Davide
Previous Topic:How to trigger the serializer on existing EMF model?
Next Topic:Setting linking diagnostics to ignore?
Goto Forum:
  


Current Time: Tue Jul 29 08:58:37 EDT 2014

Powered by FUDForum. Page generated in 0.02137 seconds