evant
10/24/2021, 8:16 PMJiaxiang
10/24/2021, 9:37 PMevant
10/24/2021, 9:41 PMvisitFunctionDeclaration
will return false if the predicate returns false, so validate()
will always say it's invalid if you choose to skip it
visitPropertyDeclaration
checks property.type.resolve().isError
instead of visiting, which means property.validate()
may return true while property.type.validate()
may return false. Seems inconsistent with other places in the visitor.class FixedKSValidateVisitor(private val predicate: (KSNode?, KSNode) -> Boolean) : KSValidateVisitor(predicate) {
override fun visitFunctionDeclaration(function: KSFunctionDeclaration, data: KSNode?): Boolean {
if (!predicate(function, function.returnType!!)) {
return true
}
return super.visitFunctionDeclaration(function, data)
}
override fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: KSNode?): Boolean {
if (predicate(property, property.type) && property.type.accept(this, data)) {
return false
}
if (!this.visitDeclaration(property, data)) {
return false
}
return true
}
}
Jiaxiang
10/24/2021, 9:51 PMpredicate
indicates no check for function return type, it will return true
directly while there are other places for validation like parameter types.evant
10/24/2021, 9:59 PM