Fixed intentions
This commit is contained in:
committed by
Dmitry Petrov
parent
7b25331de1
commit
f5a34ca5ae
+3
-1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
|
||||
class ConvertIfWithThrowToAssertIntention : SelfTargetingOffsetIndependentIntention<KtIfExpression>(KtIfExpression::class.java, "Replace 'if' with 'assert' statement") {
|
||||
override fun isApplicableTo(element: KtIfExpression): Boolean {
|
||||
@@ -37,7 +38,8 @@ class ConvertIfWithThrowToAssertIntention : SelfTargetingOffsetIndependentIntent
|
||||
if (thrownExpr.valueArguments.size > 1) return false
|
||||
|
||||
val resolvedCall = thrownExpr.getResolvedCall(thrownExpr.analyze()) ?: return false
|
||||
return DescriptorUtils.getFqName(resolvedCall.resultingDescriptor).toString() == "java.lang.AssertionError.<init>"
|
||||
val targetFqName = DescriptorUtils.getFqName(resolvedCall.resultingDescriptor).asString()
|
||||
return targetFqName in constant { setOf("kotlin.AssertionError.<init>", "java.lang.AssertionError.<init>") }
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtIfExpression, editor: Editor?) {
|
||||
|
||||
+3
-4
@@ -33,9 +33,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
val NULL_PTR_EXCEPTION_FQ = "java.lang.NullPointerException"
|
||||
val KOTLIN_NULL_PTR_EXCEPTION_FQ = "kotlin.KotlinNullPointerException"
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
|
||||
fun KtBinaryExpression.expressionComparedToNull(): KtExpression? {
|
||||
val operationToken = this.operationToken
|
||||
@@ -73,7 +71,8 @@ fun KtThrowExpression.throwsNullPointerExceptionWithNoArguments(): Boolean {
|
||||
val declDescriptor = descriptor?.containingDeclaration ?: return false
|
||||
|
||||
val exceptionName = DescriptorUtils.getFqName(declDescriptor).asString()
|
||||
return (exceptionName == NULL_PTR_EXCEPTION_FQ || exceptionName == KOTLIN_NULL_PTR_EXCEPTION_FQ) && thrownExpression.valueArguments.isEmpty()
|
||||
return exceptionName in constant { setOf("kotlin.KotlinNullPointerException", "kotlin.NullPointerException", "java.lang.NullPointerException") }
|
||||
&& thrownExpression.valueArguments.isEmpty()
|
||||
}
|
||||
|
||||
fun KtExpression.evaluatesTo(other: KtExpression): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user