Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How can I make JvmModelInferrer insert an import statement in the generated Java code?
How can I make JvmModelInferrer insert an import statement in the generated Java code? [message #1792756] Mon, 23 July 2018 14:53 Go to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 21
Registered: January 2018
Junior Member
In my JvmModelInferrer, I generate a method as follows:
					members += check.toMethod('''«test.name»_«check.rule.name»''', void.typeRef) [
						documentation = check.documentation
						annotations += Test.annotationRef
						body = '''
						TestExecutor exec = TestExecutorFactory.get();
						exec.runTest(this, this::«test.name»_«check.rule.name»);
						'''
					]


Now, in the generated Java code, the types TestExecutor and TestExecutorFactory are not being imported.

What should I do so the proper import statements are generated? I suppose I'd need to make the JvmModelInferrer aware of the fact that I'm using those types but I don't know how I'd do that.
Re: How can I make JvmModelInferrer insert an import statement in the generated Java code? [message #1792758 is a reply to message #1792756] Mon, 23 July 2018 14:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
you can simply write assuming the class is on the path of the inferrer.

body = '''
						«TestExecutor» exec = «TestExecutorFactory».get();
						exec.runTest(this, this::«test.name»_«check.rule.name»);
						'''


otherwise you can use

«"a.b.c.TestExecutor".typeRef()»


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can I make JvmModelInferrer insert an import statement in the generated Java code? [message #1792759 is a reply to message #1792758] Mon, 23 July 2018 15:02 Go to previous message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 21
Registered: January 2018
Junior Member
Absolutely fantastic! Works perfectly. Thanks for the blazingly fast answer.
Previous Topic:ClassNotFoundException org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory
Next Topic:Parameterized unit test
Goto Forum:
  


Current Time: Mon Nov 19 11:57:36 GMT 2018

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

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

Back to the top