Injecting object-instances into AA-processors

22 views
Skip to first unread message

Alexander Fischer

unread,
Dec 18, 2017, 8:14:11 AM12/18/17
to Xtend Programming Language
Hello,

we have used different processors for own active annotations. In this processors we also use some helpers and other classes, which are instantiated with factories. These factories are singletons.
With this factories I can easily integrate own implementations of helper-classes for unittests.
The singletons works until Xtend2.12 without any problems.

On Xtend2.13/Xtext2.13 the whole framework seems to instantiate the processors and all other classes with separate classloaders. So the singleton-pattern works suddenly not anymore with this version of Xtend/Xtext.

What are the suggested ways to "inject" some prepared class-instances or other informations (e.g. prepared in test-setup or other pre-initializations) into the framework, so processors, transformers or other classes can use this instances.
Can I get Guice to run succesfully and inject objects into processors or transformers?

Kindly regards,
Alexander Fischer

Karsten Thoms

unread,
Dec 18, 2017, 9:02:08 AM12/18/17
to xtend...@googlegroups.com
Hi Alexander,

I am not aware of changes related to classloaders after 2.11. Could you may provide a sample based on the Xtend Active Annotation example and open an issue for that?

I have not seen a use case to use Guice in those processors so far, but of course you could create your own Injector and inject members into the processor by yourself. Not sure, if that is what you want. Roughly like this:

override doTransform (…) {
  val injector = Guice.createInjector(new MyModule())
  injector.injectMembers(this)
  … // do the transformation 
}

~Karsten

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Fischer

unread,
Dec 18, 2017, 10:27:25 AM12/18/17
to Xtend Programming Language
Hi Karsten,

thanks for your quick responses.
The new situation with Xtend/Xtext 2.13 is, that standard singleton classes (classic implementation with static field and static instance()-Method, which looks for null and instantiates the singleton) are instantiated two times. One instance comes from my unittest-method, the other instances comes from instance()-calls inside processor-classes. After code-generation the execution returns to the unittest and sees the singleton-instance from unittest again. Inside the AA-processor or AA-transformer I see the new/second singleton-instance. After some recherche I learned, that this can occur with different class-loaders loading the same bytecode for the singleton-class.
The same unit-test runs without problems with Xtend/Xtext 2.11. There is only one singleton-instance created, the null-check in the static instance()-method works as expected. So I think, the handling with different classloaders is a new feature of Xtend/Xtext2.13 - may be for better isolation of the framework from other libraries or the new LSP-support?

~Alexander
Reply all
Reply to author
Forward
Message has been deleted
0 new messages