Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmField expression initializer generates function application
JvmField expression initializer generates function application [message #1245098] Thu, 13 February 2014 09:32 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I have a DSL based on Xbase from which I infer a JvmModel including som
fields. I use the toField method and set the initializer to an
expression. Suppose the field is of type Person, the name is hallvard
and the XExpression is new Person("Hallvard", 'M'). The following is
then generated:

private Person hallvard = new Function0<Person>() {
public Person apply() {
Person _person = new Person("Hallvard", 'M');
return _person;
}
}.apply();

I would expect a simple
private Person hallvard = new Person("Hallvard", 'M')
instead of the same expression wrapped in a function.

Since the generated code will be read by humans (students), I would
prefer the simple variant. In what cases does the generator use this
complex form and what can I do to help it simplify it?

Hallvard
Re: JvmField expression initializer generates function application [message #1245217 is a reply to message #1245098] Thu, 13 February 2014 13:21 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 13/02/2014 10:32, Hallvard Trætteberg wrote:
> Hi,
>
> I have a DSL based on Xbase from which I infer a JvmModel including som
> fields. I use the toField method and set the initializer to an
> expression. Suppose the field is of type Person, the name is hallvard
> and the XExpression is new Person("Hallvard", 'M'). The following is
> then generated:
>
> private Person hallvard = new Function0<Person>() {
> public Person apply() {
> Person _person = new Person("Hallvard", 'M');
> return _person;
> }
> }.apply();
>
> I would expect a simple
> private Person hallvard = new Person("Hallvard", 'M')
> instead of the same expression wrapped in a function.
>
> Since the generated code will be read by humans (students), I would
> prefer the simple variant. In what cases does the generator use this
> complex form and what can I do to help it simplify it?

IIRC this has been implemented as you would expect in latest versions
(at least in 2.5.1), but I cannot test it right now...

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type org.eclipse.xtext.gener
Next Topic:OSS project needs help
Goto Forum:
  


Current Time: Sat Apr 27 00:49:09 GMT 2024

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

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

Back to the top