How I can detect new object creation

Skip to first unread message

Ruslan Magzyumov

Nov 24, 2021, 1:29:28 PM11/24/21
to lint-dev
I have class, for example "ClassA". It have 2 parametrs in constructor. 

open class CalssA(
    val string: String? = null,
    val value: Integer? = null
) {

How it possible to detect creating new object then val string is null?

val first = ClassA(value = 1)  -> detected
val second = ClassA(string = "str", value = 1) -> not detected

Tor Norbye

Nov 24, 2021, 2:36:52 PM11/24/21
to lint-dev
You'll want to visit all constructor calls (override getApplicableConstructorTypes() and visitConstructor(...) in your detector), and then inspect the constructor call's valueArguments. Then you could for example just make sure valueArguments.size == 2 and that each one is not a ULiteralExpression null.
Reply all
Reply to author
Message has been deleted
0 new messages