Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] Wrong Java Generated code
[Xcore] Wrong Java Generated code [message #1735197] Thu, 16 June 2016 09:36 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have a derived method in xcore.

class Directory {
String name
derived String fullname get {
if (name != null)
   "FULL NAME: " + name
"0"
}
}


With this xcore code, the generated java code is:
	public String getFullname() {
		String _xblockexpression = null;
		{
			String _name = this.getName();
			boolean _notEquals = (!Objects.equal(_name , null));
			if (_notEquals) {
				String _name_1 = this.getName();
				/* ("FULL NAME:" + _name_1 ); */
			}
			_xblockexpression = "0";
		}
		return _xblockexpression;
	}


Somehow, the xcore generates it correctly if I do it like this:

class Directory {
String name
derived String fullname get {
if (name != null)
   return ("FULL NAME: " + name)
return "0"
}
}

Re: [Xcore] Wrong Java Generated code [message #1735221 is a reply to message #1735197] Thu, 16 June 2016 11:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31917
Registered: July 2009
Senior Member
Chris,

I think what you show is to be expected. Xbase can't know you expect
the "then" branch of the if-statement to return. Instead the method
always continues. So you need an else or a return.


On 16.06.2016 05:36, chris yo wrote:
> I have a derived method in xcore.
>
>
> class Directory {
> String name
> derived String fullname get {
> if (name != null)
> "FULL NAME: " + name
> "0"
> }
> }
>
>
> With this xcore code, the generated java code is:
>
> public String getFullname() {
> String _xblockexpression = null;
> {
> String _name = this.getName();
> boolean _notEquals = (!Objects.equal(_name , null));
> if (_notEquals) {
> String _name_1 = this.getName();
> /* ("FULL NAME:" + _name_1 ); */
> }
> _xblockexpression = "0";
> }
> return _xblockexpression;
> }
>
>
> Somehow, the xcore generates it correctly if I do it like this:
>
>
> class Directory {
> String name
> derived String fullname get {
> if (name != null)
> return ("FULL NAME: " + name)
> return "0"
> }
> }
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] Wrong Java Generated code [message #1735287 is a reply to message #1735221] Fri, 17 June 2016 02:34 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Ok. I will modify my implementation.
Previous Topic:isFactoryForType implementation guideline for adapter factories used by AdapterFactoryContentProvide
Next Topic:[Xcore] Setting default value of a string
Goto Forum:
  


Current Time: Wed Jun 23 00:45:53 GMT 2021

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

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

Back to the top