Any way to add annotation arguments at runtime?

Here is what I was doing previously:

@UninstallModules(value = [ LoginDataModule::class, OnboardingDataModule::class, LoginDataModuleUserLoggedIn::class, OnboardingDataModuleOnboardingSlidesViewed::class ]) @RunWith(JUnitParamsRunner::class) class LoginScreenFragmentTest { 

As expected, this works fine but the problem is that our codebase is growing and that would mean adding more and more modules to the UninstallModules annotation and also carefully selecting the classes to put inside the value array based on the test class we are going to run. I tried to deal with this by creating a base array and then adding classes to it based on the test that will be annotated with the UninstallModules annotation.

fun addModulesToUninstall(modulesToUninstall: Array<out KClass<*>>): Array<out KClass<*>> { var uninstalledModules = arrayOf( LoginDataModule::class, OnboardingDataModule::class ) for (moduleToUninstall in modulesToUninstall) { uninstalledModules += moduleToUninstall } return uninstalledModules } 

Then, the new annotation becomes:

@UninstallModules(value = addModulesToUninstall([LoginDataModuleUserLoggedIn::class, OnboardingDataModuleOnboardingSlidesViewed::class])) @RunWith(JUnitParamsRunner::class) class LoginScreenFragmentTest { 

But I get a red squiggly line under addModulesToUninstall with the following error warning:

An annotation argument must be a compile-time constant 

Any way around this?

submitted by /u/zimmer550king
[link] [comments]