On the same theme use of the idiom `@SomethingLike...
# java-to-kotlin-refactoring
d
On the same theme use of the idiom `@SomethingLikeInject private lateinit var fieldName: FieldType`` is there a JPA/JavaEE aware build time plugin to check all uses of
lateinit
to confirm they have an expected injection annotation on the field, and maybe warn if the field is left public. Maybe there is also the ability to put the plugin in debug build mode and it will insert implicit call to assertion check of all
lateinit
at runtime maybe at the end of all constructors such as
constructor() { myBusinessLogicMethodCall();  injectedKotlinLateInitInjectionChecker() }
and a method inserted like
private fun injectedKotlinLateInitInjectionChecker() {  assert((FieldType?)fieldName != null) {"injected Kotlin lateinit usage check failed on field: fieldName"} }
t
I’m curious to learn why you wouldn’t use constructor injection instead of the
lateinit var
field injection points. Then you would simply use the compiler to check those collaborating classes are “injected”.
d
Thanks for your reply, just noticed it now. JPA entities are mutable data objects, so various code require various ways to construct and modify state. While constructor injection is a useful approach, forcing it to be the only approach is problematic. I don't recall if my original comment above was made before or after I found the JPA "no-arg" plugin for Gradle, this ensure there is a Java comparible no-arg constructor which is part of the JPA spec. However even with constructor injection with a public no-arg, you now have 2 ways to construct object. So you may wish to still to have a injection validator. JPA that is byte-code-proxies will run constructor code, I think what I was looking for was a plugin to instrument the .class file at buildtime, looking at Kotlin type information and automatically build / replace the method, maybe it would be stubbed with an annotation
@InstrumentThisMethodWithLateInitChecks void injectedKotlinLateInitInjectionChecker() { }
then such a plugin would replace/wrap and edit bytecode