From 8fb3ecce9503354208cd4039b94521244ac86239 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Tue, 30 Jul 2019 19:42:35 +0200 Subject: [PATCH] Bumped kotlin to 1.3.41, jupiter 5.5.1, added compatibility with IDEA 2019.2 and fixed regressions with new AssertJ 3.13.0. --- build.gradle | 18 +++++++++--------- .../intellij/plugins/cajon/Extensions.kt | 2 +- .../inspections/AbstractAssertJInspection.kt | 3 +++ .../AssertThatGuavaOptionalInspection.kt | 2 +- .../AssertThatJava8OptionalInspection.kt | 2 +- .../AssertThatObjectExpressionInspection.kt | 2 +- ...ssertThatObjectIsNullOrNotNullInspection.kt | 3 ++- .../AssertThatStringIsEmptyInspection.kt | 3 ++- .../jupiter/LightCodeInsightExtension.java | 7 +++---- 9 files changed, 23 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 07a8f5d..a29a82c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ plugins { id 'java' id 'org.jetbrains.intellij' version '0.4.9' - id 'org.jetbrains.kotlin.jvm' version '1.3.40' + id 'org.jetbrains.kotlin.jvm' version '1.3.41' id 'jacoco' id 'com.github.kt3k.coveralls' version '2.8.2' } group 'de.platon42' -version '1.2' +version '1.3' repositories { mavenCentral() @@ -20,10 +20,10 @@ repositories { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testCompile "org.assertj:assertj-core:3.12.2" + testCompile "org.assertj:assertj-core:3.13.0" testCompile "org.assertj:assertj-guava:3.2.1" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0-RC2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.0-RC2' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.1' testImplementation "org.jetbrains.kotlin:kotlin-test" // testImplementation "org.jetbrains.kotlin:kotlin-test-junit" } @@ -35,17 +35,17 @@ compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } intellij { - version '2019.1.3' + version '2019.2' // pluginName 'Concise AssertJ Optimizing Nitpicker (Cajon)' updateSinceUntilBuild false + plugins = ['java'] } patchPluginXml { changeNotes """ -

V1.2 (23-Jun-19)

+

V1.3 (01-Aug-19)

Full changelog available at Github project site.

""" diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/Extensions.kt b/src/main/java/de/platon42/intellij/plugins/cajon/Extensions.kt index 059a09b..eb99ba0 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/Extensions.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/Extensions.kt @@ -106,7 +106,7 @@ fun PsiMethodCallExpression.getExpectedNullNonNullResult(): Boolean? { if (isNull || isNotNull) { return isNotNull } else { - val isEqualTo = AbstractAssertJInspection.IS_EQUAL_TO_OBJECT.test(this) + val isEqualTo = CallMatcher.anyOf(AbstractAssertJInspection.IS_EQUAL_TO_OBJECT, AbstractAssertJInspection.IS_EQUAL_TO_STRING).test(this) val isNotEqualTo = AbstractAssertJInspection.IS_NOT_EQUAL_TO_OBJECT.test(this) if ((isEqualTo || isNotEqualTo) && firstArg.type == PsiType.NULL) { return isNotEqualTo diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AbstractAssertJInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AbstractAssertJInspection.kt index fd50ccd..d176a0f 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AbstractAssertJInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AbstractAssertJInspection.kt @@ -13,6 +13,7 @@ import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_A import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_BOOLEAN_ASSERT_CLASSNAME import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_COMPARABLE_ASSERT_CLASSNAME import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_INTEGER_ASSERT_CLASSNAME +import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_STRING_ASSERT_CLASSNAME import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ASSERTIONS_CLASSNAME import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ASSERT_INTERFACE import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ENUMERABLE_ASSERT_INTERFACE @@ -81,6 +82,8 @@ open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() { val IS_EQUAL_TO_OBJECT = CallMatcher.instanceCall(ASSERT_INTERFACE, MethodNames.IS_EQUAL_TO) .parameterTypes(CommonClassNames.JAVA_LANG_OBJECT)!! + val IS_EQUAL_TO_STRING = CallMatcher.instanceCall(ABSTRACT_STRING_ASSERT_CLASSNAME, MethodNames.IS_EQUAL_TO) + .parameterTypes(CommonClassNames.JAVA_LANG_STRING)!! val IS_NOT_EQUAL_TO_OBJECT = CallMatcher.instanceCall(ASSERT_INTERFACE, MethodNames.IS_NOT_EQUAL_TO) .parameterTypes(CommonClassNames.JAVA_LANG_OBJECT)!! val IS_EQUAL_TO_BOOLEAN = CallMatcher.instanceCall(ABSTRACT_BOOLEAN_ASSERT_CLASSNAME, MethodNames.IS_EQUAL_TO) diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspection.kt index 84e376d..572e542 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspection.kt @@ -30,7 +30,7 @@ class AssertThatGuavaOptionalInspection : AbstractAssertJInspection() { val outmostMethodCall = statement.findOutmostMethodCall() ?: return if (GUAVA_OPTIONAL_GET.test(actualExpression)) { val expectedCallExpression = staticMethodCall.gatherAssertionCalls().singleOrNull() ?: return - if (IS_EQUAL_TO_OBJECT.test(expectedCallExpression)) { + if (CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING).test(expectedCallExpression)) { registerMoveOutMethod(holder, outmostMethodCall, actualExpression, MethodNames.CONTAINS) { desc, method -> QuickFixWithPostfixDelegate( RemoveActualOutmostMethodCallQuickFix(desc, method), diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspection.kt index a4644f9..85d2305 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspection.kt @@ -28,7 +28,7 @@ class AssertThatJava8OptionalInspection : AbstractAssertJInspection() { val outmostMethodCall = statement.findOutmostMethodCall() ?: return if (OPTIONAL_GET.test(actualExpression)) { val expectedCallExpression = staticMethodCall.gatherAssertionCalls().singleOrNull() ?: return - if (IS_EQUAL_TO_OBJECT.test(expectedCallExpression)) { + if (CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING).test(expectedCallExpression)) { registerMoveOutMethod(holder, outmostMethodCall, actualExpression, MethodNames.CONTAINS) { desc, method -> RemoveActualOutmostMethodCallQuickFix(desc, method) } diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectExpressionInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectExpressionInspection.kt index b93a5a7..71f8284 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectExpressionInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectExpressionInspection.kt @@ -38,7 +38,7 @@ class AssertThatObjectExpressionInspection : AbstractAssertJInspection() { } } OBJECT_TO_STRING.test(assertThatArgument) -> { - staticMethodCall.findFluentCallTo(IS_EQUAL_TO_OBJECT) ?: return + staticMethodCall.findFluentCallTo(IS_EQUAL_TO_OBJECT) ?: staticMethodCall.findFluentCallTo(IS_EQUAL_TO_STRING) ?: return registerMoveOutMethod(holder, expectedCallExpression, assertThatArgument, MethodNames.HAS_TO_STRING) { desc, method -> RemoveActualOutmostMethodCallQuickFix(desc, method) } diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspection.kt index 0606859..1df6370 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspection.kt @@ -2,6 +2,7 @@ package de.platon42.intellij.plugins.cajon.inspections import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.* +import com.siyeh.ig.callMatcher.CallMatcher import de.platon42.intellij.plugins.cajon.MethodNames import de.platon42.intellij.plugins.cajon.firstArg import de.platon42.intellij.plugins.cajon.hasAssertThat @@ -21,7 +22,7 @@ class AssertThatObjectIsNullOrNotNullInspection : AbstractAssertJInspection() { super.visitMethodCallExpression(expression) if (!expression.hasAssertThat()) return val isNotEqualTo = IS_NOT_EQUAL_TO_OBJECT.test(expression) - val isEqualTo = IS_EQUAL_TO_OBJECT.test(expression) + val isEqualTo = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING).test(expression) val isLastExpression = expression.parent is PsiStatement if (!((isEqualTo && isLastExpression) || isNotEqualTo)) return diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspection.kt index ae55a7f..b27c8e0 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspection.kt @@ -5,6 +5,7 @@ import com.intellij.psi.JavaElementVisitor import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiMethodCallExpression import com.intellij.psi.PsiStatement +import com.siyeh.ig.callMatcher.CallMatcher import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_CHAR_SEQUENCE_ASSERT_CLASSNAME import de.platon42.intellij.plugins.cajon.MethodNames import de.platon42.intellij.plugins.cajon.calculateConstantParameterValue @@ -23,7 +24,7 @@ class AssertThatStringIsEmptyInspection : AbstractAssertJInspection() { override fun visitMethodCallExpression(expression: PsiMethodCallExpression) { super.visitMethodCallExpression(expression) if (!expression.hasAssertThat()) return - val isEqual = IS_EQUAL_TO_OBJECT.test(expression) + val isEqual = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING).test(expression) val hasSize = HAS_SIZE.test(expression) val isLastExpression = expression.parent is PsiStatement if (!((isEqual || hasSize) && isLastExpression)) return diff --git a/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java b/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java index ff78afc..3b1d614 100644 --- a/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java +++ b/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java @@ -11,7 +11,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.*; import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy; import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.extension.*; import org.junit.jupiter.api.extension.ExtensionContext.Namespace; @@ -88,7 +88,6 @@ public class LightCodeInsightExtension implements ParameterResolver, AfterTestEx TestLoggerFactory.onTestFinished(true); } catch (Throwable e) { TestLoggerFactory.onTestFinished(false); - e.fillInStackTrace(); throwables[0] = e; } }; @@ -112,7 +111,7 @@ public class LightCodeInsightExtension implements ParameterResolver, AfterTestEx } } - private static class LightCodeInsightFixtureTestCaseWrapper extends LightCodeInsightFixtureTestCase { + private static class LightCodeInsightFixtureTestCaseWrapper extends LightJavaCodeInsightFixtureTestCase { private final ExtensionContext extensionContext; private LightCodeInsightFixtureTestCaseWrapper(ExtensionContext extensionContext) { @@ -159,7 +158,7 @@ public class LightCodeInsightExtension implements ParameterResolver, AfterTestEx }; } - protected void addJarContaining(ModifiableRootModel model, Class clazz) { + void addJarContaining(ModifiableRootModel model, Class clazz) { try { Path jarPath = Paths.get(clazz.getProtectionDomain().getCodeSource().getLocation().toURI());