Fix for AssertThatStringIsEmpty, refactored method.
This commit is contained in:
parent
5fa61a3004
commit
458542de7c
@ -2,6 +2,8 @@ package de.platon42.intellij.plugins.cajon.inspections
|
|||||||
|
|
||||||
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool
|
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool
|
||||||
import com.intellij.psi.CommonClassNames
|
import com.intellij.psi.CommonClassNames
|
||||||
|
import com.intellij.psi.PsiCapturedWildcardType
|
||||||
|
import com.intellij.psi.PsiMethodCallExpression
|
||||||
import com.siyeh.ig.callMatcher.CallMatcher
|
import com.siyeh.ig.callMatcher.CallMatcher
|
||||||
|
|
||||||
open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() {
|
open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() {
|
||||||
@ -26,4 +28,12 @@ open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() {
|
|||||||
override fun getGroupDisplayName(): String {
|
override fun getGroupDisplayName(): String {
|
||||||
return "AssertJ"
|
return "AssertJ"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun checkAssertedType(expression: PsiMethodCallExpression, prefix: String): Boolean {
|
||||||
|
var assertedType = expression.methodExpression.qualifierExpression?.type
|
||||||
|
if (assertedType is PsiCapturedWildcardType) {
|
||||||
|
assertedType = assertedType.upperBound
|
||||||
|
}
|
||||||
|
return assertedType?.canonicalText?.startsWith(prefix) ?: false
|
||||||
|
}
|
||||||
}
|
}
|
@ -39,14 +39,12 @@ class AssertThatBooleanIsTrueOrFalseInspection : AbstractAssertJInspection() {
|
|||||||
if (!(normalBooleanTest || flippedBooleanTest)) {
|
if (!(normalBooleanTest || flippedBooleanTest)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var assertedType = expression.methodExpression.qualifierExpression?.type
|
if (!checkAssertedType(expression, ABSTRACT_BOOLEAN_ASSERT_CLASSNAME)) {
|
||||||
if (assertedType is PsiCapturedWildcardType) {
|
return
|
||||||
assertedType = assertedType.upperBound
|
|
||||||
}
|
}
|
||||||
val assertedTypeIsBoolean =
|
|
||||||
assertedType?.canonicalText?.startsWith(ABSTRACT_BOOLEAN_ASSERT_CLASSNAME) ?: false
|
|
||||||
val equalToExpression = expression.argumentList.expressions[0]!!
|
val equalToExpression = expression.argumentList.expressions[0]!!
|
||||||
if (!TypeConversionUtil.isBooleanType(equalToExpression.type) || !assertedTypeIsBoolean) {
|
if (!TypeConversionUtil.isBooleanType(equalToExpression.type)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val constantEvaluationHelper = JavaPsiFacade.getInstance(holder.project).constantEvaluationHelper
|
val constantEvaluationHelper = JavaPsiFacade.getInstance(holder.project).constantEvaluationHelper
|
||||||
|
@ -33,6 +33,10 @@ class AssertThatStringIsEmptyInspection : AbstractAssertJInspection() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkAssertedType(expression, ABSTRACT_STRING_ASSERT_CLASSNAME)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val psiExpression = expression.argumentList.expressions[0] as? PsiLiteralExpression ?: return
|
val psiExpression = expression.argumentList.expressions[0] as? PsiLiteralExpression ?: return
|
||||||
|
|
||||||
if (psiExpression.value == "") {
|
if (psiExpression.value == "") {
|
||||||
@ -47,5 +51,4 @@ class AssertThatStringIsEmptyInspection : AbstractAssertJInspection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ public class StringIsEmpty {
|
|||||||
String string = "string";
|
String string = "string";
|
||||||
|
|
||||||
assertThat(string).isEqualTo("foo");
|
assertThat(string).isEqualTo("foo");
|
||||||
assertThat(string).isEmpty();
|
assertThat(string).as("foo").isEmpty();
|
||||||
|
assertThat(new Object()).isEqualTo("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ public class StringIsEmpty {
|
|||||||
String string = "string";
|
String string = "string";
|
||||||
|
|
||||||
assertThat(string).isEqualTo("foo");
|
assertThat(string).isEqualTo("foo");
|
||||||
assertThat(string).isEqualTo("");
|
assertThat(string).as("foo").isEqualTo("");
|
||||||
|
assertThat(new Object()).isEqualTo("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user