Hi! I’m working on custom Detekt rule.
Is there any ways to know the class name in
visitCallExpression
with Type Resolution?
Copy code
import timber.log.Timber
class DummyClass {
fun hello() {
try {
throw IllegalStateException("error")
} catch (e: Exception) {
// Any way to know this called wtf function belongs to Timber in visitCallExpression()?
<http://Timber.wtf|Timber.wtf>(e, "hello")
}
}
}
ken_kentan
07/19/2023, 1:12 AM
I can get the function name with following code, but I have no idea how to retrieve the class name.
Copy code
val calleeExpression = expression.calleeExpression
if (calleeExpression is KtNameReferenceExpression) {
println(calleeExpression.getReferencedName())
}
j
jordan29.04.1197
07/19/2023, 9:56 PM
You need to get parent of expression than parent of parent and repeat the process unlit parent type will be class than you will able to get name of class. Option 2 : use visitClass than get all experssion and check they.