Skip to main content



      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 18:03 Go to next message
Eclipse UserFriend
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 00:51 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: JvmTypesBuilder extension injection does not work in static inner classes [message #1746442 is a reply to message #1746327] Fri, 28 October 2016 14:39 Go to previous messageGo to next message
Eclipse UserFriend
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 14:47 Go to previous messageGo to next message
Eclipse UserFriend
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 14:32 Go to previous message
Eclipse UserFriend
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: Mon May 12 13:44:35 EDT 2025

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

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

Back to the top