Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XbaseCompiler creating new objects for this access
icon5.gif  XbaseCompiler creating new objects for this access [message #1032659] Wed, 03 April 2013 09:06 Go to next message
Dustin Steiner is currently offline Dustin SteinerFriend
Messages: 10
Registered: October 2012
Junior Member
In our Xtext-based project (Master thesis MDD research stuff Wink, we reuse XBlockExpression from Xbase in order to have some kind of methods for our DSL.
In the generator we want to use the XBaseCompiler in order to get working Java code (found this code via http://www.rcp-vision.com/?p=1640):

val result = new FakeTreeAppendable(manager);
if (expression != null) {
	xbaseCompiler.toJavaStatement(expression, result, false);
}


Unfortunately when running this code, the XBaseCompiler creates new variables for the this reference. Here's an example:
Our DSL looks like that:
entity Todo {
	title: String {
		get; set;
	}
	def test():void {
		val a = this.title;
	}
}


And we manually create the following Java file:
public class Todo {
	protected String mTitle;
	public String getTitle() {
		return mTitle;
	}
	public void setTitle(String value) {
		mTitle = value;
	}
	
	public void test() {
		Todo _Todo = Todo;
		final String a = _Todo.getTitle();
	}
}


Here you see the problem. Instead of accessing this.getTitle(), it tries to create this new Todo _Todo variable (which doesn't even use the new-keyword).
In the background we also use the JVMInferrer to get autocompletion for the editors and to be able to have the JVMTypes available in the XExpressions of course.

Is this a known problem or will I have to recreate the whole project again and check, if this is the result of some unknown combination of Xtext features?
Would be great if you could help us out! Smile
Re: XbaseCompiler creating new objects for this access [message #1032663 is a reply to message #1032659] Wed, 03 April 2013 09:13 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I'm the author of that blog post, and I haven't checked whether that
still works with Xtext 2.4.

However, that was an experiment to understand the XbaseCompiler, but, if
you use the JvmModelInferrer, I think you should rely on that instead of
writing your own generator... or are you using the XbaseCompiler in the
inferrer itself?

On 04/03/2013 11:06 AM, Dustin Steiner wrote:
> In our Xtext-based project (Master thesis MDD research stuff ;), we
> reuse XBlockExpression from Xbase in order to have some kind of methods
> for our DSL.
> In the generator we want to use the XBaseCompiler in order to get
> working Java code (found this code via http://www.rcp-vision.com/?p=1640):
>
> val result = new FakeTreeAppendable(manager);
> if (expression != null) {
> xbaseCompiler.toJavaStatement(expression, result, false);
> }
>
> Unfortunately when running this code, the XBaseCompiler creates new
> variables for the this reference. Here's an example:
> Our DSL looks like that:
> entity Todo {
> title: String {
> get; set;
> }
> def test():void {
> val a = this.title;
> }
> }
>
> And we manually create the following Java file:
> public class Todo {
> protected String mTitle;
> public String getTitle() {
> return mTitle;
> }
> public void setTitle(String value) {
> mTitle = value;
> }
>
> public void test() {
> Todo _Todo = Todo;
> final String a = _Todo.getTitle();
> }
> }
>
> Here you see the problem. Instead of accessing this.getTitle(), it tries
> to create this new Todo _Todo variable (which doesn't even use the
> new-keyword).
> In the background we also use the JVMInferrer to get autocompletion for
> the editors and to be able to have the JVMTypes available in the
> XExpressions of course.
>
> Is this a known problem or will I have to recreate the whole project
> again and check, if this is the result of some unknown combination of
> Xtext features?
> Would be great if you could help us out! :)


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: XbaseCompiler creating new objects for this access [message #1032697 is a reply to message #1032663] Wed, 03 April 2013 10:07 Go to previous messageGo to next message
Dustin Steiner is currently offline Dustin SteinerFriend
Messages: 10
Registered: October 2012
Junior Member
Sorry, forgot to mention that we're still using Xtext 2.3.

We're using the XBaseCompiler in an Xtend generator and not in the inferrer because we need Java source code files and not Bytecode. Or is it possible to also save .java files from the inferrer and not only generating the .class files?
Re: XbaseCompiler creating new objects for this access [message #1032704 is a reply to message #1032697] Wed, 03 April 2013 10:15 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 04/03/2013 12:07 PM, Dustin Steiner wrote:
> Sorry, forgot to mention that we're still using Xtext 2.3.
>
> We're using the XBaseCompiler in an Xtend generator and not in the
> inferrer because we need Java source code files and not Bytecode. Or is
> it possible to also save .java files from the inferrer and not only
> generating the .class files?

all the Jvm inferrer infrastructure generates Java code, not bytecode :)

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: XbaseCompiler creating new objects for this access [message #1032769 is a reply to message #1032704] Wed, 03 April 2013 12:12 Go to previous messageGo to next message
Dustin Steiner is currently offline Dustin SteinerFriend
Messages: 10
Registered: October 2012
Junior Member
Interesting and weird. It did/does not generate .java files for us. But now that I started a new test-project, I also see, that it generates "real" code.

Is it possible to turn set the location for the generated files? We are working on a cross-platform abstraction layer and are generating code for Android, iOS and AppEngine in different projects, but only the Xtend generators are called (the inferrer is called, but there are no files generated, it kind of just works...). Therefor we only need the JVM files in the Android and AppEngine projects but not on iOS there we only need the Java-Expressions to let J2ObjC generate Objective-C code.
Otherwise we will have to implement a small expression language and parse it on our own.
Re: XbaseCompiler creating new objects for this access [message #1036639 is a reply to message #1032769] Mon, 08 April 2013 16:34 Go to previous messageGo to next message
Dustin Steiner is currently offline Dustin SteinerFriend
Messages: 10
Registered: October 2012
Junior Member
Anyone? Is it possible to call the XbaseCompiler on only the XBlockExpression and get the correct code? Is it possible to somehow tell the compiler, which scope we are in, without using the inferrer? Because the inferrer will only work without the generators, which we need in order to generate more than just Java files. And as far as we saw, the location the inferrer generates to cannot be changes?!
Re: XbaseCompiler creating new objects for this access [message #1036645 is a reply to message #1036639] Mon, 08 April 2013 16:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

Regarding your second question: the generation is done by
jvmmodelgenerator. You may digg into into to see if you can change
the target location / outlet

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XbaseCompiler creating new objects for this access [message #1036708 is a reply to message #1036645] Mon, 08 April 2013 18:07 Go to previous message
Dustin Steiner is currently offline Dustin SteinerFriend
Messages: 10
Registered: October 2012
Junior Member
Thanks!

After digging even deeper into the whole XbaseCompiler source, I found what causes the problem: the "this" variables is never set in the internal scope. Adding the Jvminferred type as "this" makes everything work Very Happy
Previous Topic:IStorage2UriMapperJdtExtensions unbound in Xtext 2.4
Next Topic:Why there is an additional .smap file when code are automatically generated?
Goto Forum:
  


Current Time: Thu Mar 28 10:52:43 GMT 2024

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

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

Back to the top