Hi! I’m working on custom Detekt rule. Is there an...
# detekt
k
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")
        }
    }
}
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
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.