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: 140
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 online Christian DietrichFriend
Messages: 10797
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: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
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: 77
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)




TypeFox - Support And Consulting For Xtext
http://typefox.io
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: 77
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.


TypeFox - Support And Consulting For Xtext
http://typefox.io
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: 140
Registered: July 2009
Location: Berlin
Senior Member
Thanks for all the answers I will give the constructor a try.
Previous Topic:Restrict scope but still do it accross multiple files
Next Topic:Embeded single line editor
Goto Forum:
  


Current Time: Tue Jun 27 21:12:55 GMT 2017

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

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