Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guilhermekrz/3d7129c465218ee963e63b6f61478f9f to your computer and use it in GitHub Desktop.
Save guilhermekrz/3d7129c465218ee963e63b6f61478f9f to your computer and use it in GitHub Desktop.
private inner class ThrowCallVisitor(private val context: JavaContext) : AbstractUastVisitor() {
override fun visitCallExpression(node: UCallExpression): Boolean {
if(node.uastParent is KotlinUThrowExpression) {
val type = node.returnType ?: throw IllegalStateException("type of KotlinUThrowExpression cannot be null")
if(!isUncheckedException(type)) {
reportUsage(context, context.getLocation(element = node))
}
}
return false
}
private fun isUncheckedException(type: PsiType): Boolean {
if(type.canonicalText == RuntimeException::class.java.canonicalName) {
return true
}
for(superType in type.superTypes) {
if(isUncheckedException(superType)) {
return true
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment