Internally: Upgraded to AssertJ 13.2.2.
Support for hasSizeLessThan(), hasSizeLessThanOrEqualTo(), hasSizeGreaterThanOrEqualTo(), and hasSizeGreaterThan() for AssertThatSizeInspection (with AssertJ >=13.2.0). Really fixed highlighting for JUnit conversion. Sorry. Fixed testing code to work against IDEA 2019.1.
This commit is contained in:
+9
-4
@@ -2,10 +2,7 @@ package de.platon42.intellij.plugins.cajon.inspections
|
||||
|
||||
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiCapturedWildcardType
|
||||
import com.intellij.psi.PsiMethodCallExpression
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import com.siyeh.ig.callMatcher.CallMatcher
|
||||
@@ -133,4 +130,12 @@ open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() {
|
||||
val constantEvaluationHelper = JavaPsiFacade.getInstance(expression.project).constantEvaluationHelper
|
||||
return constantEvaluationHelper.computeConstantExpression(valueExpression)
|
||||
}
|
||||
|
||||
protected fun hasAssertJMethod(element: PsiElement, classAndMethod: String): Boolean {
|
||||
val classname = "org.assertj.core.api.${classAndMethod.substringBeforeLast(".")}"
|
||||
val findClass =
|
||||
JavaPsiFacade.getInstance(element.project).findClass(classname, GlobalSearchScope.allScope(element.project))
|
||||
?: return false
|
||||
return findClass.findMethodsByName(classAndMethod.substringAfterLast(".")).isNotEmpty()
|
||||
}
|
||||
}
|
||||
+13
@@ -53,6 +53,19 @@ class AssertThatSizeInspection : AbstractAssertJInspection() {
|
||||
registerSizeMethod(holder, expression, expectedCallExpression, "isNotEmpty()", noExpectedExpression = true)
|
||||
return
|
||||
}
|
||||
// new stuff in AssertJ 13.2.0
|
||||
if (hasAssertJMethod(expression, "AbstractIterableAssert.hasSizeLessThan")) {
|
||||
val matchedMethod = listOf(
|
||||
Pair(IS_GREATER_THAN_INT, "hasSizeGreaterThan()"),
|
||||
Pair(IS_GREATER_THAN_OR_EQUAL_TO_INT, "hasSizeGreaterThanOrEqualTo()"),
|
||||
Pair(IS_LESS_THAN_OR_EQUAL_TO_INT, "hasSizeLessThanOrEqualTo()"),
|
||||
Pair(IS_LESS_THAN_INT, "hasSizeLessThan()")
|
||||
).find { it.first.test(expectedCallExpression) }?.second
|
||||
if (matchedMethod != null) {
|
||||
registerSizeMethod(holder, expression, expectedCallExpression, matchedMethod)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -1,8 +1,6 @@
|
||||
package de.platon42.intellij.plugins.cajon.inspections
|
||||
|
||||
import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.JavaElementVisitor
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
@@ -147,8 +145,6 @@ class JUnitAssertToAssertJInspection : AbstractJUnitAssertInspection() {
|
||||
holder.registerProblem(
|
||||
expression,
|
||||
message,
|
||||
ProblemHighlightType.INFORMATION,
|
||||
null as TextRange?,
|
||||
ReplaceJUnitAssertMethodCallQuickFix(description, hasExpected, replacementMethod)
|
||||
)
|
||||
}
|
||||
@@ -164,8 +160,6 @@ class JUnitAssertToAssertJInspection : AbstractJUnitAssertInspection() {
|
||||
holder.registerProblem(
|
||||
expression,
|
||||
message,
|
||||
ProblemHighlightType.INFORMATION,
|
||||
null as TextRange?,
|
||||
ReplaceJUnitDeltaAssertMethodCallQuickFix(description, replacementMethod)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user