Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XbaseCompiler exception when compiling simple XExpressions
XbaseCompiler exception when compiling simple XExpressions [message #1758335] Mon, 27 March 2017 19:01 Go to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Hi,
i'm using XbaseCoimpiler in my generator to genetare java code for XExpressions.
i setup the compilet like this:
def compileXExpression(XExpression xExpression) {
		var importManager=new ImportManager()
		val result = new FakeTreeAppendable(importManager)		
		xbaseCompiler.toJavaStatement(xExpression, result, true)// xbaseCompiler.toJavaStatement(xExpression, result, false) doesn't work either.
		result
	}

and then call that method every time i need the expression translated to java.
even with simple expressions the compiler is unable to find its type:
if i put as expression:
"".toString
i get this exception
java.lang.NullPointerException
	at org.eclipse.xtext.xbase.compiler.ImportManager.appendType(ImportManager.java:115)
	at org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable.appendType(StringBuilderBasedAppendable.java:36)
	at org.eclipse.xtext.xbase.compiler.AbstractStringBuilderBasedAppendable.append(AbstractStringBuilderBasedAppendable.java:49)
	at org.eclipse.xtext.xbase.compiler.output.FakeTreeAppendable.append(FakeTreeAppendable.java:38)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.appendConstructedTypeName(XbaseCompiler.java:972)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.constructorCallToJavaExpression(XbaseCompiler.java:941)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaExpression(XbaseCompiler.java:996)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.internalToConvertedExpression(XbaseCompiler.java:322)
	at org.eclipse.xtext.xbase.compiler.TypeConvertingCompiler.internalToConvertedExpression(TypeConvertingCompiler.java:104)
	at org.eclipse.xtext.xbase.compiler.TypeConvertingCompiler.internalToJavaExpression(TypeConvertingCompiler.java:47)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendReceiver(FeatureCallCompiler.java:783)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.featureCalltoJavaExpression(FeatureCallCompiler.java:580)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:162)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:111)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:385)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:473)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.toJavaStatement(AbstractXbaseCompiler.java:485)

i've changed the arguments to the xbaseCompiler, but it doesn't work. Based on several examples online it seems to be right, but is not working.
Do you have any clue on what i'm doing wrong?
Thanks for your help!

[Updated on: Mon, 27 March 2017 19:04]

Report message to a moderator

Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758336 is a reply to message #1758335] Mon, 27 March 2017 19:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
you are basically trying to do something you should not do.
this is why i told you that this is a bad idea in the first place ........

i assume you dont implement JvmModelInferrer or did construct the model in a way the itypecomputer was not called.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758337 is a reply to message #1758336] Mon, 27 March 2017 19:14 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
oh, i see.
I saw an example by Lorenzo Bettini here
https://github.com/LorenzoBettini/Xtext2-experiments/blob/master/helloxbase/org.xtext.example.helloxbase/src/org/xtext/example/helloxbase/generator/HelloXbaseGenerator.xtend

the article is here
https://dzone.com/articles/xtext-21-using-xbase

I thought it could work, since he mixes a generator and xbasecompiler...
is this not supported anymore?
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758338 is a reply to message #1758337] Mon, 27 March 2017 19:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
well there were some major changes since this. there is a way to get it running but i cannot tell you step by step.
i just can give you the hint about the type computer playing an important role and that this might be the cause for your problem.
(see https://www.eclipse.org/forums/index.php/m/1081654/ which might be exactly on your problem)

but i still dont get your problem with the JvmModelGenerator/Inferrer in the first place since you did not do any further elaboration


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758339 is a reply to message #1758338] Mon, 27 March 2017 19:31 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
thanks for your help!
Well, i need to generate non valid java classes, so for instance import and reference classes that are not yet on the classpath. Using the inferrer the code won't even get generated, since it's not valid.
With the generator i can put all kinds on non existent references in my generated java files and fix them once they are provided (much later down the process)
I know is weird, but it is mainly to support the development of the plugin itself, since the required classes live in a different project and even a different eclipse installation loaded with the language plugins.

i hope this makes a little more sense.
Thanks again
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758340 is a reply to message #1758339] Mon, 27 March 2017 19:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
hmmmm but how can you verify the code is valid if you import stuff that is not there?
xbase will not even be able to say 1+1 = 2 is the classpath is broken. since you could provide a import that overloads + in a way that 1+1 = 4


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758407 is a reply to message #1758340] Tue, 28 March 2017 13:16 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
no, i'm only importing non existent java classes, since there's no operator overload in java i think i'm safe.
Those missing classes are hardcoded framework classes that i need to include in the generated code (annotations, services, etc.), so i know exactly where to put them.
As for the Xbase code, i only extended a couple of classes to suit my purposes, all the rest of the validation is there., so in theory the user can't enter invalid code, only my generator can put invalid classes in selected places.
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758414 is a reply to message #1758407] Tue, 28 March 2017 13:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
Yes but why don't you use xbase and inferrer then any simply adapt jvmmodelgenerator to adapt the Imports....

But I still don't get it if no use uses the imports they are unused and you can leave them away.
And I don't understand how you compile the generator code if the missing classes are not on the classpath
Of the generated code you can't compile the generated code


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758453 is a reply to message #1758414] Tue, 28 March 2017 19:26 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
-Ok, i'm back to my inferrer, but now i need to modify the body of my generated method and i don't know how.
Originally i was doing this in the inferrer:
	def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		acceptor.accept(element.toClass(element.name)) [
			
			for (com:element.sections.filter(Command)){
				members += com.toMethod(com.name, typeRef(CommandResponse))[
					for (argument:com.arguments.args){
						parameters+=element.toParameter(argument.name, argument.type)						
						} 
					body=com.block
				]
			}
		]

and that put in the generated method all that the user entered.
But now i want to put my own autogenerated stuff before that block , something like:
body='''String myId="1"; ''' +com.block

But now i'm affraid this is not possible...
Can you confirm this please?
once again, thank you very much for your help!
Re: XbaseCompiler exception when cimpiling simple XExpressions [message #1758455 is a reply to message #1758453] Tue, 28 March 2017 20:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
This does not work

You need to infer two methods

One with body = '''...''' and one with body = expression

In the first one you can call the second one


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Missing auto complete and validation in 2.11
Next Topic:deploy xtext language as maven artifact
Goto Forum:
  


Current Time: Wed Dec 11 20:12:55 GMT 2024

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

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

Back to the top