Ky
02/25/2020, 7:43 PMdata class
and lint seems to be considering the parameters of the data class
as a method.
data class ListViewModel(
private val handle: SavedStateHandle,
private val repository: ListRepository,
private val scheduler: IObservableSchedulerRx2,
private val errorHandler: Mvvm.ErrorHandler
)
So for each method, I am logging the method name and return type, and this is the output when it hits these params
METHOD NAME: component1
FUN RETURN TYPE: PsiType:SavedStateHandle
component2, component3, etc.. for each subsequent parameter.
Any suggestions?wasyl
02/25/2020, 7:55 PMcomponentX
😉 I think it’s reasonable enough to assume this will block any possible actual mistakes. Or consider not making your view models data classes — I wouldn’t say its what data classes
are for, generallyKy
02/25/2020, 8:13 PM@Parcelize
and the lint is also considering these methods and causing the rule to fail(toString
, hashCode
,equals
, copy
) Obviously I can just ignore these methods individually but are you aware of a way to just ignore the @Parcelize annotation?wasyl
02/25/2020, 8:19 PM@Parcelize
, but with the class being data class
, so I’d say removing it makes even more sense 😉node: UMethod
in the detector, you can check node.sourceElement
to get what part of source resulted in that method in the tree. For me when I log these (println("${node.name} : ${node.sourceElement}")
), it looks like this:
getClassProperty : class org.jetbrains.kotlin.psi.KtProperty
methodReturningInt : class org.jetbrains.kotlin.psi.KtNamedFunction
methodReturningUnit : class org.jetbrains.kotlin.psi.KtNamedFunction
getConstructorProperty : class org.jetbrains.kotlin.psi.KtParameter
TestClass : class org.jetbrains.kotlin.psi.KtPrimaryConstructor
component1 : class org.jetbrains.kotlin.psi.KtParameter
copy : class org.jetbrains.kotlin.psi.KtClass
toString : class org.jetbrains.kotlin.psi.KtClass
hashCode : class org.jetbrains.kotlin.psi.KtClass
equals : class org.jetbrains.kotlin.psi.KtClass
fun
source element, which is of type org.jetbrains.kotlin.psi.KtNamedFunction
. So seems node.sourceElement is KtNamedFunction
pretty good discriminator for the methods you’re looking for.Ky
02/25/2020, 8:32 PMsourceElement
but clearly this is very helpful and should solve my problem
Thanks!!