I try to check whether specific parameters are passed to parent’s constructor via Konsist.
For example:
I have a ViewModel like:
class ExampleViewModel @Inject constructor(
private val useCase1: SomeUseCase,
private val useCase2: OtherUseCase,
) : BaseViewModel(useCase1, useCase2) { ... }
I want to check that all the useCases are passed to parent’s constructor.
Is there a way to get parent constructor call out of KoClassDeclaration?
I managed to filter required properties to check as follows:
val useCaseParams = klass.primaryConstructor
?.parameters
?.mapNotNull { it.type.asClassDeclaration() }
?.filter { it.hasParentClassOf(UseCase::class) }
.orEmpty()
But I can’t get parent constructor declaration to check if all the use case params are passed there.
Vlad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.