alorma
03/15/2021, 5:29 PMinterface
or class
?
I want to check if a method is anotated with @Deprecated
but only need to check interfaces, not implementations
Current code on threadclass DeprecateBlockingMethods : Rule() {
override val issue = Issue(
javaClass.simpleName,
Severity.Warning,
"This rule reports a method with Blocking on the name without @Deprecated annotation",
Debt(mins = 1)
)
override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
if (!function.isPublic) return
if (!function.isBlocking) return
if (!function.isAnnotatedWithDeprecated) {
report(CodeSmell(issue,
Entity.from(function.identifyingElement!!),
message = "The blocking method ${function.name} is not annotated with @Deprecated"))
}
}
private val KtNamedFunction.isBlocking
get() = name?.contains("Blocking") == true
private val KtNamedFunction.isAnnotatedWithDeprecated: Boolean
get() {
return modifierList?.annotationEntries?.any { annotation ->
annotation.shortName?.asString() == "Deprecated"
} == true
}
gammax
03/15/2021, 6:45 PMgetNonStrictParentOfType<KtClass>() ?: return
chao
03/15/2021, 6:49 PMgammax
03/15/2021, 7:21 PMKtClass
covers both class
and interface
FYIalorma
03/16/2021, 2:51 PMgetNonStrictParentOfType<KtClass>() ?: return