Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guilhermekrz/2106df6cab7b2622a04daf51d9b23a8d to your computer and use it in GitHub Desktop.
Save guilhermekrz/2106df6cab7b2622a04daf51d9b23a8d to your computer and use it in GitHub Desktop.
private const val OKHTTP_CLIENT = "okhttp3.OkHttpClient"
private val okHttpClientConstructors = mutableSetOf<CallContextLocation>()
data class CallContextLocation(val context: JavaContext, val location: Location)
override fun getApplicableUastTypes(): List<Class<out UElement>>? {
return listOf(UCallExpression::class.java)
}
override fun createUastHandler(context: JavaContext): UElementHandler? {
return OkHttpClientHandler(context)
}
inner class OkHttpClientHandler(private val context: JavaContext) : UElementHandler() {
override fun visitCallExpression(node: UCallExpression) {
if(node.getExpressionType()?.canonicalText == OKHTTP_CLIENT && node.kind == UastCallKind.CONSTRUCTOR_CALL) {
okHttpClientConstructors.add(CallContextLocation(context, context.getLocation(node)))
}
}
}
override fun afterCheckRootProject(context: Context) {
if(okHttpClientConstructors.size > 1) {
for(callContextLocation in okHttpClientConstructors) {
reportUsage(callContextLocation.context, callContextLocation.location)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment