Created
June 2, 2020 00:28
-
-
Save guilhermekrz/3d7129c465218ee963e63b6f61478f9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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