我正在处理代码检查规则。
所有的ResourceXmlDetector
都能够正常运行并通过了所有测试。但是Detector(), SourceCodeScanner
失败了,因为它们返回0个警告/错误,原因是visitMethodCall
没有被调用,因此context.report
也不会被调用。
我的代码与Android lint-checks非常相似,例如CipherGetInstanceDetector,但我找不到我的错误。
@Suppress("UnstableApiUsage")
class MySourceDetector : Detector(), SourceCodeScanner {
override fun getApplicableMethodNames() = listOf("...")
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
if (context.evaluator.isMemberInClass(method, "...")) {
...
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 = ISSUE.getExplanation(TextFormat.RAW)
)
}
companion object {
@JvmField
val ISSUE = Issue.create(...Scope.JAVA_FILE_SCOPE)
}
}
唯一停在断点的方法是
Issue.create
和getApplicableMethodNames()
。还有什么遗漏吗?
getColor
和parseColor
,至少我知道getColor
被识别了,因为我看到过一些样例使用它。 - GuilhE