Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend2 generation issue
Xtend2 generation issue [message #669883] Wed, 11 May 2011 23:40 Go to next message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Hi,

I have an Xtend class that is failing to generate into Java code, even though the Xtend class is validating without errors. I have pared down the implementation as much as I could to try to narrow in on the issue. As a result, the resulting minimal example code below may seem nonsensical, but the original purpose of the class is to walk over a UI Screen model and collect any requirements for any of its constituent Widgets.

For the purposes of this example I'm just using simple vanilla Java beans for the model classes:

import java.util.List;

public class Screen {

	private List<Widget> widgets;
	
	public List<Widget> getWidgets() {
		return widgets;
	}

}


import java.util.List;

public class Widget {

	private List<Widget> widgets;
	
	public List<Widget> getWidgets() {
		return widgets;
	}
	
}


Note that even though Screen and Widget are identical in this minimal example, in reality Widget would be the root of a hierarchy of UI widgets, some of which are containers that may contain other widgets, and Screen is not a widget because a Screen cannot be contained in a widget.

The Xtend file looks like this:

Test.xtend:
import java.util.*

class Test {
	
	requires(Screen s) {
		var requires = new LinkedHashSet<String>()
		
		for (child : s.widgets)
			requires += child.requires
		
		return requires
	}
	
	requires(Widget w) {
		var requires = new LinkedHashSet<String>()
		
		for (child : w.widgets)
			requires.addAll(child.requires)
		
		return requires
	}
}


The Xtend class as shown above fails to compile to Java. However if I comment out one of the for loops within either of the requires() methods, it will compile. I am using the 3.7M6 Xtext 2 beta from: http://blog.efftinge.de/2011/04/eclipse-xtend-beta-available .html

At this point I'm out of my depth as to how to debug the issue further, but hopefully this is enough for someone else to go on!

Thanks,
Edwin
Re: Xtend2 generation issue [message #669932 is a reply to message #669883] Thu, 12 May 2011 06:32 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Edwin,

please make sure to use the latest version. It contains a lot of fixes
compared to M6. Please file a ticket if the problem persists.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 12.05.11 01:40, schrieb Edwin Park:
> Hi,
>
> I have an Xtend class that is failing to generate into Java
> code, even though the Xtend class is validating without
> errors. I have pared down the implementation as much as I
> could to try to narrow in on the issue. As a result, the
> resulting minimal example code below may seem nonsensical,
> but the original purpose of the class is to walk over a UI
> Screen model and collect any requirements for any of its
> constituent Widgets.
>
> For the purposes of this example I'm just using simple
> vanilla Java beans for the model classes:
>
>
> import java.util.List;
>
> public class Screen {
>
> private List<Widget> widgets;
>
> public List<Widget> getWidgets() {
> return widgets;
> }
>
> }
>
>
>
> import java.util.List;
>
> public class Widget {
>
> private List<Widget> widgets;
>
> public List<Widget> getWidgets() {
> return widgets;
> }
>
> }
>
>
> Note that even though Screen and Widget are identical in
> this minimal example, in reality Widget would be the root
> of a hierarchy of UI widgets, some of which are containers
> that may contain other widgets, and Screen is not a widget
> because a Screen cannot be contained in a widget.
>
> The Xtend file looks like this:
>
> Test.xtend:
>
> import java.util.*
>
> class Test {
>
> requires(Screen s) {
> var requires = new LinkedHashSet<String>()
>
> for (child : s.widgets)
> requires += child.requires
>
> return requires
> }
>
> requires(Widget w) {
> var requires = new LinkedHashSet<String>()
>
> for (child : w.widgets)
> requires.addAll(child.requires)
>
> return requires
> }
> }
>
>
> The Xtend class as shown above fails to compile to Java.
> However if I comment out one of the for loops within either
> of the requires() methods, it will compile. I am using the
> 3.7M6 Xtext 2 beta from:
> http://blog.efftinge.de/2011/04/eclipse-xtend-beta-available .html
>
> At this point I'm out of my depth as to how to debug the
> issue further, but hopefully this is enough for someone
> else to go on!
>
> Thanks,
> Edwin
>
Re: Xtend2 generation issue [message #670095 is a reply to message #669932] Thu, 12 May 2011 16:17 Go to previous messageGo to next message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Hi Sebastian,

I have updated to the latest Xtend/Xtext version 2.0.0.v201105111532 and this problem described above still exists. The Xtend file is slightly changed (added 'def') given the changed syntax requirements in the new version:

import java.util.*

class Test {
	
	def requires(Screen s) {
		var requires = new LinkedHashSet<String>()
		
		for (child : s.widgets)
			requires += child.requires
		
		return requires
	}
	
	def requires(Widget w) {
		var requires = new LinkedHashSet<String>()
		
		for (child : w.widgets)
			requires.addAll(child.requires)
		
		return requires
	}
	
}

Re: Xtend2 generation issue [message #670106 is a reply to message #670095] Thu, 12 May 2011 17:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi

as a workaround use requires(child) instead of child.requires or explicitely type the variable var LinkedHashSet<String> requires = new LinkedHashSet<String>()

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend2 generation issue [message #670125 is a reply to message #670106] Thu, 12 May 2011 17:52 Go to previous message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Hi Christian,

Thanks for the tips! Explicitly typing the var didn't work, but explicitly typing the def did: def LinkedHashSet<String> requires(Widget w) {

Thanks!
Edwin
Re: Xtend2 generation issue [message #670129 is a reply to message #670095] Thu, 12 May 2011 17:46 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Edwin,

please file a ticket. Thanks in advance.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 12.05.11 18:17, schrieb Edwin Park:
> Hi Sebastian,
>
> I have updated to the latest Xtend/Xtext version
> 2.0.0.v201105111532 and this problem described above still
> exists. The Xtend file is slightly changed (added 'def')
> given the changed syntax requirements in the new version:
>
>
> import java.util.*
>
> class Test {
>
> def requires(Screen s) {
> var requires = new LinkedHashSet<String>()
>
> for (child : s.widgets)
> requires += child.requires
>
> return requires
> }
>
> def requires(Widget w) {
> var requires = new LinkedHashSet<String>()
>
> for (child : w.widgets)
> requires.addAll(child.requires)
>
> return requires
> }
>
> }
>
>
Previous Topic:Problem with calculating FQN of proxy
Next Topic:extraneous input ' ' expecting RULE_ID
Goto Forum:
  


Current Time: Tue Apr 23 12:57:56 GMT 2024

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

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

Back to the top