Created
January 2, 2020 13:49
-
-
Save fbcbl/3e8b4a0e69a0b8f18111198ce5d5ac63 to your computer and use it in GitHub Desktop.
Android Lint - AndroidLogDetector
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
class AndroidLogDetector : Detector(), SourceCodeScanner { | |
override fun getApplicableMethodNames(): List<String> = | |
listOf("tag", "format", "v", "d", "i", "w", "e", "wtf") | |
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) { | |
super.visitMethodCall(context, node, method) | |
val evaluator = context.evaluator | |
if (evaluator.isMemberInClass(method, "android.util.Log")) { | |
reportUsage(context, node) | |
} | |
} | |
private fun reportUsage(context: JavaContext, node: UCallExpression) { | |
context.report( | |
issue = ISSUE, | |
scope = node, | |
location = context.getCallLocation( | |
call = node, | |
includeReceiver = true, | |
includeArguments = true | |
), | |
message = "android.util.Log usage is forbidden." | |
) | |
} | |
(...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment