Created
June 11, 2020 12:58
-
-
Save guilhermekrz/2106df6cab7b2622a04daf51d9b23a8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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