SourceCodeScanner 不调用 visitMethodCall
SourceCodeScanner not calling visitMethodCall
我正在玩 lint 规则。
我所有的 ResourceXmlDetector
运行 都没有问题并通过了所有测试。但是 Detector(), SourceCodeScanner
失败了,因为它们 return 0 warnings/errors,原因是 visitMethodCall
没有被调用,因此 context.report
也不会。
我的代码类似于android lint-checks, for instance 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()
。缺少什么?
根据UElementVisitor#DelegatingPsiVisitor.visitMethodCallExpression
源码,发现有些java或者kotlin方法无法识别为"Method":val function = node.resolve()
为null。
我认为这不重要,但我的测试规则是:
TestLintTask.lint()
.files(TestFiles.kotlin("Test.kt", input).indented())
.issues(ISSUE)
.run()
.expectWarningCount(1)
.expect(output)
用 kotlin(input)
替换 kotlin("Test.kt", input)
使它起作用...
我正在玩 lint 规则。
我所有的 ResourceXmlDetector
运行 都没有问题并通过了所有测试。但是 Detector(), SourceCodeScanner
失败了,因为它们 return 0 warnings/errors,原因是 visitMethodCall
没有被调用,因此 context.report
也不会。
我的代码类似于android lint-checks, for instance 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()
。缺少什么?
根据UElementVisitor#DelegatingPsiVisitor.visitMethodCallExpression
源码,发现有些java或者kotlin方法无法识别为"Method":val function = node.resolve()
为null。
我认为这不重要,但我的测试规则是:
TestLintTask.lint()
.files(TestFiles.kotlin("Test.kt", input).indented())
.issues(ISSUE)
.run()
.expectWarningCount(1)
.expect(output)
用 kotlin(input)
替换 kotlin("Test.kt", input)
使它起作用...