Compatibility fixes for IDEA <= 2019.1 :-/
This commit is contained in:
parent
eab50f590b
commit
0e2007641c
@ -15,7 +15,7 @@ class AssumeThatInsteadOfReturnInspection : AbstractAssertJInspection() {
|
||||
private const val MAX_RECURSION_DEPTH = 5
|
||||
private const val MAX_STATEMENTS_COUNT = 50
|
||||
|
||||
private val TEST_ANNOTATIONS = listOf(
|
||||
private val TEST_ANNOTATIONS = setOf(
|
||||
"org.junit.Test",
|
||||
"org.junit.jupiter.api.Test",
|
||||
"org.junit.jupiter.api.TestTemplate",
|
||||
@ -52,7 +52,9 @@ class AssumeThatInsteadOfReturnInspection : AbstractAssertJInspection() {
|
||||
return object : JavaElementVisitor() {
|
||||
override fun visitMethod(method: PsiMethod) {
|
||||
super.visitMethod(method)
|
||||
if (TEST_ANNOTATIONS.none(method::hasAnnotation)) {
|
||||
// Note: replace with if(TEST_ANNOTATIONS.none(method::hasAnnotation)) for IDEA >= 2018.2
|
||||
val annotations = method.annotations.mapNotNull { it.qualifiedName }
|
||||
if (annotations.none(TEST_ANNOTATIONS::contains)) {
|
||||
return
|
||||
}
|
||||
val containingClass = method.containingClass ?: return
|
||||
|
@ -4,7 +4,7 @@ import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.siyeh.ig.psiutils.TrackingEquivalenceChecker
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker
|
||||
import de.platon42.intellij.plugins.cajon.*
|
||||
import de.platon42.intellij.plugins.cajon.quickfixes.JoinStatementsQuickFix
|
||||
|
||||
@ -25,7 +25,8 @@ class JoinAssertThatStatementsInspection : AbstractAssertJInspection() {
|
||||
var sameCount = 0
|
||||
var firstStatement: PsiStatement? = null
|
||||
var lastStatement: PsiStatement? = null
|
||||
val equivalenceChecker = TrackingEquivalenceChecker()
|
||||
// Note: replace with TrackingEquivalenceChecker() for IDEA >= 2019.1
|
||||
val equivalenceChecker = EquivalenceChecker.getCanonicalPsiEquivalence()!!
|
||||
for (statement in block.statements) {
|
||||
val assertThatCall = isLegitAssertThatCall(statement)
|
||||
var reset = true
|
||||
@ -36,9 +37,10 @@ class JoinAssertThatStatementsInspection : AbstractAssertJInspection() {
|
||||
if (!reset) {
|
||||
val isSame = when (actualExpression) {
|
||||
is PsiMethodCallExpression -> equivalenceChecker.expressionsAreEquivalent(actualExpression, lastActualExpression)
|
||||
// Note: replace with PsiTreeUtil.findChildrenOfAnyType(strict = false) for IDEA >= 2018.1
|
||||
&& !KNOWN_METHODS_WITH_SIDE_EFFECTS.test(actualExpression)
|
||||
&& PsiTreeUtil.findChildrenOfAnyType(
|
||||
actualExpression,
|
||||
false,
|
||||
PsiMethodCallExpression::class.java
|
||||
).none { KNOWN_METHODS_WITH_SIDE_EFFECTS.test(it) }
|
||||
else -> equivalenceChecker.expressionsAreEquivalent(actualExpression, lastActualExpression)
|
||||
|
Loading…
Reference in New Issue
Block a user