Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmTypesBuilder extension injection does not work in static inner classes
JvmTypesBuilder extension injection does not work in static inner classes [message #1746322] Wed, 26 October 2016 22:03 Go to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I want to create a template class for my JvmInferrer but the injection of the JvmTypesBuilder does not work in static inner classes.

	
	static class IndexReaderBuildTemplate {

		@Inject extension JvmTypesBuilder

                ...
			acceptor.accept(element.toClass(fqIndexReaderInterfacename)) [
 		
			members += element.toMethod("open", typeRef(void)) [


The typeRef function is unknown to the class.

What can I do ?
Re: JvmTypesBuilder extension injection does not work in static inner classes [message #1746327 is a reply to message #1746322] Thu, 27 October 2016 04:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14497
Registered: July 2009
Senior Member
hi from my point of view it makes no sense to have a inner class here.

since you would have to do the same as

@Inject extension JvmTypesBuilder org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer.setContext(Resource)

does for your actual inferrer for your inner classes

=> inject JvmTypeReferenceBuilder
=> call setContext on instances JvmTypeReferenceBuilder members


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmTypesBuilder extension injection does not work in static inner classes [message #1746442 is a reply to message #1746327] Fri, 28 October 2016 18:39 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

So instead of using injection you could make it a simple property that you initialize via constructor.
E.g.:
new IndexReaderBuildTemplate(_jvmTypesBuilder)


Re: JvmTypesBuilder extension injection does not work in static inner classes [message #1746443 is a reply to message #1746442] Fri, 28 October 2016 18:47 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

Also the injection only works on instances created by an injector (or explicitly provided to an injector for injection).
So you could inject an instance of your static class into the inferrer, and then injection would work transitively in that object as well.
But because of Christian's point you should not do it in this case.
Re: JvmTypesBuilder extension injection does not work in static inner classes [message #1746482 is a reply to message #1746443] Sun, 30 October 2016 18:32 Go to previous message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Thanks for all the answers I will give the constructor a try.
Previous Topic:How to validate wildcard package import
Next Topic:dynamic template proposals in xtext revisited
Goto Forum:
  


Current Time: Tue Jun 06 20:27:06 GMT 2023

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

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

Back to the top