Skip to main content


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 08:52 Go to next message
Davide Poletti is currently offline Davide PolettiFriend
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 08:59]

Report message to a moderator

Re: JvmTypesBuilder generate final parameters [message #1002304 is a reply to message #1002252] Fri, 18 January 2013 11:04 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
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 12:06 Go to previous message
Davide Poletti is currently offline Davide PolettiFriend
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: Fri Apr 26 23:29:34 GMT 2024

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

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

Back to the top